RooHashTable.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  *    File: $Id: RooHashTable.h,v 1.12 2007/05/11 09:11:30 verkerke Exp $
00005  * Authors:                                                                  *
00006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
00007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
00008  *                                                                           *
00009  * Copyright (c) 2000-2005, Regents of the University of California          *
00010  *                          and Stanford University. All rights reserved.    *
00011  *                                                                           *
00012  * Redistribution and use in source and binary forms,                        *
00013  * with or without modification, are permitted according to the terms        *
00014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00015  *****************************************************************************/
00016 #ifndef ROO_HASH_TABLE
00017 #define ROO_HASH_TABLE
00018 
00019 #include "TObject.h"
00020 #include "TString.h"
00021 
00022 class RooAbsArg ;
00023 class RooLinkedList ;
00024 class RooLinkedListElem ;
00025 class RooSetPair ;
00026 class RooArgSet ;
00027 
00028 class RooHashTable : public TObject {
00029 public:
00030 
00031   enum HashMethod { Pointer=0, Name=1, Intrinsic=2 } ;
00032 
00033   // Constructor
00034   RooHashTable(Int_t initSize = 17, HashMethod hashMethod=Name) ;
00035   RooHashTable(const RooHashTable& other) ;
00036 
00037   // Destructor
00038   virtual ~RooHashTable() ;
00039 
00040   void add(TObject* arg, TObject* hashArg=0) ;
00041   Bool_t remove(TObject* arg, TObject* hashArg=0) ;
00042   TObject* find(const char* name) const ;
00043   TObject* find(const TObject* arg) const ;
00044   RooLinkedListElem* findLinkTo(const TObject* arg) const ;
00045   RooSetPair* findSetPair(const RooArgSet* set1, const RooArgSet* set2) const ;  
00046   Bool_t replace(const TObject* oldArg, const TObject* newArg, const TObject* oldHashArg=0) ;
00047   Int_t size() const { return _size ; }
00048   Double_t avgCollisions() const ;
00049 
00050 protected:  
00051   inline ULong_t hash(const TObject* arg) const {
00052     // Return hash value calculated by method chosen in constructor
00053     switch(_hashMethod) {
00054       case Pointer:   return TString::Hash((void*)(&arg),sizeof(void*)) ;
00055       case Name:      return TString::Hash(arg->GetName(),strlen(arg->GetName())) ;
00056       case Intrinsic: return arg->Hash() ;
00057     }
00058     return 0 ;
00059   }
00060 
00061   HashMethod _hashMethod ; // Hashing method
00062   Int_t _usedSlots ;       // Number of used slots
00063   Int_t _entries ;         // Number of entries stored
00064   Int_t _size ;            // Total number of slots
00065   RooLinkedList** _arr ;   //! Array of linked lists storing elements in each slot
00066 
00067   ClassDef(RooHashTable,1) // Hash table
00068 };
00069 
00070 
00071 
00072 
00073 #endif

Generated on Tue Jul 5 14:26:12 2011 for ROOT_528-00b_version by  doxygen 1.5.1