diff options
author | Kenneth Heafield <github@kheafield.com> | 2013-06-24 19:05:47 +0400 |
---|---|---|
committer | Kenneth Heafield <github@kheafield.com> | 2013-06-24 19:05:47 +0400 |
commit | 794867c555e82edf3bd12ffb3faa35fb24d6e0a1 (patch) | |
tree | 8fa6a1051d3f878ff5981a66d2e951148743fded /util/probing_hash_table.hh | |
parent | f3cd72537c48ad584ee375195d27871932d3805c (diff) |
KenLM 6b4a1c7940a36026de1d96693ccb6ec0f16de8dc
Diffstat (limited to 'util/probing_hash_table.hh')
-rw-r--r-- | util/probing_hash_table.hh | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/util/probing_hash_table.hh b/util/probing_hash_table.hh index 57866ff93..51a2944d9 100644 --- a/util/probing_hash_table.hh +++ b/util/probing_hash_table.hh @@ -109,9 +109,20 @@ template <class EntryT, class HashT, class EqualT = std::equal_to<typename Entry if (equal_(got, key)) { out = i; return true; } if (equal_(got, invalid_)) return false; if (++i == end_) i = begin_; - } + } + } + + // Like UnsafeMutableFind, but the key must be there. + template <class Key> MutableIterator UnsafeMutableMustFind(const Key key) { + for (MutableIterator i(begin_ + (hash_(key) % buckets_));;) { + Key got(i->GetKey()); + if (equal_(got, key)) { return i; } + assert(!equal_(got, invalid_)); + if (++i == end_) i = begin_; + } } + template <class Key> bool Find(const Key key, ConstIterator &out) const { #ifdef DEBUG assert(initialized_); @@ -124,6 +135,16 @@ template <class EntryT, class HashT, class EqualT = std::equal_to<typename Entry } } + // Like Find but we're sure it must be there. + template <class Key> ConstIterator MustFind(const Key key) const { + for (ConstIterator i(begin_ + (hash_(key) % buckets_));;) { + Key got(i->GetKey()); + if (equal_(got, key)) { return i; } + assert(!equal_(got, invalid_)); + if (++i == end_) i = begin_; + } + } + void Clear() { Entry invalid; invalid.SetKey(invalid_); |