|
SNAP Library 2.2, User Reference
2014-03-11 19:15:55
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
#include <shash.h>
Public Types | |
| typedef THashSetKeyI< TKey > | TIter |
Public Member Functions | |
| THashSet () | |
| THashSet (const THashSet &Set) | |
| THashSet (const int &ExpectVals, const bool &_AutoSizeP=false) | |
| THashSet (const TVec< TKey > &KeyV) | |
| THashSet (TSIn &SIn) | |
| void | Load (TSIn &SIn) |
| void | Save (TSOut &SOut) const |
| void | LoadXml (const PXmlTok &XmlTok, const TStr &Nm="") |
| void | SaveXml (TSOut &SOut, const TStr &Nm) |
| THashSet & | operator= (const THashSet &Set) |
| bool | operator== (const THashSet &Set) const |
| const TKey & | operator[] (const int &KeyId) const |
| TKey & | operator[] (const int &KeyId) |
| ::TSize | GetMemUsed () const |
| TIter | BegI () const |
| TIter | EndI () const |
| TIter | GetI (const TKey &Key) const |
| void | Gen (const int &ExpectVals) |
| void | Clr (const bool &DoDel=true, const int &NoDelLim=-1) |
| bool | Empty () const |
| int | Len () const |
| int | GetPorts () const |
| bool | IsAutoSize () const |
| int | GetMxKeyIds () const |
| int | GetReservedKeyIds () const |
| bool | IsKeyIdEqKeyN () const |
| int | AddKey (const TKey &Key) |
| void | AddKeyV (const TVec< TKey > &KeyV) |
| void | DelKey (const TKey &Key) |
| bool | DelIfKey (const TKey &Key) |
| void | DelKeyId (const int &KeyId) |
| void | DelKeyIdV (const TIntV &KeyIdV) |
| void | MarkDelKey (const TKey &Key) |
| void | MarkDelKeyId (const int &KeyId) |
| const TKey & | GetKey (const int &KeyId) const |
| int | GetKeyId (const TKey &Key) const |
| int | GetRndKeyId (TRnd &Rnd) const |
| bool | IsKey (const TKey &Key) const |
| bool | IsKey (const TKey &Key, int &KeyId) const |
| bool | IsKeyId (const int &KeyId) const |
| int | FFirstKeyId () const |
| bool | FNextKeyId (int &KeyId) const |
| void | GetKeyV (TVec< TKey > &KeyV) const |
| void | Swap (THashSet &Set) |
| void | Defrag () |
| void | Pack () |
Static Public Member Functions | |
| static THashSet< TKey > | GetSet (const TKey &Key1) |
| static THashSet< TKey > | GetSet (const TKey &Key1, const TKey &Key2) |
| static THashSet< TKey > | GetSet (const TKey &Key1, const TKey &Key2, const TKey &Key3) |
| static THashSet< TKey > | GetSet (const TKey &Key1, const TKey &Key2, const TKey &Key3, const TKey &Key4) |
| static THashSet< TKey > | GetSet (const TKey &Key1, const TKey &Key2, const TKey &Key3, const TKey &Key4, const TKey &Key5) |
| static THashSet< TKey > | GetSet (const TKey &Key1, const TKey &Key2, const TKey &Key3, const TKey &Key4, const TKey &Key5, const TKey &Key6) |
| static THashSet< TKey > | GetSet (const TKey &Key1, const TKey &Key2, const TKey &Key3, const TKey &Key4, const TKey &Key5, const TKey &Key6, const TKey &Key7) |
| static THashSet< TKey > | GetSet (const TKey &Key1, const TKey &Key2, const TKey &Key3, const TKey &Key4, const TKey &Key5, const TKey &Key6, const TKey &Key7, const TKey &Key8) |
| static THashSet< TKey > | GetSet (const TKey &Key1, const TKey &Key2, const TKey &Key3, const TKey &Key4, const TKey &Key5, const TKey &Key6, const TKey &Key7, const TKey &Key8, const TKey &Key9) |
Private Types | |
| typedef THashSetKey< TKey > | TSetKey |
Private Member Functions | |
| TSetKey & | GetSetKey (const int &KeyId) |
| const TSetKey & | GetSetKey (const int &KeyId) const |
| uint | GetNextPrime (const uint &Val) const |
| void | Resize () |
Private Attributes | |
| TIntV | PortV |
| TVec< TSetKey > | KeyV |
| TBool | AutoSizeP |
| TInt | FFreeKeyId |
| TInt | FreeKeys |
| typedef THashSetKeyI<TKey> THashSet< TKey, THashFunc >::TIter |
typedef THashSetKey<TKey> THashSet< TKey, THashFunc >::TSetKey [private] |
Definition at line 1247 of file shash.h.
{
if ((KeyV.Len()>2*PortV.Len())||PortV.Empty()) {Resize(); }
int PortN=abs(THashFunc::GetPrimHashCd(Key)%PortV.Len());
int HashCd=abs(THashFunc::GetSecHashCd(Key));
int PrevKeyId=-1;
int KeyId=PortV[PortN];
while ((KeyId!=-1) &&
!((KeyV[KeyId].HashCd==HashCd) && (KeyV[KeyId].Key==Key))) {
PrevKeyId=KeyId; KeyId=KeyV[KeyId].Next; }
if (KeyId==-1) {
if (FFreeKeyId==-1) {
KeyId=KeyV.Add(TSetKey(-1, HashCd, Key));
} else {
KeyId=FFreeKeyId; FFreeKeyId=KeyV[FFreeKeyId].Next; FreeKeys--;
KeyV[KeyId].Next = -1;
KeyV[KeyId].HashCd = HashCd;
KeyV[KeyId].Key = Key;
}
if (PrevKeyId==-1) {
PortV[PortN]=KeyId;
} else {
KeyV[PrevKeyId].Next=KeyId;
}
}
return KeyId;
}
Definition at line 1359 of file shash.h.
{
if (!IsKeyIdEqKeyN()) {
THashSet<TKey> Set(PortV.Len());
int KeyId=FFirstKeyId();
while (FNextKeyId(KeyId)) {
Set.AddKey(GetKey(KeyId));
}
Pack();
operator=(Set);
IAssert(IsKeyIdEqKeyN());
}
}
Definition at line 1282 of file shash.h.
{
IAssert(!PortV.Empty());
int PortN=abs(THashFunc::GetPrimHashCd(Key)%PortV.Len());
int HashCd=abs(THashFunc::GetSecHashCd(Key));
int PrevKeyId=-1;
int KeyId=PortV[PortN];
while ((KeyId!=-1) &&
!((KeyV[KeyId].HashCd==HashCd) && (KeyV[KeyId].Key==Key))) {
PrevKeyId=KeyId; KeyId=KeyV[KeyId].Next; }
IAssertR(KeyId!=-1, Key.GetStr());
if (PrevKeyId==-1) {PortV[PortN]=KeyV[KeyId].Next; }
else {KeyV[PrevKeyId].Next=KeyV[KeyId].Next; }
KeyV[KeyId].Next=FFreeKeyId; FFreeKeyId=KeyId; FreeKeys++;
KeyV[KeyId].HashCd=TInt(-1);
KeyV[KeyId].Key=TKey();
}
| int THashSet< TKey, THashFunc >::FFirstKeyId | ( | ) | const [inline] |
| bool THashSet< TKey, THashFunc >::FNextKeyId | ( | int & | KeyId | ) | const |
| int THashSet< TKey, THashFunc >::GetKeyId | ( | const TKey & | Key | ) | const |
| void THashSet< TKey, THashFunc >::GetKeyV | ( | TVec< TKey > & | KeyV | ) | const |
Definition at line 1340 of file shash.h.
{
KeyV.Clr();
int KeyId=FFirstKeyId();
while (FNextKeyId(KeyId)) {
KeyV.Add(GetKey(KeyId)); }
}
| ::TSize THashSet< TKey, THashFunc >::GetMemUsed | ( | ) | const [inline] |
Definition at line 1095 of file shash.h.
{
return PortV.GetMemUsed() + KeyV.GetMemUsed() + sizeof(bool) + 2*sizeof(int); }
| int THashSet< TKey, THashFunc >::GetMxKeyIds | ( | ) | const [inline] |
| uint THashSet< TKey, THashFunc >::GetNextPrime | ( | const uint & | Val | ) | const [private] |
Definition at line 1177 of file shash.h.
{
uint* f=(uint*)TIntH::HashPrimeT, *m, *l=(uint*)TIntH::HashPrimeT + (int)TIntH::HashPrimes;
int h, len = (int)TIntH::HashPrimes;
while (len > 0) {
h = len >> 1; m = f + h;
if (*m < Val) { f = m; f++; len = len - h - 1; }
else len = h;
}
return f == l ? *(l - 1) : *f;
}
| int THashSet< TKey, THashFunc >::GetReservedKeyIds | ( | ) | const [inline] |
| int THashSet< TKey, THashFunc >::GetRndKeyId | ( | TRnd & | Rnd | ) | const [inline] |
Definition at line 1137 of file shash.h.
{
IAssert(IsKeyIdEqKeyN());
IAssert(Len()>0);
return Rnd.GetUniDevInt(Len()); }
| static THashSet<TKey> THashSet< TKey, THashFunc >::GetSet | ( | const TKey & | Key1 | ) | [inline, static] |
Definition at line 1155 of file shash.h.
{
THashSet<TKey> Set(1); Set.AddKey(Key1); return Set;}
| static THashSet<TKey> THashSet< TKey, THashFunc >::GetSet | ( | const TKey & | Key1, |
| const TKey & | Key2 | ||
| ) | [inline, static] |
Definition at line 1157 of file shash.h.
{
THashSet<TKey> Set(2); Set.AddKey(Key1); Set.AddKey(Key2); return Set;}
| static THashSet<TKey> THashSet< TKey, THashFunc >::GetSet | ( | const TKey & | Key1, |
| const TKey & | Key2, | ||
| const TKey & | Key3 | ||
| ) | [inline, static] |
Definition at line 1159 of file shash.h.
{
THashSet<TKey> Set(3); Set.AddKey(Key1); Set.AddKey(Key2); Set.AddKey(Key3); return Set;}
| static THashSet<TKey> THashSet< TKey, THashFunc >::GetSet | ( | const TKey & | Key1, |
| const TKey & | Key2, | ||
| const TKey & | Key3, | ||
| const TKey & | Key4 | ||
| ) | [inline, static] |
Definition at line 1161 of file shash.h.
{
THashSet<TKey> Set(4); Set.AddKey(Key1); Set.AddKey(Key2); Set.AddKey(Key3); Set.AddKey(Key4); return Set;}
| static THashSet<TKey> THashSet< TKey, THashFunc >::GetSet | ( | const TKey & | Key1, |
| const TKey & | Key2, | ||
| const TKey & | Key3, | ||
| const TKey & | Key4, | ||
| const TKey & | Key5 | ||
| ) | [inline, static] |
Definition at line 1163 of file shash.h.
{
THashSet<TKey> Set(5); Set.AddKey(Key1); Set.AddKey(Key2); Set.AddKey(Key3); Set.AddKey(Key4); Set.AddKey(Key5); return Set;}
| static THashSet<TKey> THashSet< TKey, THashFunc >::GetSet | ( | const TKey & | Key1, |
| const TKey & | Key2, | ||
| const TKey & | Key3, | ||
| const TKey & | Key4, | ||
| const TKey & | Key5, | ||
| const TKey & | Key6 | ||
| ) | [inline, static] |
Definition at line 1165 of file shash.h.
{
THashSet<TKey> Set(6); Set.AddKey(Key1); Set.AddKey(Key2); Set.AddKey(Key3); Set.AddKey(Key4); Set.AddKey(Key5); Set.AddKey(Key6); return Set;}
| static THashSet<TKey> THashSet< TKey, THashFunc >::GetSet | ( | const TKey & | Key1, |
| const TKey & | Key2, | ||
| const TKey & | Key3, | ||
| const TKey & | Key4, | ||
| const TKey & | Key5, | ||
| const TKey & | Key6, | ||
| const TKey & | Key7 | ||
| ) | [inline, static] |
Definition at line 1167 of file shash.h.
{
THashSet<TKey> Set(7); Set.AddKey(Key1); Set.AddKey(Key2); Set.AddKey(Key3); Set.AddKey(Key4); Set.AddKey(Key5); Set.AddKey(Key6); Set.AddKey(Key7); return Set;}
| static THashSet<TKey> THashSet< TKey, THashFunc >::GetSet | ( | const TKey & | Key1, |
| const TKey & | Key2, | ||
| const TKey & | Key3, | ||
| const TKey & | Key4, | ||
| const TKey & | Key5, | ||
| const TKey & | Key6, | ||
| const TKey & | Key7, | ||
| const TKey & | Key8 | ||
| ) | [inline, static] |
Definition at line 1169 of file shash.h.
{
THashSet<TKey> Set(8); Set.AddKey(Key1); Set.AddKey(Key2); Set.AddKey(Key3); Set.AddKey(Key4); Set.AddKey(Key5); Set.AddKey(Key6); Set.AddKey(Key7); Set.AddKey(Key8); return Set;}
| static THashSet<TKey> THashSet< TKey, THashFunc >::GetSet | ( | const TKey & | Key1, |
| const TKey & | Key2, | ||
| const TKey & | Key3, | ||
| const TKey & | Key4, | ||
| const TKey & | Key5, | ||
| const TKey & | Key6, | ||
| const TKey & | Key7, | ||
| const TKey & | Key8, | ||
| const TKey & | Key9 | ||
| ) | [inline, static] |
Definition at line 1171 of file shash.h.
{
THashSet<TKey> Set(9); Set.AddKey(Key1); Set.AddKey(Key2); Set.AddKey(Key3); Set.AddKey(Key4); Set.AddKey(Key5); Set.AddKey(Key6); Set.AddKey(Key7); Set.AddKey(Key8); Set.AddKey(Key9); return Set;}
| bool THashSet< TKey, THashFunc >::IsAutoSize | ( | ) | const [inline] |
| bool THashSet< TKey, THashFunc >::IsKeyIdEqKeyN | ( | ) | const [inline] |
| void THashSet< TKey, THashFunc >::MarkDelKey | ( | const TKey & | Key | ) |
Definition at line 1302 of file shash.h.
{
IAssert(!PortV.Empty());
int PortN=abs(THashFunc::GetPrimHashCd(Key)%PortV.Len());
int HashCd=abs(THashFunc::GetSecHashCd(Key));
int PrevKeyId=-1;
int KeyId=PortV[PortN];
while ((KeyId!=-1) &&
!((KeyV[KeyId].HashCd==HashCd) && (KeyV[KeyId].Key==Key))) {
PrevKeyId=KeyId; KeyId=KeyV[KeyId].Next; }
IAssertR(KeyId!=-1, Key.GetStr());
if (PrevKeyId==-1) {PortV[PortN]=KeyV[KeyId].Next; }
else {KeyV[PrevKeyId].Next=KeyV[KeyId].Next; }
KeyV[KeyId].Next=FFreeKeyId; FFreeKeyId=KeyId; FreeKeys++;
KeyV[KeyId].HashCd=TInt(-1);
}
| void THashSet< TKey, THashFunc >::MarkDelKeyId | ( | const int & | KeyId | ) | [inline] |
Definition at line 1132 of file shash.h.
{MarkDelKey(GetKey(KeyId)); }
| bool THashSet< TKey, THashFunc >::operator== | ( | const THashSet< TKey, THashFunc > & | Set | ) | const |
Definition at line 1227 of file shash.h.
{
if (Len() != Set.Len()) { return false; }
for (int k = FFirstKeyId(); FNextKeyId(k); k++) {
if (! Set.IsKey(GetKey(k))) { return false; }
}
return true;
}
| const TKey& THashSet< TKey, THashFunc >::operator[] | ( | const int & | KeyId | ) | const [inline] |
| TKey& THashSet< TKey, THashFunc >::operator[] | ( | const int & | KeyId | ) | [inline] |
Definition at line 1189 of file shash.h.
{
// resize & initialize port vector
if (PortV.Len()==0) {PortV.Gen(17); }
else if (AutoSizeP&&(KeyV.Len()>2*PortV.Len())) {
PortV.Gen(GetNextPrime(PortV.Len()+1));
} else {
return;
}
PortV.PutAll(TInt(-1));
// reSet keys
for (int KeyId=0; KeyId<KeyV.Len(); KeyId++) {
TSetKey& SetKey=KeyV[KeyId];
if (SetKey.HashCd!=-1) {
int PortN=abs(THashFunc::GetPrimHashCd(SetKey.Key)%PortV.Len());
SetKey.Next=PortV[PortN];
PortV[PortN]=KeyId;
}
}
}
TInt THashSet< TKey, THashFunc >::FFreeKeyId [private] |