KaliVeda
Toolkit for HIC analysis
KVHashList.cpp
1 //Created by KVClassFactory on Mon Nov 30 15:00:00 2009
2 //Author: John Frankland,,,
3 
4 #include "KVHashList.h"
5 #include "THashList.h"
6 
8 
9 
10 
11 
26 KVHashList::KVHashList(Int_t capacity, Int_t rehash)
27  : KVSeqCollection()
28 {
29  // Create a THashList object. Capacity is the initial hashtable capacity
30  // (i.e. number of slots), by default kInitHashTableCapacity = 17, and
31  // rehash is the value at which a rehash will be triggered. I.e. when the
32  // average size of the linked lists at a slot becomes longer than rehash
33  // then the hashtable will be resized and refilled to reduce the collision
34  // rate to about 1. The higher the collision rate, i.e. the longer the
35  // linked lists, the longer lookup will take.
36  // The default value of rehash = 2 (minimum allowed value) - automatic
37  // rehashing is enabled by default. If rehash=0 the table will
38  // NOT automatically be rehashed. Use Rehash() for manual rehashing.
39  // WARNING !!!
40  // If the name of an object in the HashList is modified, The hashlist
41  // must be Rehashed
42 
43  fCollection = new THashList(capacity, rehash);
44  fCollection->SetName(GetName());
45 }
46 
47 
48 
53 
55 {
56  // Return the average collision rate. The higher the number the longer
57  // the linked lists in the hashtable, the slower the lookup. If the number
58  // is high, or lookup noticeably too slow, perfrom a Rehash()
59 
60  return ((THashList*)fCollection)->AverageCollisions();
61 }
62 
63 
64 
81 
82 void KVHashList::Rehash(Int_t newCapacity)
83 {
84  // Rehash the hashlist.
85  //
86  // This needs to be done in two cases:
87  // 1. If the collision rate becomes too high (i.e. the average size of the
88  // linked lists become too long - use AverageCollisions() to check if you
89  // need to rehash.) then lookup efficiency decreases since relatively long
90  // lists have to be searched every time.
91  // To improve performance rehash the hashtable, increasing
92  // the number of slots. This method resizes the table to newCapacity slots
93  // and refills the table.
94  // 2. If the names of any objects in the list CHANGE, you must
95  // rehash the list (as the lookup of objects depends on the TString::Hash()
96  // value calculated from their name when they are added to the list).
97  // In this case it is not necessary to increase the capacity of the list,
98  // just call Rehash() with no arguments.
99 
100  if (!newCapacity) newCapacity = fCollection->GetSize();
101  ((THashList*)fCollection)->Rehash(newCapacity);
102 }
103 
104 
105 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,5,0)
106 
110 
111 const TList* KVHashList::GetListForObject(const char* name) const
112 #else
113 TList* KVHashList::GetListForObject(const char* name) const
114 #endif
115 {
116  // Return the THashTable's list (bucket) in which obj can be found based on
117  // its hash; see THashTable::GetListForObject().
118 
119  return ((THashList*)fCollection)->GetListForObject(name);
120 }
121 
122 
123 
124 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,5,0)
125 
129 
131 #else
132 TList* KVHashList::GetListForObject(const TObject* obj) const
133 #endif
134 {
135  // Return the THashTable's list (bucket) in which obj can be found based on
136  // its hash; see THashTable::GetListForObject().
137 
138  return ((THashList*)fCollection)->GetListForObject(obj);
139 }
140 
141 
int Int_t
float Float_t
char name[80]
Extended version of ROOT THashList.
Definition: KVHashList.h:29
Float_t AverageCollisions() const
Definition: KVHashList.cpp:54
void Rehash(Int_t newCapacity=0)
Definition: KVHashList.cpp:82
const TList * GetListForObject(const char *name) const
Definition: KVHashList.cpp:111
KaliVeda extensions to ROOT collection classes.
TSeqCollection * fCollection
Pointer to embedded ROOT collection.
virtual Int_t GetSize() const
ClassImp(TPyArg)