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; }
138 bool operator == (
const NodeRef& src)
const {
return (First == *src.pFirst); }
142 bool operator == (
const K& src)
const {
return (First == src); }
145 static UPInt KY_STDCALL CalcHash(
const K& data) {
return HashF()(data); }
146 inline UPInt GetHash()
const {
return HashF()(First); }
153 UPInt operator()(
const K& data)
const {
return data.GetHash(); }
158 UPInt operator()(
const K& data)
const {
return StringLH_HashNode<U,HashF>::CalcHash(data); }
165 template<
class U,
int SID = Stat_Default_Mem,
166 class HashF = String::NoCaseHashFunctor,
167 class HashNode = StringLH_HashNode<U,HashF>,
168 class Entry = HashsetCachedNodeEntry<HashNode, typename HashNode::NodeHashF> >
172 KY_MEMORY_REDEFINE_NEW(StringHashLH, SID)
174 typedef AllocatorLH<U, SID> Allocator;
178 typedef StringHashLH<U, SID, HashF, HashNode, Entry> SelfType;
179 typedef typename HashNode::NodeHashF HashNodeF;
180 typedef HashSet<HashNode, HashNodeF,
181 typename HashNode::NodeAltHashF,
182 Allocator, Entry > Container;
190 StringHashLH(
int sizeHint) : mHash(sizeHint) { }
191 StringHashLH(
const SelfType& src) : mHash(src.mHash) { }
194 void operator = (
const SelfType& src) { mHash = src.mHash; }
197 inline void Clear() { mHash.Clear(); }
199 inline bool IsEmpty()
const {
return mHash.IsEmpty(); }
202 inline void Set(
const String& key,
const U& value)
204 typename HashNode::NodeRef e(key, value);
207 inline void Add(
const String& key,
const U& value)
209 typename HashNode::NodeRef e(key, value);
214 inline void Remove(
const String& key)
216 mHash.RemoveAlt(key);
219 inline void RemoveAlt(
const K& key)
221 mHash.RemoveAlt(key);
228 bool Get(
const String& key, U* pvalue)
const
230 const HashNode* p = mHash.GetAlt(key);
241 bool GetAlt(
const K& key, U* pvalue)
const
243 const HashNode* p = mHash.GetAlt(key);
256 inline U* Get(
const String& key)
258 HashNode* p = mHash.GetAlt(key);
259 return p ? &p->Second : 0;
261 inline const U* Get(
const String& key)
const
263 const HashNode* p = mHash.GetAlt(key);
264 return p ? &p->Second : 0;
268 inline U* GetAlt(
const K& key)
270 HashNode* p = mHash.GetAlt(key);
271 return p ? &p->Second : 0;
274 inline const U* GetAlt(
const K& key)
const
276 const HashNode* p = mHash.GetAlt(key);
277 return p ? &p->Second : 0;
281 inline UPInt GetSize()
const {
return mHash.GetSize(); }
282 inline void Resize(UPInt n) { mHash.Resize(n); }
283 inline void SetSapacity(UPInt newSize) { mHash.RemoveAlt(newSize); }
286 typedef typename Container::ConstIterator ConstIterator;
287 typedef typename Container::Iterator Iterator;
289 inline Iterator Begin() {
return mHash.Begin(); }
290 inline Iterator End() {
return mHash.End(); }
291 inline ConstIterator Begin()
const {
return mHash.Begin(); }
292 inline ConstIterator End()
const {
return mHash.End(); }
294 Iterator Find(
const String& key) {
return mHash.FindAlt(key); }
295 ConstIterator Find(
const String& key)
const {
return mHash.FindAlt(key); }
298 Iterator FindAlt(
const K& key) {
return mHash.FindAlt(key); }
300 ConstIterator FindAlt(
const K& key)
const {
return mHash.FindAlt(key); }
305 bool GetCaseInsensitive(
const String& key, U* pvalue)
const
307 String::NoCaseKey ikey(key);
308 return GetAlt(ikey, pvalue);
311 const U* GetCaseInsensitive(
const String& key)
const
313 String::NoCaseKey ikey(key);
316 U* GetCaseInsensitive(
const String& key)
318 String::NoCaseKey ikey(key);
325 Iterator FindCaseInsensitive(
const String& key)
327 String::NoCaseKey ikey(key);
328 return FindAlt(ikey);
333 void SetCaseInsensitive(
const String& key,
const U& value)
335 Iterator it = FindCaseInsensitive(key);
351 #if defined(KY_DEFINE_NEW)
352 #define new KY_DEFINE_NEW
Definition: gamekitcrowddispersion.h:20