Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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