This is an automated email from the ASF dual-hosted git repository.
paziz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 04c76d7 Specify return object in case key not found
04c76d7 is described below
commit 04c76d701f30937852561d373c3d4449cde14bc1
Author: Persia Aziz <[email protected]>
AuthorDate: Tue Apr 25 13:19:33 2017 -0500
Specify return object in case key not found
---
lib/ts/Map.h | 7 ++++++-
lib/ts/test_Map.cc | 5 +++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/lib/ts/Map.h b/lib/ts/Map.h
index d4ade96..5301ae9 100644
--- a/lib/ts/Map.h
+++ b/lib/ts/Map.h
@@ -114,11 +114,16 @@ public:
using Map<K, C, A>::i;
using Map<K, C, A>::v;
using Map<K, C, A>::e;
+ HashMap() {}
+ HashMap(C c) : invalid_value(c) {}
MapElem<K, C> *get_internal(K akey);
C get(K akey);
value_type *put(K akey, C avalue);
void get_keys(Vec<K> &keys);
void get_values(Vec<C> &values);
+
+private:
+ C invalid_value = 0; // return this object if key is not present
};
#define form_Map(_c, _p, _v)
\
@@ -513,7 +518,7 @@ HashMap<K, AHashFns, C, A>::get(K akey)
{
MapElem<K, C> *x = get_internal(akey);
if (!x)
- return 0;
+ return invalid_value;
return x->value;
}
diff --git a/lib/ts/test_Map.cc b/lib/ts/test_Map.cc
index ca96ba7..27d35b9 100644
--- a/lib/ts/test_Map.cc
+++ b/lib/ts/test_Map.cc
@@ -168,6 +168,11 @@ main(int /* argc ATS_UNUSED */, char ** /*argv ATS_UNUSED
*/)
ink_assert(sh.get("af") == 10);
ink_assert(sh.get("ac") == 7);
+ HashMap<cchar *, StringHashFns, int> sh2(-99); // return -99 if key not found
+ sh2.put("aa", 15);
+ sh2.put("ab", 16);
+ ink_assert(sh2.get("aa") == 15);
+ ink_assert(sh2.get("ac") == -99);
test_TSHashTable();
printf("test_Map PASSED\n");
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].