SNAP Library 2.1, User Reference  2013-09-25 10:47:25
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
THashSet< TKey, THashFunc > Class Template Reference

#include <shash.h>

List of all members.

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)
THashSetoperator= (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

TSetKeyGetSetKey (const int &KeyId)
const TSetKeyGetSetKey (const int &KeyId) const
uint GetNextPrime (const uint &Val) const
void Resize ()

Private Attributes

TIntV PortV
TVec< TSetKeyKeyV
TBool AutoSizeP
TInt FFreeKeyId
TInt FreeKeys

Detailed Description

template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
class THashSet< TKey, THashFunc >

Definition at line 1040 of file shash.h.


Member Typedef Documentation

template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
typedef THashSetKeyI<TKey> THashSet< TKey, THashFunc >::TIter

Definition at line 1042 of file shash.h.

template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
typedef THashSetKey<TKey> THashSet< TKey, THashFunc >::TSetKey [private]

Definition at line 1044 of file shash.h.


Constructor & Destructor Documentation

template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
THashSet< TKey, THashFunc >::THashSet ( ) [inline]

Definition at line 1059 of file shash.h.

            :
    PortV(), KeyV(),
    AutoSizeP(true), FFreeKeyId(-1), FreeKeys(0) { }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
THashSet< TKey, THashFunc >::THashSet ( const THashSet< TKey, THashFunc > &  Set) [inline]

Definition at line 1062 of file shash.h.

template<class TKey , class THashFunc >
THashSet< TKey, THashFunc >::THashSet ( const int &  ExpectVals,
const bool &  _AutoSizeP = false 
)

Definition at line 1210 of file shash.h.

                                                                                :
  PortV(GetNextPrime(ExpectVals/2+1)), KeyV(ExpectVals, 0),
  AutoSizeP(_AutoSizeP), FFreeKeyId(-1), FreeKeys(0) {
  PortV.PutAll(TInt(-1));
}
template<class TKey, class THashFunc >
THashSet< TKey, THashFunc >::THashSet ( const TVec< TKey > &  KeyV) [explicit]

Definition at line 1217 of file shash.h.

                                                           :
 PortV(GetNextPrime(_KeyV.Len()/2+1)), KeyV(_KeyV.Len(), 0),
 AutoSizeP(false), FFreeKeyId(-1), FreeKeys(0) {
  PortV.PutAll(TInt(-1));
  for (int i = 0; i < _KeyV.Len(); i++) {
    AddKey(_KeyV[i]);
  }
}
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
THashSet< TKey, THashFunc >::THashSet ( TSIn SIn) [inline, explicit]

Definition at line 1067 of file shash.h.

                              :
    PortV(SIn), KeyV(SIn),
    AutoSizeP(SIn), FFreeKeyId(SIn), FreeKeys(SIn) {
    SIn.LoadCs(); }

Member Function Documentation

template<class TKey, class THashFunc >
int THashSet< TKey, THashFunc >::AddKey ( const TKey &  Key)

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;
}
template<class TKey, class THashFunc >
void THashSet< TKey, THashFunc >::AddKeyV ( const TVec< TKey > &  KeyV)

Definition at line 1277 of file shash.h.

                                                              {
  for (int i = 0; i < KeyV.Len(); i++) { AddKey(KeyV[i]); }
}
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
TIter THashSet< TKey, THashFunc >::BegI ( ) const [inline]

Definition at line 1098 of file shash.h.

                     {
    if (Len()>0) {
      if (IsKeyIdEqKeyN()) { return TIter(KeyV.BegI(), KeyV.EndI()); }
      int FKeyId=-1;  FNextKeyId(FKeyId);
      return TIter(KeyV.BegI()+FKeyId, KeyV.EndI()); }
    return TIter(KeyV.EndI(), KeyV.EndI());
  }
template<class TKey , class THashFunc >
void THashSet< TKey, THashFunc >::Clr ( const bool &  DoDel = true,
const int &  NoDelLim = -1 
)

Definition at line 1236 of file shash.h.

                                                                          {
  if (DoDel) {
    PortV.Clr(); KeyV.Clr();
  } else {
    PortV.PutAll(TInt(-1));
    KeyV.Clr(DoDel, NoDelLim);
  }
  FFreeKeyId=TInt(-1); FreeKeys=TInt(0);
}
template<class TKey , class THashFunc >
void THashSet< TKey, THashFunc >::Defrag ( )

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());
  }
}
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
bool THashSet< TKey, THashFunc >::DelIfKey ( const TKey &  Key) [inline]

Definition at line 1125 of file shash.h.

                                 {
    int KeyId; if (IsKey(Key, KeyId)) {DelKeyId(KeyId); return true;} return false;}
template<class TKey, class THashFunc >
void THashSet< TKey, THashFunc >::DelKey ( const TKey &  Key)

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();
}
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
void THashSet< TKey, THashFunc >::DelKeyId ( const int &  KeyId) [inline]

Definition at line 1127 of file shash.h.

{DelKey(GetKey(KeyId)); }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
void THashSet< TKey, THashFunc >::DelKeyIdV ( const TIntV KeyIdV) [inline]

Definition at line 1128 of file shash.h.

                                      {
    for (int KeyIdN=0; KeyIdN<KeyIdV.Len(); KeyIdN++) {DelKeyId(KeyIdV[KeyIdN]); }}
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
bool THashSet< TKey, THashFunc >::Empty ( ) const [inline]

Definition at line 1113 of file shash.h.

{return Len()==0; }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
TIter THashSet< TKey, THashFunc >::EndI ( ) const [inline]

Definition at line 1105 of file shash.h.

{return TIter(KeyV.EndI(), KeyV.EndI()); }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
int THashSet< TKey, THashFunc >::FFirstKeyId ( ) const [inline]

Definition at line 1147 of file shash.h.

{return 0-1; }
template<class TKey , class THashFunc >
bool THashSet< TKey, THashFunc >::FNextKeyId ( int &  KeyId) const

Definition at line 1334 of file shash.h.

                                                           {
  do {KeyId++; } while ((KeyId<KeyV.Len())&&(KeyV[KeyId].HashCd==-1));
  return KeyId<KeyV.Len();
}
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
void THashSet< TKey, THashFunc >::Gen ( const int &  ExpectVals) [inline]

Definition at line 1108 of file shash.h.

                                  {
    PortV.Gen(GetNextPrime(ExpectVals/2)); KeyV.Gen(ExpectVals, 0);
    FFreeKeyId=-1; FreeKeys=0; PortV.PutAll(TInt(-1)); }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
TIter THashSet< TKey, THashFunc >::GetI ( const TKey &  Key) const [inline]

Definition at line 1106 of file shash.h.

{return TIter(&KeyV[GetKeyId(Key)], KeyV.EndI()); }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
const TKey& THashSet< TKey, THashFunc >::GetKey ( const int &  KeyId) const [inline]

Definition at line 1134 of file shash.h.

                                             {
    return GetSetKey(KeyId).Key; }
template<class TKey, class THashFunc >
int THashSet< TKey, THashFunc >::GetKeyId ( const TKey &  Key) const

Definition at line 1321 of file shash.h.

                                                             {
  if (PortV.Empty()) {return -1; }
  int PortN=abs(THashFunc::GetPrimHashCd(Key)%PortV.Len());
  int HashCd=abs(THashFunc::GetSecHashCd(Key));
  int KeyId=PortV[PortN];

  while ((KeyId!=-1) &&
   !((KeyV[KeyId].HashCd==HashCd) && (KeyV[KeyId].Key==Key))) {
    KeyId=KeyV[KeyId].Next; }
  return KeyId;
}
template<class TKey, class THashFunc >
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)); }
}
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
::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); }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
int THashSet< TKey, THashFunc >::GetMxKeyIds ( ) const [inline]

Definition at line 1117 of file shash.h.

{return KeyV.Len(); }
template<class TKey , class THashFunc >
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;
}
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
int THashSet< TKey, THashFunc >::GetPorts ( ) const [inline]

Definition at line 1115 of file shash.h.

{return PortV.Len(); }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
int THashSet< TKey, THashFunc >::GetReservedKeyIds ( ) const [inline]

Definition at line 1118 of file shash.h.

{ return KeyV.Reserved(); }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
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()); }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
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;}
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
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;}
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
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;}
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
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;}
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
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;}
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
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;}
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
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;}
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
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;}
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
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;}
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
TSetKey& THashSet< TKey, THashFunc >::GetSetKey ( const int &  KeyId) [inline, private]

Definition at line 1050 of file shash.h.

                                       {
    TSetKey& SetKey=KeyV[KeyId];
    Assert(SetKey.HashCd!=-1); return SetKey; }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
const TSetKey& THashSet< TKey, THashFunc >::GetSetKey ( const int &  KeyId) const [inline, private]

Definition at line 1053 of file shash.h.

                                                   {
    const TSetKey& SetKey=KeyV[KeyId];
    Assert(SetKey.HashCd!=-1); return SetKey; }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
bool THashSet< TKey, THashFunc >::IsAutoSize ( ) const [inline]

Definition at line 1116 of file shash.h.

{return AutoSizeP; }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
bool THashSet< TKey, THashFunc >::IsKey ( const TKey &  Key) const [inline]

Definition at line 1141 of file shash.h.

{return GetKeyId(Key)!=-1; }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
bool THashSet< TKey, THashFunc >::IsKey ( const TKey &  Key,
int &  KeyId 
) const [inline]

Definition at line 1142 of file shash.h.

                                                {
    KeyId=GetKeyId(Key); return KeyId!=-1; }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
bool THashSet< TKey, THashFunc >::IsKeyId ( const int &  KeyId) const [inline]

Definition at line 1144 of file shash.h.

                                       {
    return (0<=KeyId)&&(KeyId<KeyV.Len())&&(KeyV[KeyId].HashCd!=-1); }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
bool THashSet< TKey, THashFunc >::IsKeyIdEqKeyN ( ) const [inline]

Definition at line 1119 of file shash.h.

{return FreeKeys==0; }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
int THashSet< TKey, THashFunc >::Len ( ) const [inline]

Definition at line 1114 of file shash.h.

{return KeyV.Len()-FreeKeys; }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
void THashSet< TKey, THashFunc >::Load ( TSIn SIn) [inline]

Definition at line 1071 of file shash.h.

                       {
    PortV.Load(SIn); KeyV.Load(SIn);
    AutoSizeP=TBool(SIn); FFreeKeyId=TInt(SIn); FreeKeys=TInt(SIn);
    SIn.LoadCs(); }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
void THashSet< TKey, THashFunc >::LoadXml ( const PXmlTok XmlTok,
const TStr Nm = "" 
) [inline]

Definition at line 1079 of file shash.h.

                                                         {
    XLoadHd(Nm); TVec<TSetKey> KeyV; XLoad(KeyV); XLoad(AutoSizeP);
    for (int KeyN=0; KeyN<KeyV.Len(); KeyN++) {
      AddKey(KeyV[KeyN].Key); }}
template<class TKey, class THashFunc >
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);
}
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
void THashSet< TKey, THashFunc >::MarkDelKeyId ( const int &  KeyId) [inline]

Definition at line 1132 of file shash.h.

{MarkDelKey(GetKey(KeyId)); }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
THashSet& THashSet< TKey, THashFunc >::operator= ( const THashSet< TKey, THashFunc > &  Set) [inline]

Definition at line 1086 of file shash.h.

                                           {
    if (this!=&Set) {
      PortV=Set.PortV; KeyV=Set.KeyV; AutoSizeP=Set.AutoSizeP;
      FFreeKeyId=Set.FFreeKeyId; FreeKeys=Set.FreeKeys; }
    return *this; }
template<class TKey , class THashFunc >
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;
}
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
const TKey& THashSet< TKey, THashFunc >::operator[] ( const int &  KeyId) const [inline]

Definition at line 1092 of file shash.h.

{return GetSetKey(KeyId).Key; }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
TKey& THashSet< TKey, THashFunc >::operator[] ( const int &  KeyId) [inline]

Definition at line 1093 of file shash.h.

{return GetSetKey(KeyId).Key; }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
void THashSet< TKey, THashFunc >::Pack ( ) [inline]

Definition at line 1153 of file shash.h.

{KeyV.Pack(); }
template<class TKey , class THashFunc >
void THashSet< TKey, THashFunc >::Resize ( ) [private]

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;
    }
  }
}
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
void THashSet< TKey, THashFunc >::Save ( TSOut SOut) const [inline]

Definition at line 1075 of file shash.h.

                               {
    PortV.Save(SOut); KeyV.Save(SOut);
    AutoSizeP.Save(SOut); FFreeKeyId.Save(SOut); FreeKeys.Save(SOut);
    SOut.SaveCs(); }
template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
void THashSet< TKey, THashFunc >::SaveXml ( TSOut SOut,
const TStr Nm 
) [inline]

Definition at line 1083 of file shash.h.

template<class TKey , class THashFunc >
void THashSet< TKey, THashFunc >::Swap ( THashSet< TKey, THashFunc > &  Set)

Definition at line 1348 of file shash.h.

                                                  {
  if (this!=&Set) {
    PortV.Swap(Set.PortV);
    KeyV.Swap(Set.KeyV);
    ::Swap(AutoSizeP, Set.AutoSizeP);
    ::Swap(FFreeKeyId, Set.FFreeKeyId);
    ::Swap(FreeKeys, Set.FreeKeys);
  }
}

Member Data Documentation

template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
TBool THashSet< TKey, THashFunc >::AutoSizeP [private]

Definition at line 1047 of file shash.h.

template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
TInt THashSet< TKey, THashFunc >::FFreeKeyId [private]

Definition at line 1048 of file shash.h.

template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
TInt THashSet< TKey, THashFunc >::FreeKeys [private]

Definition at line 1048 of file shash.h.

template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
TVec<TSetKey> THashSet< TKey, THashFunc >::KeyV [private]

Definition at line 1046 of file shash.h.

template<class TKey, class THashFunc = TDefaultHashFunc<TKey>>
TIntV THashSet< TKey, THashFunc >::PortV [private]

Definition at line 1045 of file shash.h.


The documentation for this class was generated from the following file: