KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
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
25
26KVHashList::KVHashList(Int_t capacity, Int_t rehash)
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
92void 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
121const TList* KVHashList::GetListForObject(const char* name) const
122#else
123TList* 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
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
float Float_t
char name[80]
Extended version of ROOT THashList.
Definition KVHashList.h:29
Float_t AverageCollisions() const
virtual ~KVHashList()
Destructor.
void Rehash(Int_t newCapacity=0)
const TList * GetListForObject(const char *name) const
KaliVeda extensions to ROOT collection classes.
TSeqCollection * fCollection
Pointer to embedded ROOT collection.
virtual Int_t GetSize() const
ClassImp(TPyArg)