00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TMap
00013 #define ROOT_TMap
00014
00015
00017
00018
00019
00020
00021
00022
00023
00024
00025
00027
00028 #ifndef ROOT_TCollection
00029 #include "TCollection.h"
00030 #endif
00031 #ifndef ROOT_THashTable
00032 #include "THashTable.h"
00033 #endif
00034
00035 class THashTableIter;
00036 class TMapIter;
00037 class TBrowser;
00038
00039
00040 class TMap : public TCollection {
00041
00042 friend class TMapIter;
00043
00044 private:
00045 THashTable *fTable;
00046
00047 public:
00048 TMap(Int_t capacity = TCollection::kInitHashTableCapacity, Int_t rehash = 0);
00049 virtual ~TMap();
00050 void Add(TObject *obj);
00051 void Add(TObject *key, TObject *value);
00052 Float_t AverageCollisions() const;
00053 Int_t Capacity() const;
00054 void Clear(Option_t *option="");
00055 Int_t Collisions(const char *keyname) const;
00056 Int_t Collisions(TObject *key) const;
00057 void Delete(Option_t *option="");
00058 void DeleteKeys() { Delete(); }
00059 void DeleteValues();
00060 void DeleteAll();
00061 TObject *FindObject(const char *keyname) const;
00062 TObject *FindObject(const TObject *key) const;
00063 TObject **GetObjectRef(const TObject *obj) const { return fTable->GetObjectRef(obj); }
00064 const THashTable *GetTable() const { return fTable; }
00065 TObject *GetValue(const TObject *key) const;
00066 TIterator *MakeIterator(Bool_t dir = kIterForward) const;
00067 void Print(Option_t *option="") const;
00068 void Rehash(Int_t newCapacity, Bool_t checkObjValidity = kTRUE);
00069 TObject *Remove(TObject *key);
00070
00071 ClassDef(TMap,3)
00072 };
00073
00074
00076
00077
00078
00079
00080
00082
00083 class TPair : public TObject {
00084
00085 private:
00086 TObject *fKey;
00087 TObject *fValue;
00088
00089 public:
00090 TPair(TObject *key, TObject *value) : fKey(key), fValue(value) { }
00091 TPair(const TPair &a) : TObject(), fKey(a.fKey), fValue(a.fValue) { }
00092 virtual ~TPair() { }
00093 Bool_t IsFolder() const { return kTRUE;}
00094 virtual void Browse(TBrowser *b);
00095 const char *GetName() const { return fKey->GetName(); }
00096 ULong_t Hash() const { return fKey->Hash(); }
00097 Bool_t IsEqual(const TObject *obj) const { return fKey->IsEqual(obj); }
00098 TObject *Key() const { return fKey; }
00099 TObject *Value() const { return fValue; }
00100
00101 ClassDef(TPair,0);
00102 };
00103
00104 typedef TPair TAssoc;
00105
00106
00108
00109
00110
00111
00112
00114
00115 class TMapIter : public TIterator {
00116
00117 private:
00118 const TMap *fMap;
00119 THashTableIter *fCursor;
00120 Bool_t fDirection;
00121
00122 TMapIter() : fMap(0), fCursor(0) { }
00123
00124 public:
00125 TMapIter(const TMap *map, Bool_t dir = kIterForward);
00126 TMapIter(const TMapIter &iter);
00127 ~TMapIter();
00128 TIterator &operator=(const TIterator &rhs);
00129 TMapIter &operator=(const TMapIter &rhs);
00130
00131 const TCollection *GetCollection() const { return fMap; }
00132 TObject *Next();
00133 void Reset();
00134
00135 ClassDef(TMapIter,0)
00136 };
00137
00138 #endif