00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef skHASHTBL_H
00022 #define skHASHTBL_H
00023
00024
00025 #include "skGeneral.h"
00026 #include "skAlist.h"
00027
00031 class CLASSEXPORT skHashEntry
00032 {
00033 public:
00037 skHashEntry(void * k,void * v)
00038 : m_Key(k), m_Value(v) {
00039 }
00043 int operator==(const skHashEntry& h) {
00044 return this==&h;
00045 }
00046 void * m_Key;
00047 void * m_Value;
00048 };
00049
00050 typedef skTAList<skHashEntry> skHashEntryList;
00051 typedef skTAListIterator<skHashEntry> skHashEntryListIterator;
00052
00058 class CLASSEXPORT skHashTable
00059 #ifdef __SYMBIAN32__
00060 : public CBase
00061 #endif
00062 {
00063 public:
00067 IMPORT_C void clear();
00071 IMPORT_C void clearAndDestroyKeys();
00075 IMPORT_C void clearAndDestroyValues();
00079 IMPORT_C void clearAndDestroy();
00083 inline USize entries() const;
00087 inline virtual ~skHashTable();
00088 #ifdef __SYMBIAN32__
00089
00094 operator TCleanupItem();
00099 static void Cleanup(TAny * s);
00100 #endif
00101 protected:
00105 skHashTable(USize size);
00110 IMPORT_C void insertKeyAndValue(void * key, void * value);
00114 void * value(void * key) const;
00118 void del(void * key);
00122 void delKeyNotValue(const void * key);
00126 void remove(const void * key);
00130 virtual USize hashKey(const void * key) const=0;
00134 virtual int compareKeys(const void * key1, const void * key2) const=0;
00138 virtual void deleteKey(void * key)=0;
00142 virtual void deleteValue(void * value)=0;
00143 private:
00147 skHashTable();
00151 skHashTable(const skHashTable&);
00155 skHashTable& operator=(const skHashTable&);
00159 skHashEntry * findEntry(const void * key,USize & slot) const;
00163 skHashEntry * findEntry(const void * key) const;
00168 void createSlots();
00172 skHashEntryList * m_Slots;
00176 USize m_Size;
00180 USize m_NumEntries;
00181 friend class skHashTableIterator;
00182 };
00186 class CLASSEXPORT skHashTableIterator
00187 #ifdef __SYMBIAN32__
00188 : public CBase
00189 #endif
00190 {
00191 public:
00195 virtual ~skHashTableIterator();
00200 int operator()();
00201 protected:
00205 skHashTableIterator(const skHashTable&);
00209 void * key() const;
00213 void * value() const;
00214 private:
00218 skHashTableIterator& operator=(const skHashTableIterator&);
00222 const skHashTable& m_Table;
00226 USize m_Slot;
00230 void * m_Value;
00234 void * m_Key;
00238 skHashEntryListIterator * m_ListIterator;
00239 };
00240 #define TT_PREFIX template <class TKey,class TValue>
00241
00242 const int DEFAULT_skHashTable_SIZE=3;
00246 template <class TKey,class TValue> class CLASSEXPORT skTHashTable: public skHashTable
00247 {
00248 public:
00252 skTHashTable(USize size);
00256 skTHashTable();
00260 ~skTHashTable();
00265 void insertKeyAndValue(TKey * key, TValue * value);
00269 TValue * value(const TKey * key);
00273 void del(const TKey * key);
00277 void delKeyNotValue(const TKey * key);
00281 void remove(const TKey * key);
00282
00283 protected:
00287 int compareKeys(const void * key1, const void * key2) const;
00291 void deleteKey(void * key);
00295 void deleteValue(void * value);
00299 USize hashKey(const void * key) const;
00300 };
00304 template <class TKey,class TValue> class CLASSEXPORT skTHashTableIterator: public skHashTableIterator
00305 {
00306 public:
00310 skTHashTableIterator(const skTHashTable<TKey,TValue>&);
00314 TKey * key() const;
00318 TValue * value() const;
00319 };
00320
00321 #include "skHashTable.inl"
00322
00323 #endif