/usr/include/root/TMap.h is in libroot-core-dev 5.34.19+dfsg-1.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | // @(#)root/cont:$Id$
// Author: Fons Rademakers 12/11/95
/*************************************************************************
* Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#ifndef ROOT_TMap
#define ROOT_TMap
//////////////////////////////////////////////////////////////////////////
// //
// TMap //
// //
// TMap implements an associative array of (key,value) pairs using a //
// hash table for efficient retrieval (therefore TMap does not conserve //
// the order of the entries). The hash value is calculated //
// using the value returned by the keys Hash() function. Both key and //
// value need to inherit from TObject. //
// //
//////////////////////////////////////////////////////////////////////////
#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; //Hash table used to store TPair's
TMap(const TMap& map); // not implemented
TMap& operator=(const TMap& map); // not implemented
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);
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0);
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0) const;
ClassDef(TMap,3) //A (key,value) map
};
//////////////////////////////////////////////////////////////////////////
// //
// TPair //
// //
// Class used by TMap to store (key,value) pairs. //
// //
//////////////////////////////////////////////////////////////////////////
class TPair : public TObject {
private:
TObject *fKey;
TObject *fValue;
TPair& operator=(const TPair&); // Not implemented
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); // Pair TObject*, TObject*
};
typedef TPair TAssoc; // for backward compatibility
// Preventing warnings with -Weffc++ in GCC since it is a false positive for the TMapIter destructor.
#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40600
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#endif
//////////////////////////////////////////////////////////////////////////
// //
// TMapIter //
// //
// Iterator of a map. //
// //
//////////////////////////////////////////////////////////////////////////
class TMapIter : public TIterator,
public std::iterator<std::bidirectional_iterator_tag,
TObject*, std::ptrdiff_t,
const TObject**, const TObject*&> {
private:
const TMap *fMap; //map being iterated
THashTableIter *fCursor; //current position in map
Bool_t fDirection; //iteration direction
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_t operator!=(const TIterator &aIter) const;
Bool_t operator!=(const TMapIter &aIter) const;
TObject *operator*() const;
ClassDef(TMapIter,0) //Map iterator
};
#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40600
#pragma GCC diagnostic pop
#endif
#endif
|