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;}
225 void GetKeyDat(
const int& KeyId, TKey& Key, TDat& Dat)
const {
227 Key=KeyDat.
Key; Dat=KeyDat.
Dat;}
230 else {
return false;}}
244 void Sort(
const bool& CmpKey,
const bool& Asc);
249 template<
class TKey,
class TDat,
class THashFunc>
251 3ul, 5ul, 11ul, 23ul,
252 53ul, 97ul, 193ul, 389ul, 769ul,
253 1543ul, 3079ul, 6151ul, 12289ul, 24593ul,
254 49157ul, 98317ul, 196613ul, 393241ul, 786433ul,
255 1572869ul, 3145739ul, 6291469ul, 12582917ul, 25165843ul,
256 50331653ul, 100663319ul, 201326611ul, 402653189ul, 805306457ul,
257 1610612741ul, 3221225473ul, 4294967291ul
260 template<
class TKey,
class TDat,
class THashFunc>
262 const uint* f=(
const uint*)HashPrimeT, *m, *l=(
const uint*)HashPrimeT + (int)HashPrimes;
263 int h, len = (int)HashPrimes;
265 h = len >> 1; m = f + h;
266 if (*m < Val) { f = m; f++; len = len - h - 1; }
269 return f == l ? *(l - 1) : *f;
272 template<
class TKey,
class TDat,
class THashFunc>
279 }
else if (AutoSizeP&&(KeyDatV.Len()>2*PortV.Len())){
280 PortV.Gen(GetNextPrime(PortV.Len()+1));
284 PortV.PutAll(
TInt(-1));
286 for (
int KeyId=0; KeyId<KeyDatV.Len(); KeyId++){
289 const int PortN = abs(THashFunc::GetPrimHashCd(KeyDat.
Key) % PortV.Len());
290 KeyDat.
Next=PortV[PortN];
296 template<
class TKey,
class TDat,
class THashFunc>
298 PortV(GetNextPrime(ExpectVals/2)), KeyDatV(ExpectVals, 0),
299 AutoSizeP(_AutoSizeP), FFreeKeyId(-1), FreeKeys(0){
303 template<
class TKey,
class TDat,
class THashFunc>
305 if (Len() != Hash.
Len()) {
return false; }
306 for (
int i = FFirstKeyId(); FNextKeyId(i); ) {
307 const TKey& Key = GetKey(i);
308 if (! Hash.
IsKey(Key)) {
return false; }
309 if (GetDat(Key) != Hash.
GetDat(Key)) {
return false; }
314 template<
class TKey,
class TDat,
class THashFunc>
317 PortV.Clr(); KeyDatV.Clr();
319 PortV.PutAll(
TInt(-1));
320 KeyDatV.Clr(DoDel, NoDelLim);
321 if (ResetDat){KeyDatV.PutAll(
THKeyDat());}
323 FFreeKeyId=
TInt(-1); FreeKeys=
TInt(0);
326 template<
class TKey,
class TDat,
class THashFunc>
328 if ((KeyDatV.Len()>2*PortV.Len())||PortV.Empty()){Resize();}
329 const int PortN=abs(THashFunc::GetPrimHashCd(Key)%PortV.Len());
330 const int HashCd=abs(THashFunc::GetSecHashCd(Key));
332 int KeyId=PortV[PortN];
333 while ((KeyId!=-1) &&
334 !((KeyDatV[KeyId].HashCd==HashCd) && (KeyDatV[KeyId].Key==Key))){
335 PrevKeyId=KeyId; KeyId=KeyDatV[KeyId].Next;}
339 KeyId=KeyDatV.Add(
THKeyDat(-1, HashCd, Key));
341 KeyId=FFreeKeyId; FFreeKeyId=KeyDatV[FFreeKeyId].Next; FreeKeys--;
343 KeyDatV[KeyId].Next=-1;
344 KeyDatV[KeyId].HashCd=HashCd;
345 KeyDatV[KeyId].Key=Key;
351 KeyDatV[PrevKeyId].Next=KeyId;
357 template<
class TKey,
class TDat,
class THashFunc>
360 const int PortN=abs(THashFunc::GetPrimHashCd(Key)%PortV.Len());
361 const int HashCd=abs(THashFunc::GetSecHashCd(Key));
363 int KeyId=PortV[PortN];
365 while ((KeyId!=-1) &&
366 !((KeyDatV[KeyId].HashCd==HashCd) && (KeyDatV[KeyId].Key==Key))){
367 PrevKeyId=KeyId; KeyId=KeyDatV[KeyId].Next;}
371 if (PrevKeyId==-1){PortV[PortN]=KeyDatV[KeyId].Next;}
372 else {KeyDatV[PrevKeyId].Next=KeyDatV[KeyId].Next;}
373 KeyDatV[KeyId].Next=FFreeKeyId; FFreeKeyId=KeyId; FreeKeys++;
374 KeyDatV[KeyId].HashCd=
TInt(-1);
375 KeyDatV[KeyId].Key=TKey();
376 KeyDatV[KeyId].Dat=TDat();
379 template<
class TKey,
class TDat,
class THashFunc>
383 const int PortN=abs(THashFunc::GetPrimHashCd(Key)%PortV.Len());
384 const int HashCd=abs(THashFunc::GetSecHashCd(Key));
386 int KeyId=PortV[PortN];
387 while ((KeyId!=-1) &&
388 !((KeyDatV[KeyId].HashCd==HashCd) && (KeyDatV[KeyId].Key==Key))){
389 PrevKeyId=KeyId; KeyId=KeyDatV[KeyId].Next;}
391 if (PrevKeyId==-1){PortV[PortN]=KeyDatV[KeyId].Next;}
392 else {KeyDatV[PrevKeyId].Next=KeyDatV[KeyId].Next;}
393 KeyDatV[KeyId].Next=FFreeKeyId; FFreeKeyId=KeyId; FreeKeys++;
394 KeyDatV[KeyId].HashCd=
TInt(-1);
397 template<
class TKey,
class TDat,
class THashFunc>
401 while (KeyDatV[KeyId].HashCd == -1) {
408 template<
class TKey,
class TDat,
class THashFunc>
411 if (FreeKeys/
double(Len()+FreeKeys) > EmptyFrac) { Defrag(); }
413 while (KeyDatV[KeyId].HashCd == -1) {
419 template<
class TKey,
class TDat,
class THashFunc>
421 if (PortV.Empty()){
return -1;}
422 const int PortN=abs(THashFunc::GetPrimHashCd(Key)%PortV.Len());
423 const int HashCd=abs(THashFunc::GetSecHashCd(Key));
424 int KeyId=PortV[PortN];
425 while ((KeyId!=-1) &&
426 !((KeyDatV[KeyId].HashCd==HashCd) && (KeyDatV[KeyId].Key==Key))){
427 KeyId=KeyDatV[KeyId].Next;}
431 template<
class TKey,
class TDat,
class THashFunc>
433 do {KeyId++;}
while ((KeyId<KeyDatV.Len())&&(KeyDatV[KeyId].HashCd==-1));
434 return KeyId<KeyDatV.Len();
437 template<
class TKey,
class TDat,
class THashFunc>
440 int KeyId=FFirstKeyId();
441 while (FNextKeyId(KeyId)){
442 KeyV.
Add(GetKey(KeyId));}
445 template<
class TKey,
class TDat,
class THashFunc>
448 int KeyId=FFirstKeyId();
449 while (FNextKeyId(KeyId)){
450 DatV.
Add(GetHashKeyDat(KeyId).Dat);}
453 template<
class TKey,
class TDat,
class THashFunc>
455 KeyDatPrV.Gen(Len(), 0);
457 int KeyId=FFirstKeyId();
458 while (FNextKeyId(KeyId)){
459 GetKeyDat(KeyId, Key, Dat);
464 template<
class TKey,
class TDat,
class THashFunc>
466 DatKeyPrV.Gen(Len(), 0);
468 int KeyId=FFirstKeyId();
469 while (FNextKeyId(KeyId)){
470 GetKeyDat(KeyId, Key, Dat);
475 template<
class TKey,
class TDat,
class THashFunc>
477 KeyDatKdV.Gen(Len(), 0);
479 int KeyId=FFirstKeyId();
480 while (FNextKeyId(KeyId)){
481 GetKeyDat(KeyId, Key, Dat);
486 template<
class TKey,
class TDat,
class THashFunc>
488 DatKeyKdV.Gen(Len(), 0);
490 int KeyId=FFirstKeyId();
491 while (FNextKeyId(KeyId)){
492 GetKeyDat(KeyId, Key, Dat);
497 template<
class TKey,
class TDat,
class THashFunc>
500 PortV.Swap(Hash.
PortV);
508 template<
class TKey,
class TDat,
class THashFunc>
510 if (!IsKeyIdEqKeyN()){
512 int KeyId=FFirstKeyId(); TKey Key; TDat Dat;
513 while (FNextKeyId(KeyId)){
514 GetKeyDat(KeyId, Key, Dat);
515 Hash.AddDat(Key, Dat);
523 template<
class TKey,
class TDat,
class THashFunc>
525 IAssertR(IsKeyIdEqKeyN(),
"THash::Sort only works when table has no deleted keys.");
526 TIntV TargV(Len()), MapV(Len()), StateV(Len());
527 for (
int i = 0; i < TargV.Len(); i++) {
528 TargV[i] = i; MapV[i] = i; StateV[i] = i;
532 TargV.SortCmp(HashCmp);
535 for (
int i = 0; i < TargV.Len()-1; i++) {
536 const int SrcPos = MapV[TargV[i]];
539 Tmp = KeyDatV[SrcPos];
540 KeyDatV[SrcPos] = KeyDatV[Loc];
543 MapV[StateV[i]] = SrcPos;
544 StateV.Swap(Loc, SrcPos);
546 for (
int i = 0; i < TargV.Len(); i++) {
547 MapV[TargV[i]] = i; }
548 for (
int p = 0; p < PortV.Len(); p++) {
549 if (PortV[p] != -1) {
550 PortV[p] = MapV[PortV[p]]; } }
551 for (
int i = 0; i < KeyDatV.Len(); i++) {
552 if (KeyDatV[i].Next != -1) {
553 KeyDatV[i].
Next = MapV[KeyDatV[i].Next]; }
627 template <
class TKey,
class TDat>
648 if (
this!=&Vec){
H=Vec.
H;}
return *
this;}
650 bool operator<(const PHash<TKey, TDat>& Vec)
const {
return H<Vec.H;}
665 void Resize(
TSize _MxBfL);
670 Bf = (
char *) malloc(Pool.MxBfL);
IAssert(Bf); memcpy(Bf, Pool.Bf, Pool.BfL); }
683 bool Empty()
const {
return ! Len(); }
687 int AddStr(
const char *Str,
uint Len);
701 void Clr(
bool DoDel =
false) { BfL = 0;
if (DoDel && Bf) { free(Bf); Bf = 0; MxBfL = 0; } }
702 int Cmp(
const int& StrId,
const char *Str)
const {
Assert(StrId < GetStrs());
703 if (StrId != 0)
return strcmp(Bf + (
TSize)IdOffV[StrId], Str);
else return strcmp(
"", Str); }
715 template <
class TDat,
class TStringPool = TStrPool,
class THashFunc = TDefaultHashFunc<TStr> >
763 int AddKey(
const char *Key);
766 int AddDat(
const char *Key,
const TDat& Dat) {
const int KeyId =
AddKey(Key);
KeyDatV[KeyId].Dat = Dat;
return KeyId; }
793 int GetKeyId(
const char *Key)
const;
802 bool IsKey(
const char *Key,
int& KeyId)
const { KeyId =
GetKeyId(Key);
return KeyId != -1; }
803 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; }
820 template <
class TDat,
class TStringPool,
class THashFunc>
825 h = len >> 1; m = f + h;
826 if (*m < Val) { f = m; f++; len = len - h - 1; }
829 return f == l ? *(l - 1) : *f;
832 template <
class TDat,
class TStringPool,
class THashFunc>
835 if (PortV.Empty()) { PortV.Gen(17); PortV.PutAll(-1); }
837 if (AutoSizeP && KeyDatV.Len() > 3 * PortV.Len()) {
838 const int NxPrime = GetNextPrime(KeyDatV.Len());
840 PortV.Gen(NxPrime); PortV.PutAll(-1); }
844 const int NPorts = PortV.Len();
845 for (
int i = 0; i < KeyDatV.Len(); i++) {
847 if (KeyDat.
HashCd != -1) {
848 const int Port = abs(THashFunc::GetPrimHashCd(Pool->GetCStr(KeyDat.
Key)) % NPorts);
849 KeyDat.
Next = PortV[Port];
855 template <
class TDat,
class TStringPool,
class THashFunc>
869 template <
class TDat,
class TStringPool,
class THashFunc>
871 if (Pool.Empty()) Pool = TStringPool::New();
872 if ((AutoSizeP && KeyDatV.Len() > PortV.Len()) || PortV.Empty()) Resize();
873 const int PortN = abs(THashFunc::GetPrimHashCd(Key) % PortV.Len());
874 const int HashCd = abs(THashFunc::GetSecHashCd(Key));
876 int KeyId = PortV[PortN];
877 while (KeyId != -1 && ! (KeyDatV[KeyId].HashCd == HashCd && Pool->Cmp(KeyDatV[KeyId].Key, Key) == 0)) {
878 PrevKeyId = KeyId; KeyId = KeyDatV[KeyId].Next; }
880 const int StrId = Pool->AddStr(Key);
881 if (FFreeKeyId == -1) {
882 KeyId = KeyDatV.Add(
THKeyDat(-1, HashCd, StrId));
885 FFreeKeyId = KeyDatV[FFreeKeyId].Next;
887 KeyDatV[KeyId] =
THKeyDat(-1, HashCd, StrId);
889 if (PrevKeyId == -1) PortV[PortN] = KeyId;
890 else KeyDatV[PrevKeyId].Next = KeyId;
895 template <
class TDat,
class TStringPool,
class THashFunc>
897 if (PortV.Empty())
return -1;
898 const int PortN = abs(THashFunc::GetPrimHashCd(Key) % PortV.Len());
899 const int Hc = abs(THashFunc::GetSecHashCd(Key));
900 int KeyId = PortV[PortN];
901 while (KeyId != -1 && ! (KeyDatV[KeyId].HashCd == Hc && Pool->Cmp(KeyDatV[KeyId].Key, Key) == 0))
902 KeyId = KeyDatV[KeyId].Next;
906 template <
class TDat,
class TStringPool,
class THashFunc>
908 do KeyId++;
while (KeyId < KeyDatV.Len() && KeyDatV[KeyId].HashCd == -1);
909 return KeyId < KeyDatV.Len();
912 template <
class TDat,
class TStringPool,
class THashFunc>
915 int KeyId = FFirstKeyId();
916 while (FNextKeyId(KeyId))
917 KeyV.
Add(GetKey(KeyId));
920 template <
class TDat,
class TStringPool,
class THashFunc>
922 StrIdV.
Gen(Len(), 0);
923 int KeyId = FFirstKeyId();
924 while (FNextKeyId(KeyId))
925 StrIdV.
Add(GetKeyOfs(KeyId));
928 template <
class TDat,
class TStringPool,
class THashFunc>
931 int KeyId = FFirstKeyId();
932 while (FNextKeyId(KeyId))
933 DatV.
Add(GetHashKeyDat(KeyId).Dat);
936 template <
class TDat,
class TStringPool,
class THashFunc>
938 KeyDatPrV.Gen(Len(), 0);
940 int KeyId = FFirstKeyId();
941 while (FNextKeyId(KeyId)){
942 GetKeyDat(KeyId, Str, Dat);
947 template <
class TDat,
class TStringPool,
class THashFunc>
949 DatKeyPrV.Gen(Len(), 0);
951 int KeyId = FFirstKeyId();
952 while (FNextKeyId(KeyId)){
953 GetKeyDat(KeyId, Str, Dat);
966 template <
class TKey,
class TDat,
class THashFunc = TDefaultHashFunc<TKey> >
980 TCache(
const int64& _MxMemUsed,
const int& Ports,
void* _RefToBs):
989 void Put(
const TKey& Key,
const TDat& Dat);
990 bool Get(
const TKey& Key, TDat& Dat);
991 void Del(
const TKey& Key,
const bool& DoEventCall=
true);
995 bool FNextKeyDat(
void*& KeyDatP, TKey& Key, TDat& Dat);
1001 template <
class TKey,
class TDat,
class THashFunc>
1003 const int64 StartMemUsed = CurMemUsed;
1004 while (!TimeKeyL.Empty()&&(StartMemUsed-CurMemUsed<MemToPurge)){
1005 TKey Key=TimeKeyL.Last()->GetVal();
1010 template <
class TKey,
class TDat,
class THashFunc>
1013 int KeyId=KeyDatH.FFirstKeyId();
1014 while (KeyDatH.FNextKeyId(KeyId)){
1015 const TKey& Key=KeyDatH.GetKey(KeyId);
1017 TDat Dat=KeyLNDatPr.
Val2;
1018 MemUsed+=
int64(Key.GetMemUsed()+Dat->GetMemUsed());
1023 template <
class TKey,
class TDat,
class THashFunc>
1025 CurMemUsed=GetMemUsed();
1026 if (CurMemUsed>MxMemUsed){
1027 Purge(CurMemUsed-MxMemUsed);
1033 template <
class TKey,
class TDat,
class THashFunc>
1035 int KeyId=KeyDatH.GetKeyId(Key);
1037 int64 KeyDatMem=
int64(Key.GetMemUsed()+Dat->GetMemUsed());
1038 if (CurMemUsed+KeyDatMem>MxMemUsed){Purge(KeyDatMem);}
1039 CurMemUsed+=KeyDatMem;
1040 TKeyLN KeyLN=TimeKeyL.AddFront(Key);
1042 KeyDatH.AddDat(Key, KeyLNDatPr);
1046 KeyLNDatPr.
Val2=Dat;
1047 TimeKeyL.PutFront(KeyLN);
1051 template <
class TKey,
class TDat,
class THashFunc>
1053 int KeyId=KeyDatH.GetKeyId(Key);
1057 Dat=KeyDatH[KeyId].Val2;
1062 template <
class TKey,
class TDat,
class THashFunc>
1064 int KeyId=KeyDatH.GetKeyId(Key);
1068 TDat& Dat=KeyLNDatPr.
Val2;
1070 Dat->OnDelFromCache(Key, RefToBs);}
1071 CurMemUsed-=
int64(Key.GetMemUsed()+Dat->GetMemUsed());
1073 TimeKeyL.Del(KeyLN);
1074 KeyDatH.DelKeyId(KeyId);
1078 template <
class TKey,
class TDat,
class THashFunc>
1080 printf(
"To flush: %d\n", KeyDatH.Len());
1081 int KeyId=KeyDatH.FFirstKeyId();
int Done = 0;
1082 while (KeyDatH.FNextKeyId(KeyId)){
1083 if (Done%10000==0){printf(
"%d\r", Done);}
1084 const TKey& Key=KeyDatH.GetKey(KeyId);
1086 TDat Dat=KeyLNDatPr.
Val2;
1087 Dat->OnDelFromCache(Key, RefToBs);
1090 printf(
"Done %d\n", KeyDatH.Len());
1093 template <
class TKey,
class TDat,
class THashFunc>
1101 template <
class TKey,
class TDat,
class THashFunc>
1103 return TimeKeyL.First();
1106 template <
class TKey,
class TDat,
class THashFunc>
1111 Key=
TKeyLN(KeyDatP)->
GetVal(); Dat=KeyDatH.GetDat(Key).Val2;
1112 KeyDatP=
TKeyLN(KeyDatP)->
Next();
return true;
1123 const int MulBy = 16;
1125 while (*p) { HashCd = (MulBy * HashCd) + *p++; HashCd &= 0x0FFFFFFF; }
1128 const int MulBy = 16;
1130 while (*p) { HashCd = (MulBy * HashCd) ^ *p++; HashCd &= 0x0FFFFFFF; }
1149 unsigned int hash = 5381;
1150 for(
unsigned int i = 0; i < Len; Str++, i++) {
1151 hash = ((hash << 5) + hash) + (*Str); }
1156 const char *r = p;
while (*r) { r++; }
1157 return (
int)
DJBHash((
const char *) p, r - p) & 0x7fffffff; }
1159 const char *r = p;
while (*r) { r++; }
1160 return (
int)
DJBHash((
const char *) p, r - p) & 0x7fffffff; }
1166 template <
class TVec>
1171 for (
int ValN=0; ValN<Vec.
Len(); ValN++){
1177 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
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 & 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
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
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
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
THashKeyDatCmp(THash< TKey, TDat, THashFunc > &_Hash, const bool &_CmpKey, const bool &_Asc)
THashKeyDatI(const THKeyDat *_KeyDatI, const THKeyDat *_EndI)
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)
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()
The vector reduces its capacity (frees memory) to match its size.
THashKeyDatI & operator=(const THashKeyDatI &HashKeyDatI)
THash< TStr, TStrV > TStrStrVH
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
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)