32 #ifndef _include_sourcemod_namehashset_h_
33 #define _include_sourcemod_namehashset_h_
41 #include <am-allocator-policies.h>
42 #include <am-hashmap.h>
43 #include <am-string.h>
57 template <
typename T,
typename KeyPolicy = T>
63 template <
typename KeyType,
typename KeyPolicyType>
66 typedef KeyType Payload;
68 static uint32_t hash(
const CharsAndLength &key)
73 static bool matches(
const CharsAndLength &key,
const KeyType &value)
75 return KeyPolicyType::matches(key.chars(), value);
81 template <
typename KeyType>
82 struct Policy<KeyType *, KeyType *>
84 typedef KeyType *Payload;
91 static bool matches(
const CharsAndLength &key,
const KeyType *value)
93 return KeyType::matches(key.chars(), value);
97 typedef ke::HashTable<Policy<T, KeyPolicy>, ke::SystemAllocatorPolicy> Internal;
103 this->reportOutOfMemory();
106 typedef typename Internal::Result Result;
107 typedef typename Internal::Insert Insert;
108 typedef typename Internal::iterator iterator;
110 Result find(
const char *aKey)
112 return table_.find(aKey);
115 Insert findForAdd(
const char *aKey)
117 return table_.findForAdd(aKey);
120 void add(Insert &i,
const T &value)
122 return table_.add(i, value);
125 void add(Insert &i, ke::Moveable<T> value)
127 return table_.add(i, value);
130 bool retrieve(
const char *aKey, T *value)
132 CharsAndLength key(aKey);
133 Result r = table_.find(aKey);
140 bool insert(
const char *aKey,
const T &value)
142 CharsAndLength key(aKey);
143 Insert i = table_.findForAdd(key);
146 return table_.add(i, value);
149 bool insert(
const char *aKey, ke::Moveable<T> value)
151 CharsAndLength key(aKey);
152 Insert i = table_.findForAdd(key);
155 return table_.add(i, value);
158 bool contains(
const char *aKey)
160 CharsAndLength key(aKey);
161 Result r = table_.find(aKey);
165 bool remove(
const char *aKey)
167 CharsAndLength key(aKey);
168 Result r = table_.find(key);
175 void remove(Result &r)
185 size_t mem_usage()
const
187 return table_.estimateMemoryUse();
192 return iterator(&table_);
201 #endif // _include_sourcemod_namehashset_h_
Definition: sm_stringhashmap.h:58
Definition: sm_namehashset.h:58
Generic Key -> Value map class, based on a hash table. The Key, in this case, is always an ASCII stri...
Definition: IAdminSystem.h:63