library: libCore #include "THashList.h"

# THashList

class description - source file - inheritance tree (.pdf)

## class THashList : public TList

| Inheritance Chart:
`TObject`
| <- | `TCollection`
| <- | `TSeqCollection`
| <- | `TList`
| <- | `THashList` |

        public:

                           THashList(Int_t capacity = TCollection::kInitHashTableCapacity, Int_t rehash = 0)
                           THashList(TObject* parent, Int_t capacity = TCollection::kInitHashTableCapacity, Int_t rehash = 0)
                   virtual ~THashList()
              virtual void AddAfter(const TObject* after, TObject* obj)
              virtual void AddAfter(TObjLink* after, TObject* obj)
              virtual void AddAt(TObject* obj, Int_t idx)
              virtual void AddBefore(const TObject* before, TObject* obj)
              virtual void AddBefore(TObjLink* before, TObject* obj)
              virtual void AddFirst(TObject* obj)
              virtual void AddFirst(TObject* obj, Option_t* opt)
              virtual void AddLast(TObject* obj)
              virtual void AddLast(TObject* obj, Option_t* opt)
                   Float_t AverageCollisions() const
            static TClass* Class()
              virtual void Clear(Option_t* option = "")
              virtual void Delete(Option_t* option = "")
          virtual TObject* FindObject(const char* name) const
          virtual TObject* FindObject(const TObject* obj) const
           virtual TClass* IsA() const
              virtual void RecursiveRemove(TObject* obj)
                      void Rehash(Int_t newCapacity)
          virtual TObject* Remove(TObject* obj)
          virtual TObject* Remove(TObjLink* lnk)
              virtual void ShowMembers(TMemberInspector& insp, char* parent)
              virtual void Streamer(TBuffer& b)
                      void StreamerNVirtual(TBuffer& b)

### Data Members

        protected:

          THashTable* fTable  Hashtable used for quick lookup of objects

## Class Description

     THashList

     THashList implements a hybrid collection class consisting of a
     hash table and a list to store TObject's. The hash table is used for
     quick access and lookup of objects while the list allows the objects
     to be ordered. 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.

/* */

THashList(Int_t capacity, Int_t rehash)

     Create a THashList object. Capacity is the initial hashtable capacity
     (i.e. number of slots), by default kInitHashTableCapacity = 17, and
     rehash 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 rehash
     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 rehash=0 the table will
     NOT automatically be rehashed. Use Rehash() for manual rehashing.
     WARNING !!!
     If the name of an object in the HashList is modified, The hashlist
     must be Rehashed

THashList(TObject *, Int_t capacity, Int_t rehash)

     For backward compatibility only. Use other ctor.

~THashList()

     Delete a hashlist. Objects are not deleted unless the THashList is the
     owner (set via SetOwner()).

void AddFirst(TObject *obj)

     Add object at the beginning of the list.

void AddFirst(TObject *obj, Option_t *opt)

     Add object at the beginning of the list and also store option.
     Storing an option is useful when one wants to change the behaviour
     of an object a little without having to create a complete new
     copy of the object. This feature is used, for example, by the Draw()
     method. It allows the same object to be drawn in different ways.

void AddLast(TObject *obj)

     Add object at the end of the list.

void AddLast(TObject *obj, Option_t *opt)

     Add object at the end of the list and also store option.
     Storing an option is useful when one wants to change the behaviour
     of an object a little without having to create a complete new
     copy of the object. This feature is used, for example, by the Draw()
     method. It allows the same object to be drawn in different ways.

void AddBefore(const TObject *before, TObject *obj)

     Insert object before object before in the list.

void AddBefore(TObjLink *before, TObject *obj)

     Insert object before object before in the list.

void AddAfter(const TObject *after, TObject *obj)

     Insert object after object after in the list.

void AddAfter(TObjLink *after, TObject *obj)

     Insert object after object after in the list.

void AddAt(TObject *obj, Int_t idx)

     Insert object at location idx in the list.

Float_t AverageCollisions() const

     Return the average collision rate. The higher the number the longer
     the linked lists in the hashtable, the slower the lookup. If the number
     is high, or lookup noticeably too slow, perfrom a Rehash().

void Clear(Option_t *option)

     Remove all objects from the list. Does not delete the objects unless
     the THashList is the owner (set via SetOwner()).

void Delete(Option_t *option)

     Remove all objects from the list AND delete all heap based objects.

TObject* FindObject(const char *name) const

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

TObject* FindObject(const TObject *obj) const

     Find object using its hash value (returned by its Hash() member).

void RecursiveRemove(TObject *obj)

     Remove object from this collection and recursively remove the object
     from all other objects (and collections).
     This function overrides TCollection::RecursiveRemove that calls
     the Remove function. THashList::Remove cannot be called because
     it uses the hash value of the hash table. This hash value
     is not available anymore when RecursiveRemove is called from
     the TObject destructor.

void Rehash(Int_t newCapacity)

     Rehash the hashlist. 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.

TObject* Remove(TObject *obj)

     Remove object from the list.

TObject* Remove(TObjLink *lnk)

     Remove object via its objlink from the list.

### Inline Functions

                TClass* Class()
                TClass* IsA() const
                   void ShowMembers(TMemberInspector& insp, char* parent)
                   void Streamer(TBuffer& b)
                   void StreamerNVirtual(TBuffer& b)

Author: Fons Rademakers 10/08/95
Last update: root/cont:$Name: $:$Id: THashList.cxx,v 1.7 2004/11/12 21:51:18 brun Exp $
Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *