From 5174cb1f74d3af64780ecf8e94beb68204f2651b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 6 Aug 2009 09:42:34 +0000 Subject: [PATCH] * Added copyless direct value accessors (via Iterator::NextValue(), and Get()). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32154 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/shared/HashMap.h | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/headers/private/shared/HashMap.h b/headers/private/shared/HashMap.h index 8edbba306b..b55e0d98d9 100644 --- a/headers/private/shared/HashMap.h +++ b/headers/private/shared/HashMap.h @@ -28,12 +28,13 @@ #ifndef HASH_MAP_H #define HASH_MAP_H -//#include + #include #include "AutoLocker.h" #include "OpenHashTable.h" + namespace BPrivate { // HashMapElement @@ -107,7 +108,17 @@ public: _FindNext(); return result; } - + + Value* NextValue() + { + if (fElement == NULL) + return NULL; + + Value* value = &fElement->fValue; + _FindNext(); + return value; + } + Entry Remove() { if (!fLastElement) @@ -169,6 +180,7 @@ public: Value Remove(const Key& key); void Clear(); Value Get(const Key& key) const; + bool Get(const Key& key, Value*& _value) const; bool ContainsKey(const Key& key) const; @@ -404,6 +416,19 @@ HashMap::Get(const Key& key) const return Value(); } +// Get +template +bool +HashMap::Get(const Key& key, Value*& _value) const +{ + if (Element* element = _FindElement(key)) { + _value = &element->fValue; + return true; + } + + return false; +} + // ContainsKey template bool