You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by pa...@apache.org on 2017/07/12 19:43:48 UTC

[trafficserver] branch master updated: const-ifying the getter functions of HashMap

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 be16283  const-ifying the getter functions of HashMap
be16283 is described below

commit be16283c024e8a19d13953f1c3aa467925e0be83
Author: Persia Aziz <pe...@yahoo-inc.com>
AuthorDate: Tue Jul 11 15:38:00 2017 -0500

    const-ifying the getter functions of HashMap
---
 lib/ts/Map.h       |  8 ++++----
 lib/ts/test_Map.cc | 23 +++++++++++++++++++++++
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/lib/ts/Map.h b/lib/ts/Map.h
index 2af628d..d354613 100644
--- a/lib/ts/Map.h
+++ b/lib/ts/Map.h
@@ -111,8 +111,8 @@ public:
   using Map<K, C, A>::e;
   HashMap() {}
   HashMap(C c) : invalid_value(c) {}
-  MapElem<K, C> *get_internal(K akey);
-  C get(K akey);
+  MapElem<K, C> *get_internal(K akey) const;
+  C get(K akey) const;
   value_type *put(K akey, C avalue);
   void get_keys(Vec<K> &keys);
   void get_values(Vec<C> &values);
@@ -484,7 +484,7 @@ HashSet<K, AHashFns, C, A>::put(C avalue)
 
 template <class K, class AHashFns, class C, class A>
 inline MapElem<K, C> *
-HashMap<K, AHashFns, C, A>::get_internal(K akey)
+HashMap<K, AHashFns, C, A>::get_internal(K akey) const
 {
   if (!n)
     return 0;
@@ -509,7 +509,7 @@ HashMap<K, AHashFns, C, A>::get_internal(K akey)
 
 template <class K, class AHashFns, class C, class A>
 inline C
-HashMap<K, AHashFns, C, A>::get(K akey)
+HashMap<K, AHashFns, C, A>::get(K akey) const
 {
   MapElem<K, C> *x = get_internal(akey);
   if (!x)
diff --git a/lib/ts/test_Map.cc b/lib/ts/test_Map.cc
index 302656d..95065ff 100644
--- a/lib/ts/test_Map.cc
+++ b/lib/ts/test_Map.cc
@@ -124,11 +124,31 @@ test_TSHashTable()
   }
 }
 
+class testHashMap
+{
+private:
+  HashMap<cchar *, StringHashFns, int> testsh;
+
+public:
+  int
+  get(cchar *ch) const
+  {
+    return testsh.get(ch);
+  }
+
+  void
+  put(cchar *key, int v)
+  {
+    testsh.put(key, v);
+  }
+};
+
 int
 main(int /* argc ATS_UNUSED */, char ** /*argv ATS_UNUSED */)
 {
   typedef Map<cchar *, cchar *> SSMap;
   typedef MapElem<cchar *, cchar *> SSMapElem;
+  testHashMap testsh;
 #define form_SSMap(_p, _v) form_Map(SSMapElem, _p, _v)
   SSMap ssm;
   ssm.put("a", "A");
@@ -173,8 +193,11 @@ main(int /* argc ATS_UNUSED */, char ** /*argv ATS_UNUSED */)
   HashMap<cchar *, StringHashFns, int> sh2(-99); // return -99 if key not found
   sh2.put("aa", 15);
   sh2.put("ab", 16);
+  testsh.put("aa", 15);
+  testsh.put("ab", 16);
   ink_assert(sh2.get("aa") == 15);
   ink_assert(sh2.get("ac") == -99);
+  ink_assert(testsh.get("aa") == 15);
   test_TSHashTable();
 
   printf("test_Map PASSED\n");

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].