mirror of https://github.com/OpenTTD/OpenTTD
(svn r24741) -Add: Const-methods to SmallMap.
parent
6e6d94a2d1
commit
dcfb2af871
|
@ -49,6 +49,19 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> {
|
||||||
/** Data are freed in SmallVector destructor */
|
/** Data are freed in SmallVector destructor */
|
||||||
inline ~SmallMap() { }
|
inline ~SmallMap() { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds given key in this map
|
||||||
|
* @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
|
* Finds given key in this map
|
||||||
* @param key key to find
|
* @param key key to find
|
||||||
|
@ -67,7 +80,7 @@ struct SmallMap : SmallVector<SmallPair<T, U>, S> {
|
||||||
* @param key key to test
|
* @param key key to test
|
||||||
* @return true iff the item is present
|
* @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();
|
return this->Find(key) != this->End();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue