XRootD
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.

45 {
46  prevtablesize = psize;
47  hashtablesize = csize;
48  hashload = load;
49  hashmax = (csize * load) / 100;
50  hashnum = 0;
51  hashtable = (XrdOucHash_Item<T> **)
52  malloc( (size_t)(csize*sizeof(XrdOucHash_Item<T> *)) );
53  memset((void *)hashtable, 0, (size_t)(csize*sizeof(XrdOucHash_Item<T> *)));
54 }

◆ ~XrdOucHash()

template<class T >
XrdOucHash< T >::~XrdOucHash ( )
inline

Definition at line 186 of file XrdOucHash.hh.

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

References XrdOucHash< T >::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.

63 {
64  unsigned long khash = XrdOucHashVal(KeyVal);
65  int hent;
66  time_t lifetime, KeyTime=0;
67  XrdOucHash_Item<T> *hip, *newhip, *prevhip;
68 
69  // Compute the hash index and look up the entry. If found, either
70  // return an error or delete it because caller wanted it replaced or
71  // it has expired.
72  //
73  hent = khash % hashtablesize;
74  if ((hip = hashtable[hent]) && (hip = Search(hip, khash, KeyVal, &prevhip)))
75  {if (opt & Hash_count)
76  {hip->Update(hip->Count()+1,
77  (LifeTime || hip->Time() ? LifeTime + time(0) : 0) );}
78  if (!(opt & Hash_replace)
79  && ((lifetime=hip->Time())==0||lifetime>=time(0))) return hip->Data();
80  Remove(hent, hip, prevhip);
81  } else {
82  // Check if we should expand the table
83  //
84  if (hashnum >= hashmax) {Expand(); hent = khash % hashtablesize;}
85  }
86 
87  // Add the entry
88  //
89  if (LifeTime) KeyTime = LifeTime + time(0);
90  if ( !(newhip = new XrdOucHash_Item<T>(khash, KeyVal, KeyData, KeyTime,
91  hashtable[hent], opt)) ) throw ENOMEM;
92  hashtable[hent] = newhip;
93  hashnum++;
94  return (T *)0;
95 }
@ Hash_count
Definition: XrdOucHash.hh:54
@ Hash_replace
Definition: XrdOucHash.hh:53
unsigned long XrdOucHashVal(const char *KeyVal)
void Update(int newcount, time_t newtime)
Definition: XrdOucHash.hh:76
time_t Time()
Definition: XrdOucHash.hh:74

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 XrdCmsPrepare::Add(), XrdAccGroups::AddName(), XrdSutCache::Get(), XrdCryptoFactory::GetCryptoFactory(), XrdAccGroups::Groups(), XrdOssMio::Map(), XrdAccGroups::NetGroups(), XrdSutPFCache::Rehash(), XrdOucHash< T >::Rep(), XrdFrmFileset::Screen(), XrdOssSys::Stage_QT(), and XrdVomsFun::VOMSInit().

+ 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(*)(const char *, T *, void *)  func,
void *  Arg 
)

Definition at line 102 of file XrdOucHash.icc.

103 {
104  int i, rc;
105  time_t lifetime;
106  XrdOucHash_Item<T> *hip, *prevhip, *nexthip;
107 
108  //Run through all the entries, applying the function to each. Expire
109  // dead entries by pretending that the function asked for a deletion.
110  //
111  for (i = 0; i < hashtablesize; i++)
112  {hip = hashtable[i]; prevhip = 0;
113  while(hip)
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 )
117  return hip->Data();
118  if (rc < 0)
119  {delete hip;
120  if (prevhip) prevhip->SetNext(nexthip);
121  else hashtable[i] = nexthip;
122  hashnum--;
123  }
124  else prevhip = hip;
125  hip = nexthip;
126  }
127  }
128  return (T *)0;
129 }
XrdOucHash_Item< T > * Next()
Definition: XrdOucHash.hh:72
const char * Key()
Definition: XrdOucHash.hh:70
void SetNext(XrdOucHash_Item< T > *item)
Definition: XrdOucHash.hh:84

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

Referenced by XrdOucGMap::dn2user(), XrdAccGroups::NetGroups(), and 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.

137 {
138  unsigned long khash = XrdOucHashVal(KeyVal);
139  int hent, cnt;
140  XrdOucHash_Item<T> *hip, *phip, *thip;
141 
142  // Compute the hash index and look up the entry. If found, return it.
143  //
144  hent = khash % hashtablesize;
145  if (!(thip = hashtable[hent])) return -ENOENT;
146  if (!( hip = Search(thip, khash, KeyVal, &phip) ) ) return -ENOENT;
147 
148  // Delete the item and return
149  //
150  if ((cnt = hip->Count()) <= 0) Remove(hent, hip, phip);
151  else hip->Update(cnt-1, 0);
152  return 0;
153 }

References XrdOucHashVal().

Referenced by XrdCmsPrepare::Gone().

+ Here is the call graph for this function:
+ Here is the caller 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.

161 {
162  unsigned long khash = XrdOucHashVal(KeyVal);
163  int kent;
164  time_t lifetime = 0;
165  XrdOucHash_Item<T> *phip, *hip;
166 
167 // Compute position of the hash table entry
168 //
169  kent = khash%hashtablesize;
170 
171 // Find the entry (remove it if expired and return nothing)
172 //
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;
178  return (T *)0;
179  }
180 
181 // Return actual information
182 //
183  if (KeyTime) *KeyTime = lifetime;
184  if (hip) return hip->Data();
185  return (T *)0;
186 }

Referenced by XrdAccAccess::Access(), XrdAccGroups::AddName(), XrdNetSecurity::Authorize(), XrdOucGMap::dn2user(), XrdCmsPrepare::Exists(), XrdAccGroups::FindName(), XrdSutCache::Get(), XrdOucEnv::Get(), XrdCryptoFactory::GetCryptoFactory(), XrdOucEnv::GetInt(), XrdOucEnv::GetPtr(), XrdAccGroups::Groups(), XrdOssMio::Map(), XrdAccGroups::NetGroups(), XrdSutPFile::ReadEntry(), XrdSutPFCache::Remove(), XrdSutPFile::RemoveEntry(), XrdSutPFile::UpdateCount(), and XrdVomsFun::VOMSFun().

+ 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.

158 {return hashnum;}

Referenced by XrdAccConfig::ConfigDB(), XrdSutCache::Num(), XrdVomsFun::VOMSFun(), and XrdVomsFun::VOMSInit().

+ Here is the caller graph for this function:

◆ Purge()

template<class T >
void XrdOucHash< T >::Purge

Definition at line 193 of file XrdOucHash.icc.

194 {
195  int i;
196  XrdOucHash_Item<T> *hip, *nexthip;
197 
198  //Run through all the entries, deleting each one
199  //
200  for (i = 0; i < hashtablesize; i++)
201  {hip = hashtable[i]; hashtable[i] = 0;
202  while(hip)
203  {nexthip = hip->Next();
204  delete hip;
205  hip = nexthip;
206  }
207  }
208  hashnum = 0;
209 }

References XrdOucHash_Item< T >::Next().

Referenced by XrdOucHash< T >::~XrdOucHash(), XrdFrmFiles::Get(), XrdFrmFileset::Purge(), XrdAccGroups::PurgeCache(), XrdSutPFCache::Rehash(), and XrdSutCache::Reset().

+ 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.

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

References XrdOucHash< T >::Add(), and Hash_replace.

Referenced by XrdOucEnv::XrdOucEnv(), XrdOucEnv::Put(), XrdOucEnv::PutInt(), and XrdOucEnv::PutPtr().

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

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