TExMap.h

Go to the documentation of this file.
00001 // @(#)root/cont:$Id: TExMap.h 34618 2010-07-27 15:52:34Z rdm $
00002 // Author: Fons Rademakers   26/05/99
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TExMap
00013 #define ROOT_TExMap
00014 
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TExMap                                                               //
00019 //                                                                      //
00020 // This class stores a (key,value) pair using an external hash.         //
00021 // The (key,value) are Long64_t's and therefore can contain object      //
00022 // pointers or any longs. The map uses an open addressing hashing       //
00023 // method (linear probing).                                             //
00024 //                                                                      //
00025 //////////////////////////////////////////////////////////////////////////
00026 
00027 
00028 #ifndef ROOT_TObject
00029 #include "TObject.h"
00030 #endif
00031 
00032 class TExMapIter;
00033 
00034 
00035 class TExMap : public TObject {
00036 
00037 friend class TExMapIter;
00038 
00039 private:
00040    struct Assoc_t {
00041    private:
00042       ULong64_t  fHash;
00043    public:
00044       Long64_t   fKey;
00045       Long64_t   fValue;
00046       void       SetHash(ULong64_t h) { fHash = (h | 1); } // bit(0) is "1" when in use
00047       ULong64_t  GetHash() const { return fHash; }
00048       Bool_t     InUse() const { return fHash & 1; }
00049       void       Clear() { fHash = 0x0; }
00050    };
00051 
00052    Assoc_t    *fTable;
00053    Int_t       fSize;
00054    Int_t       fTally;
00055 
00056    Bool_t      HighWaterMark() { return (Bool_t) (fTally >= ((3*fSize)/4)); }
00057    Int_t       FindElement(ULong64_t hash, Long64_t key);
00058    void        FixCollisions(Int_t index);
00059 
00060 
00061 public:
00062    TExMap(Int_t mapSize = 100);
00063    TExMap(const TExMap &map);
00064    TExMap& operator=(const TExMap&);
00065    ~TExMap();
00066 
00067    void      Add(ULong64_t hash, Long64_t key, Long64_t value);
00068    void      Add(Long64_t key, Long64_t value) { Add(key, key, value); }
00069    void      AddAt(UInt_t slot, ULong64_t hash, Long64_t key, Long64_t value);
00070    void      Delete(Option_t *opt = "");
00071    Int_t     Capacity() const { return fSize; }
00072    void      Expand(Int_t newsize);
00073    Int_t     GetSize() const { return fTally; }
00074    Long64_t  GetValue(ULong64_t hash, Long64_t key);
00075    Long64_t  GetValue(Long64_t key) { return GetValue(key, key); }
00076    Long64_t  GetValue(ULong64_t hash, Long64_t key, UInt_t &slot);
00077    void      Remove(ULong64_t hash, Long64_t key);
00078    void      Remove(Long64_t key) { Remove(key, key); }
00079 
00080    Long64_t &operator()(ULong64_t hash, Long64_t key);
00081    Long64_t &operator()(Long64_t key) { return operator()(key, key); }
00082 
00083    ClassDef(TExMap,3)  //Map with external hash
00084 };
00085 
00086 
00087 class TExMapIter {
00088 
00089 private:
00090    const TExMap   *fMap;
00091    Int_t           fCursor;
00092 
00093 public:
00094    TExMapIter(const TExMap *map);
00095    TExMapIter(const TExMapIter& tei) : fMap(tei.fMap), fCursor(tei.fCursor) { }
00096    TExMapIter& operator=(const TExMapIter&);
00097    virtual ~TExMapIter() { }
00098 
00099    const TExMap  *GetCollection() const { return fMap; }
00100    Bool_t         Next(ULong64_t &hash, Long64_t &key, Long64_t &value);
00101    Bool_t         Next(Long64_t &key, Long64_t &value);
00102    void           Reset() { fCursor = 0; }
00103 
00104    ClassDef(TExMapIter,0)  // TExMap iterator
00105 };
00106 
00107 #endif

Generated on Tue Jul 5 14:11:27 2011 for ROOT_528-00b_version by  doxygen 1.5.1