From db28a227c41f7f1a91b2f118684be2a39b40074c Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 9 Jan 2010 20:19:29 +0000 Subject: [PATCH] Added GetIterator() version that takes a key and returns an iterator to the respective element (if in the table). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34977 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/util/OpenHashTable.h | 25 ++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/headers/private/kernel/util/OpenHashTable.h b/headers/private/kernel/util/OpenHashTable.h index 6d43d8bef2..3556dc262a 100644 --- a/headers/private/kernel/util/OpenHashTable.h +++ b/headers/private/kernel/util/OpenHashTable.h @@ -314,7 +314,30 @@ public: ValueType* fNext; }; - Iterator GetIterator() const { return Iterator(this); } + Iterator GetIterator() const + { + return Iterator(this); + } + + Iterator GetIterator(const KeyType& key) const + { + if (fTableSize == 0) + return Iterator(this, fTableSize, NULL); + + size_t index = fDefinition.HashKey(key) & (fTableSize - 1); + ValueType* slot = fTable[index]; + + while (slot) { + if (fDefinition.Compare(key, slot)) + break; + slot = _Link(slot); + } + + if (slot == NULL) + return Iterator(this, fTableSize, NULL); + + return Iterator(this, index + 1, slot); + } protected: // for g++ 2.95