THashTable


class description - source file - inheritance tree

class THashTable : public TCollection

    private:
Int_t GetHashValue(TObject* obj) const Int_t GetHashValue(TString& s) Int_t GetHashValue(const char* str) const public:
THashTable THashTable(Int_t capacity = TCollection::kInitHashTableCapacity, Int_t rehash = 0) virtual void ~THashTable() virtual void Add(TObject* obj) Float_t AverageCollisions() const TClass* Class() virtual void Clear(Option_t* option) Int_t Collisions(const char* name) const Int_t Collisions(TObject* obj) const virtual void Delete(Option_t* option) virtual TObject* FindObject(const Text_t* name) const virtual TObject* FindObject(TObject* obj) const virtual Int_t GetSize() const virtual TClass* IsA() const virtual TIterator* MakeIterator(Bool_t dir = kIterForward) const void Rehash(Int_t newCapacity, Bool_t checkObjValidity = kTRUE) virtual TObject* Remove(TObject* obj) virtual void ShowMembers(TMemberInspector& insp, char* parent) virtual void Streamer(TBuffer& b)

Data Members

private:
TList** fCont Hash table (table of lists) Int_t fEntries Number of objects in table Int_t fUsedSlots Number of used slots Int_t fRehashLevel Average collision rate which triggers rehash

Class Description

                                                                      
 THashTable                                                           
                                                                      
 THashTable implements a hash table to store TObject's. The hash      
 value is calculated using the value returned by the TObject's        
 Hash() function. Each class inheriting from TObject can override     
 Hash() as it sees fit.                                               
 THashTable does not preserve the insertion order of the objects.     
 If the insertion order is important AND fast retrieval is needed     
 use THashList instead.                                               

/*

*/

                                                                      


THashTable(Int_t capacity, Int_t rehashlevel)
 Create a THashTable object. Capacity is the initial hashtable capacity
 (i.e. number of slots), by default kInitHashTableCapacity = 17, and
 rehashlevel is the value at which a rehash will be triggered. I.e. when
 the average size of the linked lists at a slot becomes longer than
 rehashlevel then the hashtable will be resized and refilled to reduce
 the collision rate to about 1. The higher the collision rate, i.e. the
 longer the linked lists, the longer lookup will take. If rehashlevel=0
 the table will NOT automatically be rehashed. Use Rehash() for manual
 rehashing.

~THashTable()
 Delete a hashtable. All objects will be removed from the table before the
 table will be deleted.

void Add(TObject *obj)
 Add object to the hash table. Its position in the table will be
 determined by the value returned by its Hash() function.

void Clear(Option_t *option)
 Remove all objects from the table. Does not delete the objects.

Int_t Collisions(const char *name) const
 Returns the number of collisions for an object with a certain name
 (i.e. number of objects in same slot in the hash table, i.e. length
 of linked list).

Int_t Collisions(TObject *obj) const
 Returns the number of collisions for an object (i.e. number of objects
 in same slot in the hash table, i.e. length of linked list).

void Delete(Option_t *)
 Remove all objects from the table AND delete all heap based objects.

TObject* FindObject(const Text_t *name) const
 Find object using its name. Uses the hash value returned by the
 TString::Hash() after converting name to a TString.

TObject* FindObject(TObject *obj) const
 Find object using its hash value (returned by its Hash() member).

TIterator* MakeIterator(Bool_t dir) const
 Returns a hash table iterator.

void Rehash(Int_t newCapacity, Bool_t checkObjValidity)
 Rehash the hashtable. If the collision rate becomes too high (i.e.
 the average size of the linked lists become too long) then lookup
 efficiency decreases since relatively long lists have to be searched
 every time. To improve performance rehash the hashtable. This resizes
 the table to newCapacity slots and refills the table. Use
 AverageCollisions() to check if you need to rehash. Set checkObjValidity
 to kFALSE if you know that all objects in the table are still valid
 (i.e. have not been deleted from the system in the meanwhile).

TObject* Remove(TObject *obj)
 Remove object from the hashtable.



Inline Functions


              Int_t GetHashValue(TObject* obj) const
              Int_t GetHashValue(TString& s)
              Int_t GetHashValue(const char* str) const
            Float_t AverageCollisions() const
              Int_t GetSize() const
            TClass* Class()
            TClass* IsA() const
               void ShowMembers(TMemberInspector& insp, char* parent)
               void Streamer(TBuffer& b)


Author: Fons Rademakers 27/09/95
Last update: 2.23/07 27/10/99 10.47.27 by Fons Rademakers
Copyright (c) 1995-1999, The ROOT System, All rights reserved. *


ROOT page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.