33 if (mapSize < 4) mapSize = 5;
37 case 5: fSize = 5;
break;
38 case 503: fSize = 503;
break;
42 fTable =
new Assoc_t [fSize];
44 memset(fTable,0,
sizeof(Assoc_t)*fSize);
90 if (!
fTable[slot].InUse()) {
98 Error(
"Add",
"key %lld is not unique", key);
118 if (!
fTable[slot].InUse()) {
140 Error(
"operator()",
"fTable==0, should never happen");
145 if (!
fTable[slot].InUse()) {
177 Int_t firstSlot = slot;
179 if (!
fTable[slot].InUse())
return 0;
181 if (++slot == fSize) slot = 0;
182 }
while (firstSlot != slot);
184 Error(
"GetValue",
"table full");
196 if (!
fTable) { slot = 0;
return 0; }
199 slot =
Int_t(hash % fSize);
202 if (!
fTable[slot].InUse())
return 0;
204 if (++slot == (
UInt_t)fSize) slot = 0;
205 }
while (firstSlot != slot);
207 Error(
"GetValue",
"table full");
221 Error(
"Remove",
"key %lld not found at %d", key, i);
240 Int_t firstSlot = slot;
242 if (!
fTable[slot].InUse())
return slot;
243 if (key ==
fTable[slot].fKey)
return slot;
244 if (++slot == fSize) slot = 0;
245 }
while (firstSlot != slot);
247 Error(
"FindElement",
"table full");
256 Int_t oldIndex, nextIndex;
259 for (oldIndex = index+1; ;oldIndex++) {
260 if (oldIndex >= fSize)
262 nextObject =
fTable[oldIndex];
263 if (!nextObject.
InUse())
266 if (nextIndex != oldIndex) {
267 fTable[nextIndex] = nextObject;
284 for (i = newSize; --i >= 0;) {
289 for (i = 0; i < oldsize; i++)
290 if (oldTable[i].InUse()) {
292 if (!
fTable[slot].InUse())
293 fTable[slot] = oldTable[i];
295 Error(
"Expand",
"slot %d not empty (should never happen)", slot);
303 void TExMap::Streamer(
TBuffer &b)
310 TObject::Streamer(b);
321 for (i = 0; i < tally; ++i) {
326 Assoc_t *assoc =
fTable + slot;
329 assoc->fValue =
value;
332 }
else if (R__v >= 2) {
341 for (i = 0; i < tally; ++i) {
346 Assoc_t* assoc =
fTable + slot;
349 assoc->fValue =
value;
358 for (i = 0; i <
n; i++) {
362 Add(hash, key, value);
369 TObject::Streamer(b);
373 for (i=0; i <
fSize; i++) {
374 if (!
fTable[i].InUse())
continue;
431 return Next(hash, key, value);
void Add(ULong64_t hash, Long64_t key, Long64_t value)
Add an (key,value) pair to the table. The key should be unique.
void Remove(ULong64_t hash, Long64_t key)
Remove entry with specified key from the TExMap.
Int_t FindElement(ULong64_t hash, Long64_t key)
Find an entry with specified hash and key in the TExMap.
Buffer base class used for serializing objects.
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
ClassImp(TExMap) TExMap
Create a TExMap.
void SetHash(ULong64_t h)
TObject & operator=(const TObject &rhs)
TObject assignment operator.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Long64_t GetValue(ULong64_t hash, Long64_t key)
Return the value belonging to specified key and hash value.
Long64_t & operator()(ULong64_t hash, Long64_t key)
Return a reference to the value belonging to the key with the specified hash value.
virtual void SetByteCount(UInt_t cntpos, Bool_t packInVersion=kFALSE)=0
void Delete(Option_t *opt="")
Delete all entries stored in the TExMap.
TExMap & operator=(const TExMap &)
Assignment operator.
void FixCollisions(Int_t index)
Rehash the map in case an entry has been removed.
Long_t NextPrime(Long_t x)
TMath Base functions.
TExMapIter & operator=(const TExMapIter &)
Overloaded assignment operator.
unsigned long long ULong64_t
Mother of all ROOT objects.
Bool_t Next(ULong64_t &hash, Long64_t &key, Long64_t &value)
Get next entry from TExMap. Returns kFALSE at end of map.
TExMap(Int_t mapSize=100)
ULong64_t GetHash() const
This class stores a (key,value) pair using an external hash.
void Expand(Int_t newsize)
Expand the TExMap.
void AddAt(UInt_t slot, ULong64_t hash, Long64_t key, Long64_t value)
Add an (key,value) pair to the table.
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0