Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

skHashTable.h

00001 /*
00002   Copyright 1996-2003
00003   Simon Whiteside
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Lesser General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public
00016     License along with this library; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019   $Id: skHashTable_8h-source.html,v 1.17 2004/12/17 21:31:14 sdw Exp $
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

Generated on Fri Dec 17 20:27:34 2004 for Simkin by doxygen1.3