Logo ROOT  
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#include <ROOT/RConfig.hxx>
23
24class RooAbsArg ;
25class RooLinkedList ;
27class RooSetPair ;
28class RooArgSet ;
29
30class RooHashTable : public TObject {
31public:
32
33 enum HashMethod { Pointer=0, Name=1, Intrinsic=2 } ;
34
35 // Constructor
36 RooHashTable(Int_t initSize = 17, HashMethod hashMethod=Name) ;
37 RooHashTable(const RooHashTable& other) ;
38
39 // Destructor
40 virtual ~RooHashTable() ;
41
42 void add(TObject* arg, TObject* hashArg=0) ;
43 Bool_t remove(TObject* arg, TObject* hashArg=0) ;
44 TObject* find(const char* name) const ;
45 RooAbsArg* findArg(const RooAbsArg* arg) const ;
46 TObject* find(const TObject* arg) const ;
47 RooLinkedListElem* findLinkTo(const TObject* arg) const ;
48 RooSetPair* findSetPair(const RooArgSet* set1, const RooArgSet* set2) const ;
49 Bool_t replace(const TObject* oldArg, const TObject* newArg, const TObject* oldHashArg=0) ;
50 Int_t size() const { return _size ; }
51 Int_t entries() const { return _entries ; }
52 Double_t avgCollisions() const ;
53
54protected:
55 inline ULong_t hash(const TObject* arg) const {
56 // Return hash value calculated by method chosen in constructor
57 switch(_hashMethod) {
58 case Pointer: return TString::Hash((void*)(&arg),sizeof(void*)) ;
59 case Name: return TString::Hash(arg->GetName(),strlen(arg->GetName())) ;
60 case Intrinsic: return arg->Hash() ;
61 }
62 return 0 ;
63 }
64
65 HashMethod _hashMethod ; // Hashing method
66 Int_t _usedSlots ; // Number of used slots
67 Int_t _entries ; // Number of entries stored
68 Int_t _size ; // Total number of slots
69 RooLinkedList** _arr ; //! Array of linked lists storing elements in each slot
70
71 ClassDef(RooHashTable,1) // Hash table
72} R__SUGGEST_ALTERNATIVE("Please use std::unordered_map, which is also a hash table.");
73
74#endif
#define R__SUGGEST_ALTERNATIVE(ALTERNATIVE)
Definition: RConfig.hxx:521
int Int_t
Definition: RtypesCore.h:45
unsigned long ULong_t
Definition: RtypesCore.h:55
bool Bool_t
Definition: RtypesCore.h:63
double Double_t
Definition: RtypesCore.h:59
#define ClassDef(name, id)
Definition: Rtypes.h:325
char name[80]
Definition: TGX11.cxx:110
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:72
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:35
RooHashTable implements a hash table for TObjects.
Definition: RooHashTable.h:30
RooLinkedList ** _arr
Definition: RooHashTable.h:69
Bool_t remove(TObject *arg, TObject *hashArg=0)
Remove given object from table.
Int_t size() const
Definition: RooHashTable.h:50
RooLinkedListElem * findLinkTo(const TObject *arg) const
Return RooLinkedList element link to object 'hashArg'.
Int_t entries() const
Definition: RooHashTable.h:51
Int_t _entries
Definition: RooHashTable.h:67
HashMethod _hashMethod
Definition: RooHashTable.h:65
Bool_t replace(const TObject *oldArg, const TObject *newArg, const TObject *oldHashArg=0)
Replace oldArg with newArg in the table.
ULong_t hash(const TObject *arg) const
Definition: RooHashTable.h:55
RooSetPair * findSetPair(const RooArgSet *set1, const RooArgSet *set2) const
Return RooSetPair with given pointers in table.
TObject * find(const char *name) const
Return the object with given name from the table.
virtual ~RooHashTable()
Destructor.
RooHashTable(Int_t initSize=17, HashMethod hashMethod=Name)
Construct a hash table with given capacity and hash method.
Int_t _usedSlots
Definition: RooHashTable.h:66
Double_t avgCollisions() const
Calculate the average number of collisions (table slots with >1 filled entry)
void add(TObject *arg, TObject *hashArg=0)
Add given object to table.
RooAbsArg * findArg(const RooAbsArg *arg) const
RooLinkedListElem is an link element for the RooLinkedList class.
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
Definition: RooLinkedList.h:38
RooSetPair is a utility class that stores a pair of RooArgSets.
Definition: RooSetPair.h:26
Mother of all ROOT objects.
Definition: TObject.h:37
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:359
virtual ULong_t Hash() const
Return hash value for this object.
Definition: TObject.cxx:435
UInt_t Hash(ECaseCompare cmp=kExact) const
Return hash value.
Definition: TString.cxx:662