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.5 2003/01/23 15:31:03 simkin_cvs 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 
00057 class   CLASSEXPORT skHashTable 
00058 {
00059  public:
00063   void clear();
00067   void clearAndDestroyKeys();
00071   void clearAndDestroyValues();
00075   void clearAndDestroy();
00079   USize entries() const;
00083   virtual ~skHashTable();
00084  protected:
00088   skHashTable(USize  size);
00092   void insertKeyAndValue(void * key, void * value);
00096   void *  value(void * key) const;
00100   void del(void * key);
00104   void delKeyNotValue(const void * key);
00108   void remove(const void * key);
00112   virtual USize hashKey(const void * key) const=0;
00116   virtual int compareKeys(const void * key1, const void * key2) const=0;
00120   virtual void deleteKey(void * key)=0; 
00124   virtual void deleteValue(void * value)=0;
00125  private:
00129   skHashTable();
00133   skHashTable(const skHashTable&);
00137   skHashTable& operator=(const skHashTable&);
00141   skHashEntry * findEntry(const void * key,USize & slot) const;
00145   skHashEntry * findEntry(const void * key) const;
00149   skHashEntryList * m_Slots;
00153   USize m_Size;
00157   USize m_NumEntries;
00158   friend class skHashTableIterator;
00159 };
00163 class  CLASSEXPORT skHashTableIterator
00164 {
00165  public:
00169   virtual ~skHashTableIterator();
00173   int operator()();
00174  protected:
00178   skHashTableIterator(const skHashTable&);
00182   void * key() const; 
00186   void * value() const;
00187  private:
00191   skHashTableIterator& operator=(const skHashTableIterator&);
00195   const skHashTable&    m_Table;
00199   USize  m_Slot;
00203   void * m_Value;
00207   void * m_Key;
00211   skHashEntryListIterator * m_ListIterator;
00212 };
00213 #define TT_PREFIX template <class TKey,class TValue> 
00214 
00215 const int DEFAULT_skHashTable_SIZE=3;
00219 template <class TKey,class TValue>  class  CLASSEXPORT skTHashTable: public skHashTable
00220 {
00221  public:
00225   skTHashTable(USize  size);
00229   skTHashTable();
00233   ~skTHashTable();
00237   void insertKeyAndValue(TKey * key, TValue * value);
00241   TValue * value(const TKey * key);
00245   void del(const TKey * key);
00249   void delKeyNotValue(const TKey * key);
00253   void remove(const TKey * key);
00254     
00255  protected:
00259   int compareKeys(const void * key1, const void * key2) const;
00263   void deleteKey(void * key);
00267   void deleteValue(void * value);
00271   USize hashKey(const void * key) const;
00272 };
00276 template <class TKey,class TValue>  class CLASSEXPORT skTHashTableIterator: public skHashTableIterator
00277 {
00278  public:
00282   skTHashTableIterator(const skTHashTable<TKey,TValue>&);
00286   TKey * key() const;
00290   TValue * value() const;
00291 };
00292 
00293 #include "skHashTable.inl"
00294 
00295 #endif

Generated on Thu Jan 23 15:25:38 2003 for Simkin by doxygen1.3-rc1