18 #ifndef INC_KY_Kernel_StringHash_H
19 #define INC_KY_Kernel_StringHash_H
32 template<
class U,
class Allocator = AllocatorGH<U> >
33 class StringHash :
public Hash<String, U, String::NoCaseHashFunctor, Allocator>
37 typedef StringHash<U, Allocator> SelfType;
38 typedef Hash<String, U, String::NoCaseHashFunctor, Allocator> BaseType;
42 void operator = (
const SelfType& src) { BaseType::operator = (src); }
44 bool GetCaseInsensitive(
const String& key, U* pvalue)
const
46 String::NoCaseKey ikey(key);
47 return BaseType::GetAlt(ikey, pvalue);
50 const U* GetCaseInsensitive(
const String& key)
const
52 String::NoCaseKey ikey(key);
53 return BaseType::GetAlt(ikey);
55 U* GetCaseInsensitive(
const String& key)
57 String::NoCaseKey ikey(key);
58 return BaseType::GetAlt(ikey);
62 typedef typename BaseType::Iterator base_iterator;
64 base_iterator FindCaseInsensitive(
const String& key)
66 String::NoCaseKey ikey(key);
67 return BaseType::FindAlt(ikey);
72 void SetCaseInsensitive(
const String& key,
const U& value)
74 base_iterator it = FindCaseInsensitive(key);
75 if (it != BaseType::End())
81 BaseType::Add(key, value);
88 template<
class U,
int SID = Stat_Default_Mem>
89 class StringHash_sid :
public StringHash<U, AllocatorGH<U, SID> >
91 typedef StringHash_sid<U, SID> SelfType;
92 typedef StringHash<U, AllocatorGH<U, SID> > BaseType;
95 void operator = (
const SelfType& src) { BaseType::operator = (src); }
110 template<
class U,
class HashF>
111 struct StringLH_HashNode
120 const String* pFirst;
123 NodeRef(
const String& f,
const U& s) : pFirst(&f), pSecond(&s) { }
124 NodeRef(
const NodeRef& src) : pFirst(src.pFirst), pSecond(src.pSecond) { }
127 inline UPInt GetHash()
const {
return HashF()(*pFirst); }
129 operator const String& ()
const {
return *pFirst; }
133 StringLH_HashNode(
const StringLH_HashNode& src) : First(src.First), Second(src.Second) { }
134 StringLH_HashNode(
const NodeRef& src) : First(*src.pFirst), Second(*src.pSecond) { }
135 void operator = (
const NodeRef& src) { First = *src.pFirst; Second = *src.pSecond; }
139 bool operator == (
const K& src)
const {
return (First == src); }
142 static UPInt CalcHash(
const K& data) {
return HashF()(data); }
143 inline UPInt GetHash()
const {
return HashF()(First); }
150 UPInt operator()(
const K& data)
const {
return data.GetHash(); }
155 UPInt operator()(
const K& data)
const {
return StringLH_HashNode<U,HashF>::CalcHash(data); }
162 template<
class U,
int SID = Stat_Default_Mem,
163 class HashF = String::NoCaseHashFunctor,
164 class HashNode = StringLH_HashNode<U,HashF>,
165 class Entry = HashsetCachedNodeEntry<HashNode, typename HashNode::NodeHashF> >
169 KY_MEMORY_REDEFINE_NEW(StringHashLH, SID)
171 typedef AllocatorLH<U, SID> Allocator;
175 typedef StringHashLH<U, SID, HashF, HashNode, Entry> SelfType;
176 typedef typename HashNode::NodeHashF HashNodeF;
177 typedef HashSet<HashNode, HashNodeF,
178 typename HashNode::NodeAltHashF,
179 Allocator, Entry > Container;
187 StringHashLH(
int sizeHint) : mHash(sizeHint) { }
188 StringHashLH(
const SelfType& src) : mHash(src.mHash) { }
191 void operator = (
const SelfType& src) { mHash = src.mHash; }
194 inline void Clear() { mHash.Clear(); }
196 inline bool IsEmpty()
const {
return mHash.IsEmpty(); }
199 inline void Set(
const String& key,
const U& value)
201 typename HashNode::NodeRef e(key, value);
204 inline void Add(
const String& key,
const U& value)
206 typename HashNode::NodeRef e(key, value);
211 inline void Remove(
const String& key)
213 mHash.RemoveAlt(key);
216 inline void RemoveAlt(
const K& key)
218 mHash.RemoveAlt(key);
225 bool Get(
const String& key, U* pvalue)
const
227 const HashNode* p = mHash.GetAlt(key);
238 bool GetAlt(
const K& key, U* pvalue)
const
240 const HashNode* p = mHash.GetAlt(key);
253 inline U* Get(
const String& key)
255 HashNode* p = mHash.GetAlt(key);
256 return p ? &p->Second : 0;
258 inline const U* Get(
const String& key)
const
260 const HashNode* p = mHash.GetAlt(key);
261 return p ? &p->Second : 0;
265 inline U* GetAlt(
const K& key)
267 HashNode* p = mHash.GetAlt(key);
268 return p ? &p->Second : 0;
271 inline const U* GetAlt(
const K& key)
const
273 const HashNode* p = mHash.GetAlt(key);
274 return p ? &p->Second : 0;
278 inline UPInt GetSize()
const {
return mHash.GetSize(); }
279 inline void Resize(UPInt n) { mHash.Resize(n); }
280 inline void SetSapacity(UPInt newSize) { mHash.RemoveAlt(newSize); }
283 typedef typename Container::ConstIterator ConstIterator;
284 typedef typename Container::Iterator Iterator;
286 inline Iterator Begin() {
return mHash.Begin(); }
287 inline Iterator End() {
return mHash.End(); }
288 inline ConstIterator Begin()
const {
return mHash.Begin(); }
289 inline ConstIterator End()
const {
return mHash.End(); }
291 Iterator Find(
const String& key) {
return mHash.FindAlt(key); }
292 ConstIterator Find(
const String& key)
const {
return mHash.FindAlt(key); }
295 Iterator FindAlt(
const K& key) {
return mHash.FindAlt(key); }
297 ConstIterator FindAlt(
const K& key)
const {
return mHash.FindAlt(key); }
302 bool GetCaseInsensitive(
const String& key, U* pvalue)
const
304 String::NoCaseKey ikey(key);
305 return GetAlt(ikey, pvalue);
308 const U* GetCaseInsensitive(
const String& key)
const
310 String::NoCaseKey ikey(key);
313 U* GetCaseInsensitive(
const String& key)
315 String::NoCaseKey ikey(key);
322 Iterator FindCaseInsensitive(
const String& key)
324 String::NoCaseKey ikey(key);
325 return FindAlt(ikey);
330 void SetCaseInsensitive(
const String& key,
const U& value)
332 Iterator it = FindCaseInsensitive(key);
348 #if defined(KY_DEFINE_NEW)
349 #define new KY_DEFINE_NEW
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17