46 prevtablesize = psize;
47 hashtablesize = csize;
49 hashmax = (csize * load) / 100;
66 time_t lifetime, KeyTime=0;
73 hent = khash % hashtablesize;
74 if ((hip = hashtable[hent]) && (hip = Search(hip, khash, KeyVal, &prevhip)))
77 (LifeTime || hip->
Time() ? LifeTime + time(0) : 0) );}
79 && ((lifetime=hip->
Time())==0||lifetime>=time(0)))
return hip->
Data();
80 Remove(hent, hip, prevhip);
84 if (hashnum >= hashmax) {Expand(); hent = khash % hashtablesize;}
89 if (LifeTime) KeyTime = LifeTime + time(0);
91 hashtable[hent], opt)) )
throw ENOMEM;
92 hashtable[hent] = newhip;
111 for (i = 0; i < hashtablesize; i++)
112 {hip = hashtable[i]; prevhip = 0;
114 {nexthip = hip->
Next();
115 if ((lifetime = hip->
Time()) && lifetime < time(0)) rc = -1;
116 else if ( (rc = (*func)(hip->
Key(), hip->
Data(), Arg)) > 0 )
120 if (prevhip) prevhip->
SetNext(nexthip);
121 else hashtable[i] = nexthip;
144 hent = khash % hashtablesize;
145 if (!(thip = hashtable[hent]))
return -ENOENT;
146 if (!( hip = Search(thip, khash, KeyVal, &phip) ) )
return -ENOENT;
150 if ((cnt = hip->
Count()) <= 0) Remove(hent, hip, phip);
151 else hip->
Update(cnt-1, 0);
169 kent = khash%hashtablesize;
173 if ((hip = hashtable[kent]))
174 if ((hip = Search(hip, khash, KeyVal, &phip)))
175 if ( (lifetime = hip->
Time()) && lifetime < time(0) )
176 {Remove(kent, hip, phip);
177 if (KeyTime) *KeyTime = (time_t)0;
183 if (KeyTime) *KeyTime = lifetime;
184 if (hip)
return hip->
Data();
200 for (i = 0; i < hashtablesize; i++)
201 {hip = hashtable[i]; hashtable[i] = 0;
203 {nexthip = hip->
Next();
222 int newsize, newent, i;
228 newsize = prevtablesize +hashtablesize;
234 memset((
void *)newtab, 0, memlen);
238 for (i = 0; i < hashtablesize; i++)
241 {nexthip = hip->
Next();
242 newent = (hip->
Hash()) % newsize;
244 newtab[newent] = hip;
251 free((
void *)hashtable);
253 prevtablesize = hashtablesize;
254 hashtablesize = newsize;
258 hashmax =
static_cast<int>((
static_cast<long long>(newsize)*hashload)/100);
270 else hashtable[kent] = hip->
Next();
281 const unsigned long khash,
289 while(hip && !hip->
Same(khash, kval))
293 if (pitem) *pitem = prevp;
unsigned long XrdOucHashVal(const char *KeyVal)
int Same(const unsigned long KeyHash, const char *KeyVal)
void Update(int newcount, time_t newtime)
XrdOucHash_Item< T > * Next()
void SetNext(XrdOucHash_Item< T > *item)
int Del(const char *KeyVal, XrdOucHash_Options opt=Hash_default)
T * Apply(int(*func)(const char *, T *, void *), void *Arg)
T * Add(const char *KeyVal, T *KeyData, const int LifeTime=0, XrdOucHash_Options opt=Hash_default)
T * Find(const char *KeyVal, time_t *KeyTime=0)
XrdOucHash(int psize=89, int size=144, int load=80)