KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVHashList.cpp
Go to the documentation of this file.
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 
51 
53 {
54  // Destructor
55 }
56 
57 
58 
63 
65 {
66  // Return the average collision rate. The higher the number the longer
67  // the linked lists in the hashtable, the slower the lookup. If the number
68  // is high, or lookup noticeably too slow, perfrom a Rehash()
69 
70  return ((THashList*)fCollection)->AverageCollisions();
71 }
72 
73 
74 
91 
92 void KVHashList::Rehash(Int_t newCapacity)
93 {
94  // Rehash the hashlist.
95  //
96  // This needs to be done in two cases:
97  // 1. If the collision rate becomes too high (i.e. the average size of the
98  // linked lists become too long - use AverageCollisions() to check if you
99  // need to rehash.) then lookup efficiency decreases since relatively long
100  // lists have to be searched every time.
101  // To improve performance rehash the hashtable, increasing
102  // the number of slots. This method resizes the table to newCapacity slots
103  // and refills the table.
104  // 2. If the names of any objects in the list CHANGE, you must
105  // rehash the list (as the lookup of objects depends on the TString::Hash()
106  // value calculated from their name when they are added to the list).
107  // In this case it is not necessary to increase the capacity of the list,
108  // just call Rehash() with no arguments.
109 
110  if (!newCapacity) newCapacity = fCollection->GetSize();
111  ((THashList*)fCollection)->Rehash(newCapacity);
112 }
113 
114 
115 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,5,0)
116 
120 
121 const TList* KVHashList::GetListForObject(const char* name) const
122 #else
123 TList* KVHashList::GetListForObject(const char* name) const
124 #endif
125 {
126  // Return the THashTable's list (bucket) in which obj can be found based on
127  // its hash; see THashTable::GetListForObject().
128 
129  return ((THashList*)fCollection)->GetListForObject(name);
130 }
131 
132 
133 
134 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,5,0)
135 
139 
141 #else
142 TList* KVHashList::GetListForObject(const TObject* obj) const
143 #endif
144 {
145  // Return the THashTable's list (bucket) in which obj can be found based on
146  // its hash; see THashTable::GetListForObject().
147 
148  return ((THashList*)fCollection)->GetListForObject(obj);
149 }
150 
151 
int Int_t
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
float Float_t
Extended version of ROOT THashList.
Definition: KVHashList.h:28
Float_t AverageCollisions() const
Definition: KVHashList.cpp:64
virtual ~KVHashList()
Destructor.
Definition: KVHashList.cpp:52
void Rehash(Int_t newCapacity=0)
Definition: KVHashList.cpp:92
const TList * GetListForObject(const char *name) const
Definition: KVHashList.cpp:121
KaliVeda extensions to ROOT collection classes.
TSeqCollection * fCollection
Pointer to embedded ROOT collection.
virtual Int_t GetSize() const