29 ClassImp(RooHashTable);
46 RooHashTable::RooHashTable(Int_t capacity, HashMethod hashMethod) :
47 _hashMethod(hashMethod)
50 capacity = TCollection::kInitHashTableCapacity;
52 _size = (Int_t)TMath::NextPrime(TMath::Max(capacity,(
int)TCollection::kInitHashTableCapacity));
53 _arr =
new RooLinkedList* [_size] ;
54 memset(_arr, 0, _size*
sizeof(RooLinkedList*));
65 RooHashTable::RooHashTable(
const RooHashTable& other) :
67 _hashMethod(other._hashMethod),
68 _usedSlots(other._usedSlots),
69 _entries(other._entries),
72 _arr =
new RooLinkedList* [_size] ;
73 memset(_arr, 0, _size*
sizeof(RooLinkedList*));
75 for (i=0 ; i<_size ; i++) {
77 _arr[i] =
new RooLinkedList(*other._arr[i]) ;
88 void RooHashTable::add(TObject* arg, TObject* hashArg)
90 Int_t slot = hash(hashArg?hashArg:arg) % _size ;
92 _arr[slot] =
new RooLinkedList(0) ;
93 _arr[slot]->useNptr(kFALSE) ;
106 Bool_t RooHashTable::remove(TObject* arg, TObject* hashArg)
108 Int_t slot = hash(hashArg?hashArg:arg) % _size ;
110 if (_arr[slot]->Remove(arg)) {
112 if (_arr[slot]->GetSize()==0) {
121 if (_hashMethod != Name)
return kFALSE;
124 RooAbsArg* p =
dynamic_cast<RooAbsArg*
>(arg);
126 if (p && !p->namePtr()->TestBit(RooNameReg::kRenamedArg))
return kFALSE;
130 for (i=0 ; i<_size ; i++) {
131 if (i != slot && _arr[i] && _arr[i]->Remove(arg)) {
133 if (_arr[i]->GetSize()==0) {
150 Double_t RooHashTable::avgCollisions()
const
153 for (i=0 ; i<20 ; i++) h[i]=0 ;
155 for (i=0 ; i<_size ; i++) {
157 Int_t count = _arr[i]->GetSize() ;
177 Bool_t RooHashTable::replace(
const TObject* oldArg,
const TObject* newArg,
const TObject* oldHashArg)
179 Int_t slot = hash(oldHashArg?oldHashArg:oldArg) % _size ;
181 Int_t newSlot = hash(newArg) % _size ;
182 if (newSlot == slot) {
183 return _arr[slot]->Replace(oldArg,newArg) ;
188 if (
remove((TObject*)oldArg,(TObject*)oldHashArg)) {
189 add((TObject*)newArg);
200 TObject* RooHashTable::find(
const char* name)
const
202 if (_hashMethod != Name) assert(0) ;
204 Int_t slot = TMath::Hash(name) % _size ;
205 if (_arr[slot])
return _arr[slot]->find(name) ;
213 RooAbsArg* RooHashTable::findArg(
const RooAbsArg* arg)
const
215 if (_hashMethod != Name) assert(0) ;
217 Int_t slot = TMath::Hash(arg->GetName()) % _size ;
218 if (_arr[slot])
return _arr[slot]->findArg(arg) ;
227 TObject* RooHashTable::find(
const TObject* hashArg)
const
229 RooLinkedListElem* elem = findLinkTo(hashArg) ;
230 return elem ? elem->_arg : 0 ;
238 RooLinkedListElem* RooHashTable::findLinkTo(
const TObject* hashArg)
const
240 if (_hashMethod != Pointer) assert(0) ;
242 Int_t slot = hash(hashArg) % _size ;
243 RooLinkedList* lst = _arr[slot];
245 RooFIter it = lst->fwdIterator() ;
247 while ((obj=it.next())) {
248 RooLinkedListElem* elem = (RooLinkedListElem*)obj ;
249 if (elem->_arg == hashArg)
return elem ;
260 RooSetPair* RooHashTable::findSetPair(
const RooArgSet* set1,
const RooArgSet* set2)
const
262 if (_hashMethod != Intrinsic) assert(0) ;
264 Int_t slot = RooSetPair(set1,set2).Hash() % _size ;
267 for (i=0 ; i<_arr[slot]->GetSize() ; i++) {
268 RooSetPair* pair = (RooSetPair*)_arr[slot]->At(i) ;
269 if (pair->_set1==set1 && pair->_set2==set2) {
284 RooHashTable::~RooHashTable()
287 for (i=0 ; i<_size ; i++) {
288 if (_arr[i])
delete _arr[i] ;