#ifndef ROOT_TMap
#define ROOT_TMap
#ifndef ROOT_TCollection
#include "TCollection.h"
#endif
#ifndef ROOT_THashTable
#include "THashTable.h"
#endif
#include <iterator>
class THashTableIter;
class TMapIter;
class TPair;
class TBrowser;
class TMap : public TCollection {
friend class TMapIter;
private:
THashTable *fTable;
TMap(const TMap& map);
TMap& operator=(const TMap& map);
protected:
enum { kIsOwnerValue = BIT(15) };
virtual void PrintCollectionEntry(TObject* entry, Option_t* option, Int_t recurse) const;
public:
typedef TMapIter Iterator_t;
TMap(Int_t capacity = TCollection::kInitHashTableCapacity, Int_t rehash = 0);
virtual ~TMap();
void Add(TObject *obj);
void Add(TObject *key, TObject *value);
Float_t AverageCollisions() const;
Int_t Capacity() const;
void Clear(Option_t *option="");
Int_t Collisions(const char *keyname) const;
Int_t Collisions(TObject *key) const;
void Delete(Option_t *option="");
void DeleteKeys() { Delete(); }
void DeleteValues();
void DeleteAll();
Bool_t DeleteEntry(TObject *key);
TObject *FindObject(const char *keyname) const;
TObject *FindObject(const TObject *key) const;
TObject **GetObjectRef(const TObject *obj) const { return fTable->GetObjectRef(obj); }
const THashTable *GetTable() const { return fTable; }
TObject *GetValue(const char *keyname) const;
TObject *GetValue(const TObject *key) const;
Bool_t IsOwnerValue() const { return TestBit(kIsOwnerValue); }
TObject *operator()(const char *keyname) const { return GetValue(keyname); }
TObject *operator()(const TObject *key) const { return GetValue(key); }
TIterator *MakeIterator(Bool_t dir = kIterForward) const;
void Rehash(Int_t newCapacity, Bool_t checkObjValidity = kTRUE);
TObject *Remove(TObject *key);
TPair *RemoveEntry(TObject *key);
virtual void SetOwnerValue(Bool_t enable = kTRUE);
virtual void SetOwnerKeyValue(Bool_t ownkeys = kTRUE, Bool_t ownvals = kTRUE);
ClassDef(TMap,3)
};
class TPair : public TObject {
private:
TObject *fKey;
TObject *fValue;
TPair& operator=(const TPair&);
public:
TPair(TObject *key, TObject *value) : fKey(key), fValue(value) { }
TPair(const TPair &a) : TObject(), fKey(a.fKey), fValue(a.fValue) { }
virtual ~TPair() { }
Bool_t IsFolder() const { return kTRUE;}
virtual void Browse(TBrowser *b);
const char *GetName() const { return fKey->GetName(); }
const char *GetTitle() const { return fKey->GetTitle(); }
ULong_t Hash() const { return fKey->Hash(); }
Bool_t IsEqual(const TObject *obj) const { return fKey->IsEqual(obj); }
TObject *Key() const { return fKey; }
TObject *Value() const { return fValue; }
void SetValue(TObject *val) { fValue = val; }
ClassDef(TPair,0);
};
typedef TPair TAssoc;
class TMapIter : public TIterator,
public std::iterator<std::bidirectional_iterator_tag,
TObject*, std::ptrdiff_t,
const TObject**, const TObject*&> {
private:
const TMap *fMap;
THashTableIter *fCursor;
Bool_t fDirection;
TMapIter() : fMap(0), fCursor(0), fDirection(kIterForward) { }
public:
TMapIter(const TMap *map, Bool_t dir = kIterForward);
TMapIter(const TMapIter &iter);
~TMapIter();
TIterator &operator=(const TIterator &rhs);
TMapIter &operator=(const TMapIter &rhs);
const TCollection *GetCollection() const { return fMap; }
TObject *Next();
void Reset();
bool operator!=(const TIterator &aIter) const;
bool operator!=(const TMapIter &aIter) const;
TObject *operator*() const;
ClassDef(TMapIter,0)
};
#endif