diff options
author | frosch <frosch@openttd.org> | 2012-11-14 22:50:30 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2012-11-14 22:50:30 +0000 |
commit | dcfb2af871b76a7b65fb959b2f4ebc2da2f9e4d3 (patch) | |
tree | 8c93c52e1b4b59d6244bf102cc6accf3aaa4ac7e /src | |
parent | 6e6d94a2d14a50ad93577a4b030f25f8b64986b1 (diff) | |
download | openttd-dcfb2af871b76a7b65fb959b2f4ebc2da2f9e4d3.tar.xz |
(svn r24741) -Add: Const-methods to SmallMap.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/smallmap_type.hpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/core/smallmap_type.hpp b/src/core/smallmap_type.hpp index 060a36d27..dda0fc2a1 100644 --- a/src/core/smallmap_type.hpp +++ b/src/core/smallmap_type.hpp @@ -54,6 +54,19 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> { * @param key key to find * @return &Pair(key, data) if found, this->End() if not */ + inline const Pair *Find(const T &key) const + { + for (uint i = 0; i < this->items; i++) { + if (key == this->data[i].first) return &this->data[i]; + } + return this->End(); + } + + /** + * Finds given key in this map + * @param key key to find + * @return &Pair(key, data) if found, this->End() if not + */ inline Pair *Find(const T &key) { for (uint i = 0; i < this->items; i++) { @@ -67,7 +80,7 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> { * @param key key to test * @return true iff the item is present */ - inline bool Contains(const T &key) + inline bool Contains(const T &key) const { return this->Find(key) != this->End(); } |