oaHashMap.h

Go to the documentation of this file.
00001 // *****************************************************************************
00002 // *****************************************************************************
00003 // oaHashMap.h
00004 //
00005 // This file contains the definitions of the oaHashMap class.
00006 //
00007 //  oaHashMap
00008 //      This class implements a base class that can be used for all types of
00009 //      hash maps. It is used by deriving from it for a particular key and data
00010 //      type and then overriding the virtual functions hash() and compare() for
00011 //      that particular key type.
00012 //
00013 //  oaHashMapIter
00014 //      This class implements an iterator over all objects in a hash map.
00015 //
00016 // The following class is a private implementation class used by the public
00017 // classes described above.
00018 //
00019 //  oaHashMapTbl
00020 //      This class implements a hash table that stores indices into a separate
00021 //      array of keys that is stored in a separate, owning class.
00022 //
00023 // *****************************************************************************
00024 // Except as specified in the OpenAccess terms of use of Cadence or Silicon
00025 // Integration Initiative, this material may not be copied, modified,
00026 // re-published, uploaded, executed, or distributed in any way, in any medium,
00027 // in whole or in part, without prior written permission from Cadence.
00028 //
00029 //                Copyright 2002-2005 Cadence Design Systems, Inc.
00030 //                           All Rights Reserved.
00031 //
00032 //  $Author: icftcm $
00033 //  $Revision: #1 $
00034 //  $Date: 2010/08/09 $
00035 //  $State: Exp $
00036 // *****************************************************************************
00037 // *****************************************************************************
00038 
00039 
00040 
00041 #if !defined(oaHashMap_P)
00042 #define oaHashMap_P
00043 
00044 
00045 
00046 // *****************************************************************************
00047 // Nested includes
00048 // *****************************************************************************
00049 #include "oaArray.h"
00050 #include "oaHashTbl.h"
00051 
00052 
00053 
00054 // *****************************************************************************
00055 // Declare and define types in the OpenAccess namespace.
00056 // *****************************************************************************
00057 BEGIN_OA_NAMESPACE
00058 
00059 
00060 
00061 // *****************************************************************************
00062 // Forward declaration.
00063 // *****************************************************************************
00064 template<class K, class D>
00065 class oaHashMap;
00066 template<class K, class D>
00067 class oaHashMapIter;
00068 
00069 
00070 
00071 // *****************************************************************************
00072 // oaHashMapTbl
00073 //
00074 // This class implements a hash table that stores indices into an array of keys
00075 // that is stored in an owning class.
00076 // *****************************************************************************
00077 template<class K, class D>
00078 class oaHashMapTbl : public oaHashTbl<oaUInt4> {
00079 protected:
00080                             oaHashMapTbl(oaUInt4 sizeIn = 32);
00081 
00082     virtual void            hash(oaUInt4    index,
00083                                  oaUInt4    &start,
00084                                  oaUInt4    &stride) const;
00085     virtual oaBoolean       compare(oaUInt4     index,
00086                                     const void  *data) const;
00087 
00088     void                    setOwner(oaHashMap<K, D> *ownerIn);
00089 
00090     oaHashMap<K, D>         *owner;
00091 
00092     friend class oaHashMap<K, D>;
00093 };
00094 
00095 
00096 
00097 // *****************************************************************************
00098 // oaHashMap<K, D>
00099 // *****************************************************************************
00100 template<class K, class D>
00101 class oaHashMap {
00102 public:
00103                                 oaHashMap(oaUInt4 sizeIn = 32);
00104 
00105     void                        add(const K &key,
00106                                     const D &datum);
00107     oaBoolean                   find(const K    &key,
00108                                      D          &datum) const;
00109     void                        remove(const K &key);
00110 
00111     oaUInt4                     getNumEntries() const;
00112 
00113 protected:
00114     virtual void                hash(K          key,
00115                                      oaUInt4    &start,
00116                                      oaUInt4    &stride) const = 0;
00117     virtual oaBoolean           compare(K   key1,
00118                                         K   key2) const = 0;
00119 
00120     void                        hashIndex(oaUInt4   index,
00121                                           oaUInt4   &start,
00122                                           oaUInt4   &stride) const;
00123     oaBoolean                   compareIndex(oaUInt4    index,
00124                                              const K    &key) const;
00125 
00126     const oaHashMapTbl<K, D>    *getHashTbl() const;
00127 
00128     oaHashMapTbl<K, D>          tbl;
00129 
00130 private:
00131     oaArray<K>                  keys;
00132     oaArray<D>                  data;
00133 
00134     friend class oaHashMapTbl<K, D>;
00135     friend class oaHashMapIter<K, D>;
00136 };
00137 
00138 
00139 
00140 // *****************************************************************************
00141 // oaHashMapIter<K, D>
00142 //
00143 // This class defines an iterator for enumerating the contents of an oaHashMap.
00144 // *****************************************************************************
00145 template<class K, class D>
00146 class oaHashMapIter {
00147 public:
00148                             oaHashMapIter(oaHashMap<K, D> &mapIn);
00149 
00150     void                    reset();
00151 
00152     oaBoolean               getNext(K   &key,
00153                                     D   &datum);
00154 
00155 protected:
00156     oaHashMap<K, D>         &map;
00157     oaUInt4                 index;
00158 };
00159 
00160 
00161 
00162 END_OA_NAMESPACE
00163 
00164 #endif

Return to top of page