Loading...
Searching...
No Matches
XrdOucHash< T > Class Template Reference

`#include <XrdOucHash.hh>`

Collaboration diagram for XrdOucHash< T >:

## Public Member Functions

| XrdOucHash (int psize=89, int size=144, int load=80)
| ~XrdOucHash ()
T * | Add (const char *KeyVal, T *KeyData, const int LifeTime=0, XrdOucHash_Options opt=Hash_default)
T * | Apply (int(*func)(const char *, T *, void *), void *Arg)
int | Del (const char *KeyVal, XrdOucHash_Options opt=Hash_default)
T * | Find (const char *KeyVal, time_t *KeyTime=0)
int | Num ()
void | Purge ()
T * | Rep (const char *KeyVal, T *KeyData, const int LifeTime=0, XrdOucHash_Options opt=Hash_default)

## Detailed Description

template<class T>
class XrdOucHash< T >

Definition at line 127 of file XrdOucHash.hh.

## Constructor & Destructor Documentation

## XrdOucHash()

template<class T>

XrdOucHash< T >::XrdOucHash | ( | int | psize = 89,
|  | int | size = 144,
|  | int | load = 80 )

Definition at line 44 of file XrdOucHash.icc.

{
prevtablesize = psize;
hashtablesize = csize;
hashload = load;
hashmax = (csize * load) / 100;
hashnum = 0;
hashtable = (XrdOucHash_Item<T> **)
malloc( (size_t)(csize*sizeof(XrdOucHash_Item<T> *)) );
memset((void *)hashtable, 0, (size_t)(csize*sizeof(XrdOucHash_Item<T> *)));
}
XrdOucHash
Definition XrdOucHash.hh:128

## ~XrdOucHash()

template<class T>

XrdOucHash< T >::~XrdOucHash | ( |  | ) |

inline

Definition at line 186 of file XrdOucHash.hh.

{if (hashtable) {Purge(); free(hashtable); hashtable = 0;}}
XrdOucHash::Purge
void Purge()
Definition XrdOucHash.icc:193

References Purge().

Here is the call graph for this function:

## Member Function Documentation

## Add()

template<class T>

T * XrdOucHash< T >::Add | ( | const char * | KeyVal,
|  | T * | KeyData,
|  | const int | LifeTime = 0,
|  | XrdOucHash_Options | opt = Hash_default )

Definition at line 61 of file XrdOucHash.icc.

{
unsigned long khash = XrdOucHashVal(KeyVal);
int hent;
time_t lifetime, KeyTime=0;
XrdOucHash_Item<T> *hip, *newhip, *prevhip;
// Compute the hash index and look up the entry. If found, either
// return an error or delete it because caller wanted it replaced or
// it has expired.
//
hent = khash % hashtablesize;
if ((hip = hashtable[hent]) && (hip = Search(hip, khash, KeyVal, &prevhip)))
{if (opt & Hash_count)
{hip->Update(hip->Count()+1,
(LifeTime || hip->Time() ? LifeTime + time(0) : 0) );}
if (!(opt & Hash_replace)
&& ((lifetime=hip->Time())==0||lifetime>=time(0))) return hip->Data();
Remove(hent, hip, prevhip);
} else {
// Check if we should expand the table
//
if (hashnum >= hashmax) {Expand(); hent = khash % hashtablesize;}
}
// Add the entry
//
if (LifeTime) KeyTime = LifeTime + time(0);
if ( !(newhip = new XrdOucHash_Item<T>(khash, KeyVal, KeyData, KeyTime,
hashtable[hent], opt)) ) throw ENOMEM;
hashtable[hent] = newhip;
hashnum++;
return (T *)0;
}
XrdOucHashVal
unsigned long XrdOucHashVal(const char *KeyVal)
Definition XrdOucHashVal.cc:35

References XrdOucHash_Item< T >::Count(), XrdOucHash_Item< T >::Data(), Hash_count, Hash_replace, XrdOucHash_Item< T >::Time(), XrdOucHash_Item< T >::Update(), and XrdOucHashVal().

Referenced by XrdAccGroups::AddName(), XrdCryptoFactory::GetCryptoFactory(), Rep(), and XrdOssSys::Stage_QT().

Here is the call graph for this function:
Here is the caller graph for this function:

## Apply()

template<class T>

T * XrdOucHash< T >::Apply | ( | int(* | func )(const char *, T *, void *),
|  | void * | Arg )

Definition at line 102 of file XrdOucHash.icc.

{
int i, rc;
time_t lifetime;
XrdOucHash_Item<T> *hip, *prevhip, *nexthip;
//Run through all the entries, applying the function to each. Expire
// dead entries by pretending that the function asked for a deletion.
//
for (i = 0; i < hashtablesize; i++)
{hip = hashtable[i]; prevhip = 0;
while(hip)
{nexthip = hip->Next();
if ((lifetime = hip->Time()) && lifetime < time(0)) rc = -1;
else if ( (rc = (*func)(hip->Key(), hip->Data(), Arg)) > 0 )
return hip->Data();
if (rc < 0)
{delete hip;
if (prevhip) prevhip->SetNext(nexthip);
else hashtable[i] = nexthip;
hashnum--;
}
else prevhip = hip;
hip = nexthip;
}
}
return (T *)0;
}

References XrdOucHash_Item< T >::Data(), XrdOucHash_Item< T >::Key(), XrdOucHash_Item< T >::Next(), XrdOucHash_Item< T >::SetNext(), and XrdOucHash_Item< T >::Time().

Referenced by XrdOssSys::Stage_QT().

Here is the call graph for this function:
Here is the caller graph for this function:

## Del()

template<class T>

int XrdOucHash< T >::Del | ( | const char * | KeyVal,
|  | XrdOucHash_Options | opt = Hash_default )

Definition at line 136 of file XrdOucHash.icc.

{
unsigned long khash = XrdOucHashVal(KeyVal);
int hent, cnt;
XrdOucHash_Item<T> *hip, *phip, *thip;
// Compute the hash index and look up the entry. If found, return it.
//
hent = khash % hashtablesize;
if (!(thip = hashtable[hent])) return -ENOENT;
if (!( hip = Search(thip, khash, KeyVal, &phip) ) ) return -ENOENT;
// Delete the item and return
//
if ((cnt = hip->Count()) <= 0) Remove(hent, hip, phip);
else hip->Update(cnt-1, 0);
return 0;
}

References XrdOucHashVal().

Here is the call graph for this function:

## Find()

template<class T>

T * XrdOucHash< T >::Find | ( | const char * | KeyVal,
|  | time_t * | KeyTime = 0 )

Definition at line 160 of file XrdOucHash.icc.

{
unsigned long khash = XrdOucHashVal(KeyVal);
int kent;
time_t lifetime = 0;
XrdOucHash_Item<T> *phip, *hip;
// Compute position of the hash table entry
//
kent = khash%hashtablesize;
// Find the entry (remove it if expired and return nothing)
//
if ((hip = hashtable[kent]))
if ((hip = Search(hip, khash, KeyVal, &phip)))
if ( (lifetime = hip->Time()) && lifetime < time(0) )
{Remove(kent, hip, phip);
if (KeyTime) *KeyTime = (time_t)0;
return (T *)0;
}
// Return actual information
//
if (KeyTime) *KeyTime = lifetime;
if (hip) return hip->Data();
return (T *)0;
}

Referenced by XrdAccGroups::AddName(), XrdAccGroups::FindName(), and XrdCryptoFactory::GetCryptoFactory().

Here is the caller graph for this function:

## Num()

template<class T>

int XrdOucHash< T >::Num | ( |  | ) |

inline

Definition at line 158 of file XrdOucHash.hh.

{return hashnum;}

Referenced by XrdAccConfig::ConfigDB().

Here is the caller graph for this function:

## Purge()

template<class T>

void XrdOucHash< T >::Purge | ( |  | ) |

Definition at line 193 of file XrdOucHash.icc.

{
int i;
XrdOucHash_Item<T> *hip, *nexthip;
//Run through all the entries, deleting each one
//
for (i = 0; i < hashtablesize; i++)
{hip = hashtable[i]; hashtable[i] = 0;
while(hip)
{nexthip = hip->Next();
delete hip;
hip = nexthip;
}
}
hashnum = 0;
}

References XrdOucHash_Item< T >::Next().

Referenced by ~XrdOucHash().

Here is the call graph for this function:
Here is the caller graph for this function:

## Rep()

template<class T>

T * XrdOucHash< T >::Rep | ( | const char * | KeyVal,
|  | T * | KeyData,
|  | const int | LifeTime = 0,
|  | XrdOucHash_Options | opt = Hash_default )

inline

Definition at line 166 of file XrdOucHash.hh.

{return Add(KeyVal, KeyData, LifeTime,
(XrdOucHash_Options)(opt | Hash_replace));}
XrdOucHash::Add
T * Add(const char *KeyVal, T *KeyData, const int LifeTime=0, XrdOucHash_Options opt=Hash_default)
Definition XrdOucHash.icc:61

References Add(), Hash_default, and Hash_replace.

Here is the call graph for this function:

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

- XrdOucHash.hh
- XrdOucHash.icc