Logo ROOT   6.10/09
Reference Guide
RooHashTable.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * File: $Id: RooHashTable.h,v 1.12 2007/05/11 09:11:30 verkerke Exp $
5  * Authors: *
6  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8  * *
9  * Copyright (c) 2000-2005, Regents of the University of California *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 #ifndef ROO_HASH_TABLE
17 #define ROO_HASH_TABLE
18 
19 #include "TObject.h"
20 #include "TString.h"
21 
22 class RooAbsArg ;
23 class RooLinkedList ;
24 class RooLinkedListElem ;
25 class RooSetPair ;
26 class RooArgSet ;
27 
28 class RooHashTable : public TObject {
29 public:
30 
31  enum HashMethod { Pointer=0, Name=1, Intrinsic=2 } ;
32 
33  // Constructor
34  RooHashTable(Int_t initSize = 17, HashMethod hashMethod=Name) ;
35  RooHashTable(const RooHashTable& other) ;
36 
37  // Destructor
38  virtual ~RooHashTable() ;
39 
40  void add(TObject* arg, TObject* hashArg=0) ;
41  Bool_t remove(TObject* arg, TObject* hashArg=0) ;
42  TObject* find(const char* name) const ;
43  RooAbsArg* findArg(const RooAbsArg* arg) const ;
44  TObject* find(const TObject* arg) const ;
45  RooLinkedListElem* findLinkTo(const TObject* arg) const ;
46  RooSetPair* findSetPair(const RooArgSet* set1, const RooArgSet* set2) const ;
47  Bool_t replace(const TObject* oldArg, const TObject* newArg, const TObject* oldHashArg=0) ;
48  Int_t size() const { return _size ; }
49  Int_t entries() const { return _entries ; }
50  Double_t avgCollisions() const ;
51 
52 protected:
53  inline ULong_t hash(const TObject* arg) const {
54  // Return hash value calculated by method chosen in constructor
55  switch(_hashMethod) {
56  case Pointer: return TString::Hash((void*)(&arg),sizeof(void*)) ;
57  case Name: return TString::Hash(arg->GetName(),strlen(arg->GetName())) ;
58  case Intrinsic: return arg->Hash() ;
59  }
60  return 0 ;
61  }
62 
63  HashMethod _hashMethod ; // Hashing method
64  Int_t _usedSlots ; // Number of used slots
65  Int_t _entries ; // Number of entries stored
66  Int_t _size ; // Total number of slots
67  RooLinkedList** _arr ; //! Array of linked lists storing elements in each slot
68 
69  ClassDef(RooHashTable,1) // Hash table
70 };
71 
72 
73 
74 
75 #endif
virtual ULong_t Hash() const
Return hash value for this object.
Definition: TObject.cxx:426
Double_t avgCollisions() const
Calculate the average number of collisions (table slots with >1 filled entry)
Int_t _entries
Definition: RooHashTable.h:65
RooHashTable(Int_t initSize=17, HashMethod hashMethod=Name)
Construct a hash table with given capacity and hash method.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Bool_t replace(const TObject *oldArg, const TObject *newArg, const TObject *oldHashArg=0)
Replace oldArg with newArg in the table.
Int_t _usedSlots
Definition: RooHashTable.h:64
UInt_t Hash(ECaseCompare cmp=kExact) const
Return hash value.
Definition: TString.cxx:616
RooLinkedListElem * findLinkTo(const TObject *arg) const
Return RooLinkedList element link to object 'hashArg'.
#define ClassDef(name, id)
Definition: Rtypes.h:297
RooHashTable implements a hash table for TObjects.
Definition: RooHashTable.h:28
void add(TObject *arg, TObject *hashArg=0)
Add given object to table.
RooSetPair * findSetPair(const RooArgSet *set1, const RooArgSet *set2) const
Return RooSetPair with given pointers in table.
HashMethod _hashMethod
Definition: RooHashTable.h:63
TObject * find(const char *name) const
Return the object with given name from the table.
virtual ~RooHashTable()
Destructor.
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
Definition: RooLinkedList.h:35
double Double_t
Definition: RtypesCore.h:55
unsigned long ULong_t
Definition: RtypesCore.h:51
Int_t size() const
Definition: RooHashTable.h:48
Mother of all ROOT objects.
Definition: TObject.h:37
RooLinkedList ** _arr
Definition: RooHashTable.h:67
ULong_t hash(const TObject *arg) const
Definition: RooHashTable.h:53
RooLinkedListElem is an link element for the RooLinkedList class.
Int_t entries() const
Definition: RooHashTable.h:49
RooAbsArg * findArg(const RooAbsArg *arg) const
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
RooSetPair is a utility class that stores a pair of RooArgSets.
Definition: RooSetPair.h:26
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:364