1.1 --- a/public/sm_stringhashmap.h Sun Aug 25 01:42:15 2013 -0700
1.2 +++ b/public/sm_stringhashmap.h Sun Aug 25 01:42:16 2013 -0700
1.3 @@ -32,6 +32,18 @@
1.4 #ifndef _include_sourcemod_hashtable_h_
1.5 #define _include_sourcemod_hashtable_h_
1.6
1.7 +/**
1.8 + * @file sm_stringhashmap.h
1.9 + *
1.10 + * @brief Generic Key -> Value map class, based on a hash table. The Key, in
1.11 + * this case, is always an ASCII string, and the value type is a template
1.12 + * parameter. This class is intended as a drop-in replacement for KTrie
1.13 + * (though the retrieve() signature has been improved).
1.14 + *
1.15 + * If your Value type already contains the key string, consider using
1.16 + * NameHashSet instead.
1.17 + */
1.18 +
1.19 #include <am-allocator-policies.h>
1.20 #include <am-hashmap.h>
1.21 #include <am-string.h>
1.22 @@ -102,6 +114,8 @@
1.23 internal_.reportOutOfMemory();
1.24 }
1.25
1.26 + typedef typename Internal::Result Result;
1.27 +
1.28 // Some KTrie-like helper functions.
1.29 bool retrieve(const char *aKey, T *aResult = NULL)
1.30 {
1.31 @@ -114,6 +128,12 @@
1.32 return true;
1.33 }
1.34
1.35 + Result find(const char *aKey)
1.36 + {
1.37 + CharsAndLength key(aKey);
1.38 + return internal_.find(key);
1.39 + }
1.40 +
1.41 bool contains(const char *aKey)
1.42 {
1.43 CharsAndLength key(aKey);
1.44 @@ -128,7 +148,9 @@
1.45 if (!i.found())
1.46 {
1.47 memory_used_ += key.length() + 1;
1.48 - return internal_.add(i, value);
1.49 + if (!internal_.add(i, value))
1.50 + return false;
1.51 + i->key = aKey;
1.52 }
1.53 i->value = value;
1.54 return true;