5 #pragma pack(push, 1) // pack class size
6 template <
class TKey,
class TDat>
16 THashKeyDat(
const int& _Next,
const int& _HashCd,
const TKey& _Key):
27 &&
Key==HashKeyDat.
Key &&
Dat==HashKeyDat.
Dat)){
return true;}
30 if (
this!=&HashKeyDat){
39 template<
class TKey,
class TDat>
81 static inline int GetPrimHashCd(
const TKey& Key) {
return Key.GetPrimHashCd(); }
82 static inline int GetSecHashCd(
const TKey& Key) {
return Key.GetSecHashCd(); }
87 template<
class TKey,
class TDat,
class THashFunc = TDefaultHashFunc<TKey> >
110 if (
Asc) {
return Hash.GetKey(KeyId1) <
Hash.GetKey(KeyId2); }
111 else {
return Hash.GetKey(KeyId2) <
Hash.GetKey(KeyId1); } }
114 else {
return Hash[KeyId2] <
Hash[KeyId1]; } } }
132 explicit THash(
const int& ExpectVals,
const bool& _AutoSizeP=
false);
161 int64 MemUsed =
sizeof(bool)+2*
sizeof(
int);
163 for (
int KeyDatN = 0; KeyDatN <
KeyDatV.
Len(); KeyDatN++) {
180 void Gen(
const int& ExpectVals){
184 void Clr(
const bool& DoDel=
true,
const int& NoDelLim=-1,
const bool& ResetDat=
true);
193 int AddKey(
const TKey& Key);
197 TDat&
AddDat(
const TKey& Key,
const TDat& Dat){
200 void DelKey(
const TKey& Key);
202 int KeyId;
if (
IsKey(Key, KeyId)){
DelKeyId(KeyId);
return true;}
return false;}
205 for (
int KeyIdN=0; KeyIdN<KeyIdV.
Len(); KeyIdN++){
DelKeyId(KeyIdV[KeyIdN]);}}
211 int GetKeyId(
const TKey& Key)
const;
217 bool IsKey(
const TKey& Key,
int& KeyId)
const { KeyId=
GetKeyId(Key);
return KeyId!=-1;}
224 return KeyId >= 0 ?
KeyDatV[KeyId].Dat : DefaultValue;
229 void GetKeyDat(
const int& KeyId, TKey& Key, TDat& Dat)
const {
231 Key=KeyDat.
Key; Dat=KeyDat.
Dat;}
234 else {
return false;}}
248 void Sort(
const bool& CmpKey,
const bool& Asc);
253 template<
class TKey,
class TDat,
class THashFunc>
255 3ul, 5ul, 11ul, 23ul,
256 53ul, 97ul, 193ul, 389ul, 769ul,
257 1543ul, 3079ul, 6151ul, 12289ul, 24593ul,
258 49157ul, 98317ul, 196613ul, 393241ul, 786433ul,
259 1572869ul, 3145739ul, 6291469ul, 12582917ul, 25165843ul,
260 50331653ul, 100663319ul, 201326611ul, 402653189ul, 805306457ul,
261 1610612741ul, 3221225473ul, 4294967291ul
264 template<
class TKey,
class TDat,
class THashFunc>
266 const uint* f=(
const uint*)HashPrimeT, *m, *l=(
const uint*)HashPrimeT + (int)HashPrimes;
267 int h, len = (int)HashPrimes;
269 h = len >> 1; m = f + h;
270 if (*m < Val) { f = m; f++; len = len - h - 1; }
273 return f == l ? *(l - 1) : *f;
276 template<
class TKey,
class TDat,
class THashFunc>
283 }
else if (AutoSizeP&&(KeyDatV.Len()>2*PortV.Len())){
284 PortV.Gen(GetNextPrime(PortV.Len()+1));
288 PortV.PutAll(
TInt(-1));
290 for (
int KeyId=0; KeyId<KeyDatV.Len(); KeyId++){
293 const int PortN = abs(THashFunc::GetPrimHashCd(KeyDat.
Key) % PortV.Len());
294 KeyDat.
Next=PortV[PortN];
300 template<
class TKey,
class TDat,
class THashFunc>
302 PortV(GetNextPrime(ExpectVals/2)), KeyDatV(ExpectVals, 0),
303 AutoSizeP(_AutoSizeP), FFreeKeyId(-1), FreeKeys(0){
307 template<
class TKey,
class TDat,
class THashFunc>
309 if (Len() != Hash.
Len()) {
return false; }
310 for (
int i = FFirstKeyId(); FNextKeyId(i); ) {
311 const TKey& Key = GetKey(i);
312 if (! Hash.
IsKey(Key)) {
return false; }
313 if (GetDat(Key) != Hash.
GetDat(Key)) {
return false; }
318 template<
class TKey,
class TDat,
class THashFunc>
321 PortV.Clr(); KeyDatV.Clr();
323 PortV.PutAll(
TInt(-1));
324 KeyDatV.Clr(DoDel, NoDelLim);
325 if (ResetDat){KeyDatV.PutAll(
THKeyDat());}
327 FFreeKeyId=
TInt(-1); FreeKeys=
TInt(0);
330 template<
class TKey,
class TDat,
class THashFunc>
332 if ((KeyDatV.Len()>2*PortV.Len())||PortV.Empty()){Resize();}
333 const int PortN=abs(THashFunc::GetPrimHashCd(Key)%PortV.Len());
334 const int HashCd=abs(THashFunc::GetSecHashCd(Key));
336 int KeyId=PortV[PortN];
337 while ((KeyId!=-1) &&
338 !((KeyDatV[KeyId].HashCd==HashCd) && (KeyDatV[KeyId].Key==Key))){
339 PrevKeyId=KeyId; KeyId=KeyDatV[KeyId].Next;}
343 KeyId=KeyDatV.Add(
THKeyDat(-1, HashCd, Key));
345 KeyId=FFreeKeyId; FFreeKeyId=KeyDatV[FFreeKeyId].Next; FreeKeys--;
347 KeyDatV[KeyId].Next=-1;
348 KeyDatV[KeyId].HashCd=HashCd;
349 KeyDatV[KeyId].Key=Key;
355 KeyDatV[PrevKeyId].Next=KeyId;
361 template<
class TKey,
class TDat,
class THashFunc>
364 const int PortN=abs(THashFunc::GetPrimHashCd(Key)%PortV.Len());
365 const int HashCd=abs(THashFunc::GetSecHashCd(Key));
367 int KeyId=PortV[PortN];
369 while ((KeyId!=-1) &&
370 !((KeyDatV[KeyId].HashCd==HashCd) && (KeyDatV[KeyId].Key==Key))){
371 PrevKeyId=KeyId; KeyId=KeyDatV[KeyId].Next;}
375 if (PrevKeyId==-1){PortV[PortN]=KeyDatV[KeyId].Next;}
376 else {KeyDatV[PrevKeyId].Next=KeyDatV[KeyId].Next;}
377 KeyDatV[KeyId].Next=FFreeKeyId; FFreeKeyId=KeyId; FreeKeys++;
378 KeyDatV[KeyId].HashCd=
TInt(-1);
379 KeyDatV[KeyId].Key=TKey();
380 KeyDatV[KeyId].Dat=TDat();
383 template<
class TKey,
class TDat,
class THashFunc>
387 const int PortN=abs(THashFunc::GetPrimHashCd(Key)%PortV.Len());
388 const int HashCd=abs(THashFunc::GetSecHashCd(Key));
390 int KeyId=PortV[PortN];
391 while ((KeyId!=-1) &&
392 !((KeyDatV[KeyId].HashCd==HashCd) && (KeyDatV[KeyId].Key==Key))){
393 PrevKeyId=KeyId; KeyId=KeyDatV[KeyId].Next;}
395 if (PrevKeyId==-1){PortV[PortN]=KeyDatV[KeyId].Next;}
396 else {KeyDatV[PrevKeyId].Next=KeyDatV[KeyId].Next;}
397 KeyDatV[KeyId].Next=FFreeKeyId; FFreeKeyId=KeyId; FreeKeys++;
398 KeyDatV[KeyId].HashCd=
TInt(-1);
401 template<
class TKey,
class TDat,
class THashFunc>
405 while (KeyDatV[KeyId].HashCd == -1) {
412 template<
class TKey,
class TDat,
class THashFunc>
415 if (FreeKeys/
double(Len()+FreeKeys) > EmptyFrac) { Defrag(); }
417 while (KeyDatV[KeyId].HashCd == -1) {
423 template<
class TKey,
class TDat,
class THashFunc>
425 if (PortV.Empty()){
return -1;}
426 const int PortN=abs(THashFunc::GetPrimHashCd(Key)%PortV.Len());
427 const int HashCd=abs(THashFunc::GetSecHashCd(Key));
428 int KeyId=PortV[PortN];
429 while ((KeyId!=-1) &&
430 !((KeyDatV[KeyId].HashCd==HashCd) && (KeyDatV[KeyId].Key==Key))){
431 KeyId=KeyDatV[KeyId].Next;}
435 template<
class TKey,
class TDat,
class THashFunc>
437 do {KeyId++;}
while ((KeyId<KeyDatV.Len())&&(KeyDatV[KeyId].HashCd==-1));
438 return KeyId<KeyDatV.Len();
441 template<
class TKey,
class TDat,
class THashFunc>
444 int KeyId=FFirstKeyId();
445 while (FNextKeyId(KeyId)){
446 KeyV.
Add(GetKey(KeyId));}
449 template<
class TKey,
class TDat,
class THashFunc>
452 int KeyId=FFirstKeyId();
453 while (FNextKeyId(KeyId)){
454 DatV.
Add(GetHashKeyDat(KeyId).Dat);}
457 template<
class TKey,
class TDat,
class THashFunc>
459 KeyDatPrV.Gen(Len(), 0);
461 int KeyId=FFirstKeyId();
462 while (FNextKeyId(KeyId)){
463 GetKeyDat(KeyId, Key, Dat);
468 template<
class TKey,
class TDat,
class THashFunc>
470 DatKeyPrV.Gen(Len(), 0);
472 int KeyId=FFirstKeyId();
473 while (FNextKeyId(KeyId)){
474 GetKeyDat(KeyId, Key, Dat);
479 template<
class TKey,
class TDat,
class THashFunc>
481 KeyDatKdV.Gen(Len(), 0);
483 int KeyId=FFirstKeyId();
484 while (FNextKeyId(KeyId)){
485 GetKeyDat(KeyId, Key, Dat);
490 template<
class TKey,
class TDat,
class THashFunc>
492 DatKeyKdV.Gen(Len(), 0);
494 int KeyId=FFirstKeyId();
495 while (FNextKeyId(KeyId)){
496 GetKeyDat(KeyId, Key, Dat);
501 template<
class TKey,
class TDat,
class THashFunc>
504 PortV.Swap(Hash.
PortV);
512 template<
class TKey,
class TDat,
class THashFunc>
514 if (!IsKeyIdEqKeyN()){
516 int KeyId=FFirstKeyId(); TKey Key; TDat Dat;
517 while (FNextKeyId(KeyId)){
518 GetKeyDat(KeyId, Key, Dat);
519 Hash.AddDat(Key, Dat);
527 template<
class TKey,
class TDat,
class THashFunc>
529 IAssertR(IsKeyIdEqKeyN(),
"THash::Sort only works when table has no deleted keys.");
530 TIntV TargV(Len()), MapV(Len()), StateV(Len());
531 for (
int i = 0; i < TargV.Len(); i++) {
532 TargV[i] = i; MapV[i] = i; StateV[i] = i;
536 TargV.SortCmp(HashCmp);
539 for (
int i = 0; i < TargV.Len()-1; i++) {
540 const int SrcPos = MapV[TargV[i]];
543 Tmp = KeyDatV[SrcPos];
544 KeyDatV[SrcPos] = KeyDatV[Loc];
547 MapV[StateV[i]] = SrcPos;
548 StateV.Swap(Loc, SrcPos);
550 for (
int i = 0; i < TargV.Len(); i++) {
551 MapV[TargV[i]] = i; }
552 for (
int p = 0; p < PortV.Len(); p++) {
553 if (PortV[p] != -1) {
554 PortV[p] = MapV[PortV[p]]; } }
555 for (
int i = 0; i < KeyDatV.Len(); i++) {
556 if (KeyDatV[i].Next != -1) {
557 KeyDatV[i].
Next = MapV[KeyDatV[i].Next]; }
637 template <
class TKey,
class TDat>
658 if (
this!=&Vec){
H=Vec.
H;}
return *
this;}
660 bool operator<(const PHash<TKey, TDat>& Vec)
const {
return H<Vec.H;}
675 void Resize(
TSize _MxBfL);
680 Bf = (
char *) malloc(Pool.MxBfL);
IAssert(Bf); memcpy(Bf, Pool.Bf, Pool.BfL); }
693 bool Empty()
const {
return ! Len(); }
697 return 4 *
sizeof(int) + IdOffV.GetMemUsed() + MxBfL;
700 int AddStr(
const char *Str,
uint Len);
714 void Clr(
bool DoDel =
false) { BfL = 0;
if (DoDel && Bf) { free(Bf); Bf = 0; MxBfL = 0; } }
715 int Cmp(
const int& StrId,
const char *Str)
const {
Assert(StrId < GetStrs());
716 if (StrId != 0)
return strcmp(Bf + (
TSize)IdOffV[StrId], Str);
else return strcmp(
"", Str); }
728 template <
class TDat,
class TStringPool = TStrPool,
class THashFunc = TDefaultHashFunc<TStr> >
777 int AddKey(
const char *Key);
780 int AddDat(
const char *Key,
const TDat& Dat) {
const int KeyId =
AddKey(Key);
KeyDatV[KeyId].Dat = Dat;
return KeyId; }
795 int64 MemUsed =
sizeof(bool)+2*
sizeof(
int);
797 for (
int KeyDatN = 0; KeyDatN <
KeyDatV.
Len(); KeyDatN++) {
803 MemUsed += 8 +
Pool->GetMemUsed();
819 int GetKeyId(
const char *Key)
const;
828 bool IsKey(
const char *Key,
int& KeyId)
const { KeyId =
GetKeyId(Key);
return KeyId != -1; }
829 bool IsKeyGetDat(
const char *Key, TDat& Dat)
const {
const int KeyId =
GetKeyId(Key);
if (KeyId != -1) { Dat =
KeyDatV[KeyId].Dat;
return true; }
else return false; }
846 template <
class TDat,
class TStringPool,
class THashFunc>
851 h = len >> 1; m = f + h;
852 if (*m < Val) { f = m; f++; len = len - h - 1; }
855 return f == l ? *(l - 1) : *f;
858 template <
class TDat,
class TStringPool,
class THashFunc>
861 if (PortV.Empty()) { PortV.Gen(17); PortV.PutAll(-1); }
863 if (AutoSizeP && KeyDatV.Len() > 3 * PortV.Len()) {
864 const int NxPrime = GetNextPrime(KeyDatV.Len());
866 PortV.Gen(NxPrime); PortV.PutAll(-1); }
870 const int NPorts = PortV.Len();
871 for (
int i = 0; i < KeyDatV.Len(); i++) {
873 if (KeyDat.
HashCd != -1) {
874 const int Port = abs(THashFunc::GetPrimHashCd(Pool->GetCStr(KeyDat.
Key)) % NPorts);
875 KeyDat.
Next = PortV[Port];
881 template <
class TDat,
class TStringPool,
class THashFunc>
895 template <
class TDat,
class TStringPool,
class THashFunc>
897 if (Pool.Empty()) Pool = TStringPool::New();
898 if ((AutoSizeP && KeyDatV.Len() > PortV.Len()) || PortV.Empty()) Resize();
899 const int PortN = abs(THashFunc::GetPrimHashCd(Key) % PortV.Len());
900 const int HashCd = abs(THashFunc::GetSecHashCd(Key));
902 int KeyId = PortV[PortN];
903 while (KeyId != -1 && ! (KeyDatV[KeyId].HashCd == HashCd && Pool->Cmp(KeyDatV[KeyId].Key, Key) == 0)) {
904 PrevKeyId = KeyId; KeyId = KeyDatV[KeyId].Next; }
906 const int StrId = Pool->AddStr(Key);
907 if (FFreeKeyId == -1) {
908 KeyId = KeyDatV.Add(
THKeyDat(-1, HashCd, StrId));
911 FFreeKeyId = KeyDatV[FFreeKeyId].Next;
913 KeyDatV[KeyId] =
THKeyDat(-1, HashCd, StrId);
915 if (PrevKeyId == -1) PortV[PortN] = KeyId;
916 else KeyDatV[PrevKeyId].Next = KeyId;
921 template <
class TDat,
class TStringPool,
class THashFunc>
923 if (PortV.Empty())
return -1;
924 const int PortN = abs(THashFunc::GetPrimHashCd(Key) % PortV.Len());
925 const int Hc = abs(THashFunc::GetSecHashCd(Key));
926 int KeyId = PortV[PortN];
927 while (KeyId != -1 && ! (KeyDatV[KeyId].HashCd == Hc && Pool->Cmp(KeyDatV[KeyId].Key, Key) == 0))
928 KeyId = KeyDatV[KeyId].Next;
932 template <
class TDat,
class TStringPool,
class THashFunc>
934 do KeyId++;
while (KeyId < KeyDatV.Len() && KeyDatV[KeyId].HashCd == -1);
935 return KeyId < KeyDatV.Len();
938 template <
class TDat,
class TStringPool,
class THashFunc>
941 int KeyId = FFirstKeyId();
942 while (FNextKeyId(KeyId))
943 KeyV.
Add(GetKey(KeyId));
946 template <
class TDat,
class TStringPool,
class THashFunc>
948 StrIdV.
Gen(Len(), 0);
949 int KeyId = FFirstKeyId();
950 while (FNextKeyId(KeyId))
951 StrIdV.
Add(GetKeyOfs(KeyId));
954 template <
class TDat,
class TStringPool,
class THashFunc>
957 int KeyId = FFirstKeyId();
958 while (FNextKeyId(KeyId))
959 DatV.
Add(GetHashKeyDat(KeyId).Dat);
962 template <
class TDat,
class TStringPool,
class THashFunc>
964 KeyDatPrV.Gen(Len(), 0);
966 int KeyId = FFirstKeyId();
967 while (FNextKeyId(KeyId)){
968 GetKeyDat(KeyId, Str, Dat);
973 template <
class TDat,
class TStringPool,
class THashFunc>
975 DatKeyPrV.Gen(Len(), 0);
977 int KeyId = FFirstKeyId();
978 while (FNextKeyId(KeyId)){
979 GetKeyDat(KeyId, Str, Dat);
992 template <
class TKey,
class TDat,
class THashFunc = TDefaultHashFunc<TKey> >
1015 void Put(
const TKey& Key,
const TDat& Dat);
1016 bool Get(
const TKey& Key, TDat& Dat);
1017 void Del(
const TKey& Key,
const bool& DoEventCall=
true);
1021 bool FNextKeyDat(
void*& KeyDatP, TKey& Key, TDat& Dat);
1027 template <
class TKey,
class TDat,
class THashFunc>
1029 const int64 StartMemUsed = CurMemUsed;
1030 while (!TimeKeyL.Empty()&&(StartMemUsed-CurMemUsed<MemToPurge)){
1031 TKey Key=TimeKeyL.Last()->GetVal();
1036 template <
class TKey,
class TDat,
class THashFunc>
1039 int KeyId=KeyDatH.FFirstKeyId();
1040 while (KeyDatH.FNextKeyId(KeyId)){
1041 const TKey& Key=KeyDatH.GetKey(KeyId);
1043 TDat Dat=KeyLNDatPr.
Val2;
1044 MemUsed+=
int64(Key.GetMemUsed()+Dat->GetMemUsed());
1049 template <
class TKey,
class TDat,
class THashFunc>
1051 CurMemUsed=GetMemUsed();
1052 if (CurMemUsed>MxMemUsed){
1053 Purge(CurMemUsed-MxMemUsed);
1059 template <
class TKey,
class TDat,
class THashFunc>
1061 int KeyId=KeyDatH.GetKeyId(Key);
1063 int64 KeyDatMem=
int64(Key.GetMemUsed()+Dat->GetMemUsed());
1064 if (CurMemUsed+KeyDatMem>MxMemUsed){Purge(KeyDatMem);}
1065 CurMemUsed+=KeyDatMem;
1066 TKeyLN KeyLN=TimeKeyL.AddFront(Key);
1068 KeyDatH.AddDat(Key, KeyLNDatPr);
1072 KeyLNDatPr.
Val2=Dat;
1073 TimeKeyL.PutFront(KeyLN);
1077 template <
class TKey,
class TDat,
class THashFunc>
1079 int KeyId=KeyDatH.GetKeyId(Key);
1083 Dat=KeyDatH[KeyId].Val2;
1088 template <
class TKey,
class TDat,
class THashFunc>
1090 int KeyId=KeyDatH.GetKeyId(Key);
1094 TDat& Dat=KeyLNDatPr.
Val2;
1096 Dat->OnDelFromCache(Key, RefToBs);}
1097 CurMemUsed-=
int64(Key.GetMemUsed()+Dat->GetMemUsed());
1099 TimeKeyL.Del(KeyLN);
1100 KeyDatH.DelKeyId(KeyId);
1104 template <
class TKey,
class TDat,
class THashFunc>
1106 printf(
"To flush: %d\n", KeyDatH.Len());
1107 int KeyId=KeyDatH.FFirstKeyId();
int Done = 0;
1108 while (KeyDatH.FNextKeyId(KeyId)){
1109 if (Done%10000==0){printf(
"%d\r", Done);}
1110 const TKey& Key=KeyDatH.GetKey(KeyId);
1112 TDat Dat=KeyLNDatPr.
Val2;
1113 Dat->OnDelFromCache(Key, RefToBs);
1116 printf(
"Done %d\n", KeyDatH.Len());
1119 template <
class TKey,
class TDat,
class THashFunc>
1127 template <
class TKey,
class TDat,
class THashFunc>
1129 return TimeKeyL.First();
1132 template <
class TKey,
class TDat,
class THashFunc>
1137 Key=
TKeyLN(KeyDatP)->
GetVal(); Dat=KeyDatH.GetDat(Key).Val2;
1138 KeyDatP=
TKeyLN(KeyDatP)->
Next();
return true;
1149 const int MulBy = 16;
1151 while (*p) { HashCd = (MulBy * HashCd) + *p++; HashCd &= 0x0FFFFFFF; }
1154 const int MulBy = 16;
1156 while (*p) { HashCd = (MulBy * HashCd) ^ *p++; HashCd &= 0x0FFFFFFF; }
1175 unsigned int hash = 5381;
1176 for(
unsigned int i = 0; i < Len; Str++, i++) {
1177 hash = ((hash << 5) + hash) + (*Str); }
1182 const char *r = p;
while (*r) { r++; }
1183 return (
int)
DJBHash((
const char *) p, r - p) & 0x7fffffff; }
1185 const char *r = p;
while (*r) { r++; }
1186 return (
int)
DJBHash((
const char *) p, r - p) & 0x7fffffff; }
1192 return (
int)
DJBHash((
const char *) p, Len) & 0x7fffffff; }
1194 return (
int)
DJBHash((
const char *) p, Len) & 0x7fffffff; }
1198 template <
class TVec>
1203 for (
int ValN=0; ValN<Vec.
Len(); ValN++){
1209 for (
int ValN=0; ValN<Vec.
Len(); ValN++){
bool IsKey(const TChA &Key) const
void GetKeyDat(const int &KeyId, TChA &Key, TDat &Dat) const
bool operator==(const THashKeyDat &HashKeyDat) const
const TDat & GetDat(const TStr &Key) const
void GetKeyDat(const int &KeyId, TStr &Key, TDat &Dat) const
TIter EndI() const
Returns an iterator referring to the past-the-end element in the vector.
THash< TInt, TFltPr > TIntFltPrH
THash< TStr, TStr > TStrStrH
int AddDat(const TStr &Key, const TDat &Dat)
PStringPool GetPool() const
bool IsKeyIdEqKeyN() const
TSizeTy Reserved() const
Returns the size of allocated storage capacity.
int GetKeyOfs(const int &KeyId) const
TVec< THKeyDat > THKeyDatV
#define IAssertR(Cond, Reason)
THash< TStr, TFltV > TStrFltVH
int GetPrimHashCd() const
Returns primary hash code of the vector. Used by THash.
THashKeyDatI(const THashKeyDatI &_HashKeyDatI)
THash< TStr, TInt > TStrH
THash< TIntTr, TFlt > TIntTrFltH
THashKeyDat & operator=(const THashKeyDat &HashKeyDat)
void GetDatV(TVec< TDat > &DatV) const
TPt & operator=(const TPt &Pt)
THash< TIntPr, TIntPrV > TIntPrIntPrVH
THash< TIntTr, TInt > TIntTrIntH
::TSize GetMemUsed() const
const char * GetCStr(const int &StrId) const
TDat & operator[](const int &KeyId)
TDat & GetDat(const char *Key)
bool IsKeyGetDat(const TChA &Key, TDat &Dat) const
void Sort(const bool &CmpKey, const bool &Asc)
THash< TInt, TStrPrV > TIntStrPrVH
THash & operator=(const THash &Hash)
bool operator==(const THashKeyDatI &HashKeyDatI) const
THash< TStr, TUInt64V > TStrUInt64VH
THash< TUInt64, TInt > TUInt64H
THash< TStrIntPr, TInt > TStrIntPrIntH
static PBigStrPool New(TSize _MxBfLen=0, uint _GrowBy=16 *1024 *1024)
void Save(TSOut &SOut) const
bool operator==(const THash &Hash) const
THash< TStr, TIntV > TStrIntVH
const THKeyDat & GetHashKeyDat(const int &KeyId) const
bool IsKeyId(const int &KeyId) const
TDat & operator()(const TKey &Key)
TCache(const int64 &_MxMemUsed, const int &Ports, void *_RefToBs)
THash< TInt, TIntH > TIntIntHH
void GetKeyDat(const int &KeyId, TKey &Key, TDat &Dat) const
static int GetSecHashCd(const TStr &s)
void GetKeyDat(const int &KeyId, const char *&Key, TDat &Dat) const
TSizeTy Len() const
Returns the number of elements in the vector.
int GetSecHashCd() const
Returns secondary hash code of the vector. Used by THash.
THash< TStr, TStrPr > TStrStrPrH
void Save(TSOut &SOut) const
TDat & AddDatId(const TStr &Key)
static int GetSecHashCd(const TKey &Key)
static const unsigned int HashPrimeT[HashPrimes]
static PBigStrPool New(const TStr &fileName)
TStr GetStr(const int &StrId) const
int AddStr(const TStr &Str)
void Purge(const int64 &MemToPurge)
TPair< TKeyLN, TDat > TKeyLNDatPr
TDat & operator[](const int &KeyId)
THashKeyDat(const int &_Next, const int &_HashCd, const TKey &_Key)
void SetPool(const PStringPool &StrPool)
THash< TIntPr, TStrV > TIntPrStrVH
bool IsKeyGetDat(const TStr &Key, TDat &Dat) const
TDat GetDatWithDefault(const TKey &Key, TDat DefaultValue)
int AddDat(const char *Key, const TDat &Dat)
THash< TStrTr, TInt > TStrTrIntH
TDat & AddDatId(const char *Key)
void Save(TSOut &SOut) const
THash< TIntPr, TFlt > TIntPrFltH
int AddKey(const TStr &Key)
THash< TInt, TUInt64 > TIntUInt64H
static int GetPrimHashCd(const char *p)
TPt< TBigStrPool > PBigStrPool
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
THash< TIntPr, TIntV > TIntPrIntVH
void Put(const TKey &Key, const TDat &Dat)
THash< TInt, TStr > TIntStrH
const TDat & GetDat(const TKey &Key) const
bool IsEmpty() const
Tests whether the iterator has been initialized.
void DelKeyId(const int &KeyId)
const TDat & operator[](const int &KeyId) const
TDat & GetDat(const TKey &Key)
THash< TIntPr, TInt > TIntPrIntH
void DelKeyIdV(const TIntV &KeyIdV)
TSizeTy GetMemUsed() const
Returns the memory footprint (the number of bytes) of the vector.
static int GetSecHashCd(const char *p)
bool FNextKeyId(int &KeyId) const
const char * GetCStrFromOffset(const TSize &Offset) const
THash< TUInt, TUInt > TUIntH
void GetDatKeyPrV(TVec< TPair< TDat, TKey > > &DatKeyPrV) const
void GetDatV(TVec< TDat > &DatV) const
THash< TChTr, TInt > TChTrIntH
TStr GetStrFromOffset(const TSize &Offset) const
void Save(TSOut &SOut) const
TPair< TKey, TDat > TKeyDatP
const TKey & GetKey() const
void Save(const TStr &fileName)
THash< TStrV, TInt > TStrVIntH
int GetSecHashCd(const int &StrId)
void Save(TSOut &SOut) const
int AddStr(const char *Str)
bool Get(const TKey &Key, TDat &Dat)
THash< TDbStr, TStr > TDbStrStrH
THash< TStrPr, TStrV > TStrPrStrVH
#define ClassTP(TNm, PNm)
THash< TStrV, TStrV > TStrVStrVH
TStrHash< TInt > TStrIntSH
const char * KeyFromOfs(const int &KeyO) const
static PSIn New(const TStr &FNm)
void DelKey(const TKey &Key)
int AddKey(const TChA &Key)
int Cmp(const int &StrId, const char *Str) const
void MarkDelKey(const TKey &Key)
THash< TInt, TFltTr > TIntFltTrH
bool operator<(const THashKeyDatI &HashKeyDatI) const
THash< TInt, TFlt > TIntFltH
THash< TInt, TFltV > TIntFltVH
void LoadXml(const PXmlTok &XmlTok, const TStr &Nm="")
const TDat & GetDat() const
static TPt< PHash< TKey, TDat > > New()
THash< TInt, TInt > TIntIntH
THash< TStr, TIntPr > TStrIntPrH
void Gen(const int &ExpectVals)
void GetDatKeyPrV(TVec< TPair< TDat, TStr > > &DatKeyPrV) const
bool IsKey(const char *Key) const
THash< TStr, TIntFltPr > TStrIntFltPrH
THashKeyDat< TKey, TDat > THKeyDat
static int GetSecHashCd(const char *p, const ::TSize &Len)
bool IsEnd() const
Tests whether the iterator is pointing to the past-end element.
TDat & AddDat(const TKey &Key, const TDat &Dat)
static int GetPrimHashCd(const TStr &s)
THash< TInt, TIntFltPr > TIntIntFltPrH
void PutAll(const TVal &Val)
Sets all elements of the vector to value Val.
void PutRefToBs(void *_RefToBs)
static TPt< PHash< TKey, TDat > > New(const int &MxVals, const int &Vals)
bool IsKeyIdEqKeyN() const
THash< TStrV, TIntV > TStrVIntVH
THash< TStr, TStrIntKdV > TStrStrIntKdVH
static PBigStrPool New(TSIn &SIn)
const char * GetKey(const int &KeyId) const
static int GetPrimHashCd(const char *p, const ::TSize &Len)
TPair< TInt, TDat > TKeyDatP
void GetKeyDatPrV(TVec< TPair< TStr, TDat > > &KeyDatPrV) const
void Del(const TKey &Key, const bool &DoEventCall=true)
static TPt< PHash< TKey, TDat > > Load(TSIn &SIn)
THashKeyDatI & operator++(int)
bool FNextKeyId(int &KeyId) const
bool IsKeyGetDat(const TKey &Key, TDat &Dat) const
THash< TInt, TIntV > TIntIntVH
THash< TIntIntPrPr, TFlt > TIntIntPrPrFltH
THashKeyDatCmp(THash< TKey, TDat, THashFunc > &_Hash, const bool &_CmpKey, const bool &_Asc)
THashKeyDatI(const THKeyDat *_KeyDatI, const THKeyDat *_EndI)
THash< TIntIntPrPr, TInt > TIntIntPrPrIntH
TRec * operator()() const
::TSize GetMemUsed() const
const THKeyDat & GetHashKeyDat(const int &KeyId) const
void Save(TSOut &SOut, bool PoolToo=true) const
static int GetPrimHashCd(const char *p)
THash< TStrPr, TBool > TStrPrBoolH
THash< TStr, TFlt > TStrFltH
void GetKeyDat(const int &KeyId, int &KeyO, TDat &Dat) const
THash< TIntV, TInt > TIntVIntH
int64 GetMxMemUsed() const
void Save(TSOut &SOut) const
THash< TStrPr, TStr > TStrPrStrH
TDat & GetDatId(const int &KeyId)
THash< TKey, TKeyLNDatPr, THashFunc > KeyDatH
TStrHash(const int &Ports, const bool &_AutoSizeP=false, const PStringPool &StrPool=PStringPool())
const TDat & operator[](const int &KeyId) const
The [] operator takes KeyId, use GetDat() if you need value access via the key.
THash< TInt, TInt > TIntH
PHash< TKey, TDat > & operator=(const PHash< TKey, TDat > &Vec)
THashKeyDatI< TKey, TDat > TIter
const TDat & operator()(const char *Key) const
int AddKey(const char *Key)
uint GetNextPrime(const uint &Val) const
THash< TDbStr, TInt > TDbStrIntH
THashKeyDat< TKey, TDat > THKeyDat
bool FNextKeyDat(void *&KeyDatP, TKey &Key, TDat &Dat)
THash< TStr, TUInt64 > TStrUInt64H
void SortByKey(const bool &Asc=true)
int GetKeyId(const TKey &Key) const
const TDat & GetDatId(const int &KeyId) const
THash< TIntStrPr, TInt > TIntStrPrIntH
TStrHash(const PStringPool &StrPool)
int AddKey(const TKey &Key)
static PBigStrPool Load(TSIn &SIn, bool LoadCompacted=true)
void Load(TSIn &SIn, bool PoolToo=true)
TDat & AddDat(const TStr &Key)
THash< TIntIntPrPr, TStr > TIntIntPrPrStrH
int GetKeyId(const TStr &Key) const
THash< TStr, TStrKdV > TStrStrKdVH
bool operator<(const THash &Hash) const
THKeyDat * operator->() const
THash< TStr, TIntPrV > TStrIntPrVH
void GetStrIdV(TIntV &StrIdV) const
void GetKeyV(TVec< TKey > &KeyV) const
THash< TIntPr, TStr > TIntPrStrH
TStrHash(const TStrHash &Hash)
THash< TStr, TStrIntPrV > TStrStrIntPrVH
void Save(TSOut &SOut) const
int GetReservedKeyIds() const
uint GetNextPrime(const uint &Val) const
const TDat & GetDat(const TStr &Key)
TIter BegI() const
Returns an iterator pointing to the first element in the vector.
void Pack()
Reduces vector capacity (frees memory) to match its size.
THashKeyDatI & operator=(const THashKeyDatI &HashKeyDatI)
THash< TStr, TStrV > TStrStrVH
THash< TIntPr, TIntPr > TIntPrH
THKeyDat & GetHashKeyDat(const int &KeyId)
void SaveXml(TSOut &SOut, const TStr &Nm)
static int GetPrimHashCd(const TKey &Key)
void GetKeyDatPrV(TVec< TPair< TKey, TDat > > &KeyDatPrV) const
THKeyDat & operator*() const
void GetKeyV(TVec< TStr > &KeyV) const
static int GetSecHashCd(const TVec &Vec)
bool operator()(const int &KeyId1, const int &KeyId2) const
bool DelIfKey(const TKey &Key)
void Clr(bool DoDel=false)
void Clr(const bool &DoDel=true, const int &NoDelLim=-1, const bool &ResetDat=true)
THash< TStrV, TInt > TStrVH
static int GetSecHashCd(const TStr &s)
THash< TStr, TBool > TStrBoolH
TStrHash< TIntV > TStrToIntVSH
int GetRndKeyId(TRnd &Rnd) const
Get an index of a random element. If the hash table has many deleted keys, this may take a long time...
THash< TStrV, TStr > TStrVStrH
THash< TFlt, TFlt > TFltFltH
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
TStrHash & operator=(const TStrHash &Hash)
THashKeyDat< TInt, TDat > THKeyDat
int GetUniDevInt(const int &Range=0)
int GetPrimHashCd(const int &StrId)
TDat & AddDat(const char *Key)
const THash< TKey, TDat, THashFunc > & Hash
bool IsKeyGetDat(const char *Key, TDat &Dat) const
TStrHash(TSIn &SIn, bool PoolToo=true)
TDat & AddDatId(const TKey &Key)
THKeyDat & GetHashKeyDat(const int &KeyId)
TPt< TStringPool > PStringPool
bool IsKey(const TKey &Key, int &KeyId) const
static int GetPrimHashCd(const TStr &s)
bool IsKey(const TKey &Key) const
bool operator==(const PHash< TKey, TDat > &Vec) const
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
static unsigned int DJBHash(const char *Str, const ::TSize &Len)
THash< TStr, TInt > TStrIntH
THash< TUInt64, TStrV > TUInt64StrVH
static TPt< PHash< TKey, TDat > > New(const THash< TKey, TDat > &H)
TDat & AddDat(const TKey &Key)
THKeyDat & operator()() const
bool IsKey(const char *Key, int &KeyId) const
TCache & operator=(const TCache &)
THash< TStrPr, TFlt > TStrPrFltH
THash< TStr, TStrPrV > TStrStrPrVH
TDat & AddDat(const TChA &Key)
THash< TInt, TStrV > TIntStrVH
THash< TInt, TIntPr > TIntIntPrH
THash< TStrPr, TInt > TStrPrIntH
static int GetPrimHashCd(const TVec &Vec)
TDat & AddDatId(const TChA &Key)
int GetPrimHashCd() const
int AddDat(const TChA &Key, const TDat &Dat)
const TKey & GetKey(const int &KeyId) const
bool IsKey(const TStr &Key) const
const TDat & GetDat(const TChA &Key)
void GetDatKeyKdV(TVec< TKeyDat< TDat, TKey > > &DatKeyKdV) const
THash< TInt, TIntPrV > TIntIntPrVH
void GetKeyDatKdV(TVec< TKeyDat< TKey, TDat > > &KeyDatKdV) const
THash< TInt, TIntStrPr > TIntIntStrPrH
static int GetSecHashCd(const char *p)
THash< TInt, TBool > TIntBoolH
int GetKeyId(const char *Key) const
void Swap(TRec &Rec1, TRec &Rec2)
void MarkDelKeyId(const int &KeyId)
bool IsKeyId(const int &KeyId) const
void SaveXml(TSOut &SOut, const TStr &Nm) const
THashKeyDatI & operator--(int)
const TDat & GetDat(const char *Key) const
static int GetPrimHashCd(const char *p)
TIter GetI(const TKey &Key) const
void SortByDat(const bool &Asc=true)
static int GetSecHashCd(const char *p)