32 #ifndef _include_sourcemod_hashtable_h_
33 #define _include_sourcemod_hashtable_h_
47 #include <am-allocator-policies.h>
48 #include <am-hashmap.h>
49 #include <am-string.h>
50 #include <am-moveable.h>
68 hash = c + (hash << 6) + (hash << 16) - hash;
70 length_ = str - str_ - 1;
73 uint32_t hash()
const {
76 const char *chars()
const {
79 size_t length()
const {
91 static inline bool matches(
const CharsAndLength &lookup,
const ke::AString &key) {
92 return lookup.length() == key.length() &&
93 memcmp(lookup.chars(), key.chars(), key.length()) == 0;
101 template <
typename T>
105 typedef ke::HashMap<ke::AString, T, detail::StringHashMapPolicy> Internal;
109 : internal_(ke::SystemAllocatorPolicy()),
112 if (!internal_.init())
113 internal_.reportOutOfMemory();
116 typedef typename Internal::Result Result;
117 typedef typename Internal::Insert Insert;
118 typedef typename Internal::iterator iterator;
121 bool retrieve(
const char *aKey, T *aResult = NULL)
123 CharsAndLength key(aKey);
124 Result r = internal_.find(key);
132 Result find(
const char *aKey)
134 CharsAndLength key(aKey);
135 return internal_.find(key);
138 bool contains(
const char *aKey)
140 CharsAndLength key(aKey);
141 Result r = internal_.find(key);
145 bool replace(
const char *aKey,
const T &value)
147 CharsAndLength key(aKey);
148 Insert i = internal_.findForAdd(key);
151 memory_used_ += key.length() + 1;
152 if (!internal_.add(i))
160 bool insert(
const char *aKey,
const T &value)
162 CharsAndLength key(aKey);
163 Insert i = internal_.findForAdd(key);
166 if (!internal_.add(i))
168 memory_used_ += key.length() + 1;
174 bool remove(
const char *aKey)
176 CharsAndLength key(aKey);
177 Result r = internal_.find(key);
180 memory_used_ -= key.length() + 1;
185 void remove(Result &r)
197 return internal_.iter();
200 size_t mem_usage()
const
202 return internal_.estimateMemoryUse() + memory_used_;
205 size_t elements()
const
207 return internal_.elements();
211 Insert findForAdd(
const char *aKey)
213 CharsAndLength key(aKey);
214 return internal_.findForAdd(key);
222 return internal_.add(i);
226 bool add(Insert &i,
const char *aKey)
228 if (!internal_.add(i))
241 #endif // _include_sourcemod_hashtable_h_
Definition: sm_stringhashmap.h:58
Definition: sm_stringhashmap.h:102
Definition: sm_stringhashmap.h:89
Definition: IAdminSystem.h:63