1.1 --- a/public/sm_stringhashmap.h Thu Aug 29 11:11:41 2013 -0400
1.2 +++ b/public/sm_stringhashmap.h Thu Aug 29 10:09:02 2013 -0700
1.3 @@ -47,6 +47,7 @@
1.4 #include <am-allocator-policies.h>
1.5 #include <am-hashmap.h>
1.6 #include <am-string.h>
1.7 +#include <am-moveable.h>
1.8 #include <string.h>
1.9
1.10 namespace SourceMod
1.11 @@ -113,6 +114,7 @@
1.12 }
1.13
1.14 typedef typename Internal::Result Result;
1.15 + typedef typename Internal::Insert Insert;
1.16 typedef typename Internal::iterator iterator;
1.17
1.18 // Some KTrie-like helper functions.
1.19 @@ -143,7 +145,7 @@
1.20 bool replace(const char *aKey, const T &value)
1.21 {
1.22 CharsAndLength key(aKey);
1.23 - typename Internal::Insert i = internal_.findForAdd(key);
1.24 + Insert i = internal_.findForAdd(key);
1.25 if (!i.found())
1.26 {
1.27 memory_used_ += key.length() + 1;
1.28 @@ -158,7 +160,7 @@
1.29 bool insert(const char *aKey, const T &value)
1.30 {
1.31 CharsAndLength key(aKey);
1.32 - typename Internal::Insert i = internal_.findForAdd(key);
1.33 + Insert i = internal_.findForAdd(key);
1.34 if (i.found())
1.35 return false;
1.36 if (!internal_.add(i))
1.37 @@ -190,14 +192,45 @@
1.38 internal_.clear();
1.39 }
1.40
1.41 - iterator iter() {
1.42 + iterator iter()
1.43 + {
1.44 return internal_.iter();
1.45 }
1.46
1.47 - size_t mem_usage() const {
1.48 + size_t mem_usage() const
1.49 + {
1.50 return internal_.estimateMemoryUse() + memory_used_;
1.51 }
1.52
1.53 + size_t elements() const
1.54 + {
1.55 + return internal_.elements();
1.56 + }
1.57 +
1.58 +
1.59 + Insert findForAdd(const char *aKey)
1.60 + {
1.61 + CharsAndLength key(aKey);
1.62 + return internal_.findForAdd(key);
1.63 + }
1.64 +
1.65 + // Note that |i->key| must be set after calling this, and the key must
1.66 + // be the same as used with findForAdd(). It is best to avoid these two
1.67 + // functions as the combined variants above are safer.
1.68 + bool add(Insert &i)
1.69 + {
1.70 + return internal_.add(i);
1.71 + }
1.72 +
1.73 + // Only value needs to be set after.
1.74 + bool add(Insert &i, const char *aKey)
1.75 + {
1.76 + if (!internal_.add(i))
1.77 + return false;
1.78 + i->key = aKey;
1.79 + return true;
1.80 + }
1.81 +
1.82 private:
1.83 Internal internal_;
1.84 size_t memory_used_;