Main Page   Class Hierarchy   Compound List   File List   Compound Members  

hashmap.h

00001 /*
00002     Copyright (C) 2000 by Jorrit Tyberghein
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public
00015     License along with this library; if not, write to the Free
00016     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 */
00018 
00019 #ifndef __CS_HASHMAP_H__
00020 #define __CS_HASHMAP_H__
00021 
00022 #include "csutil/typedvec.h"
00023 
00024 class csHashMap;
00025 
00027 typedef uint32 csHashKey;
00029 typedef void* csHashObject;
00030 
00032 csHashKey csHashCompute(char const*);
00034 csHashKey csHashCompute(char const*, int length);
00035 
00039 struct csHashElement
00040 {
00041   csHashKey key;
00042   csHashObject object;
00043 };
00044 
00046 CS_DECLARE_TYPED_VECTOR (csHashBucket, csHashElement);
00048 CS_DECLARE_TYPED_VECTOR (csHashBucketVector, csHashBucket);
00049 
00058 class csHashIterator
00059 {
00060   friend class csHashMap;
00061 
00062 private:
00064   csHashBucket* bucket;
00066   int element_index;
00068   uint32 bucket_index;
00070   bool do_iterate_key;
00072   csHashKey key;
00074   csHashMap* hash;
00075 
00076 private:
00078   void GotoNextSameKey ();
00080   void GotoNextElement ();
00081 
00082 public:
00083 
00089   csHashIterator (csHashMap* hash);
00095   csHashIterator (csHashMap* hash, csHashKey Key);
00096 
00098   bool HasNext ();
00100   csHashObject Next ();
00105   void DeleteNext ();
00106 };
00107 
00114 class csHashMap
00115 {
00116   friend class csHashIterator;
00117 
00118 private:
00120   csHashBucketVector Buckets;
00122   uint32 NumBuckets;
00123 
00124 public:
00135   csHashMap (uint32 size = 211);
00136 
00141   virtual ~csHashMap ();
00142 
00146   void Put (csHashKey key, csHashObject object);
00147 
00155   csHashObject Get (csHashKey key) const;
00156 
00160   void DeleteAll (csHashKey key);
00161 
00165   void DeleteAll ();
00166 };
00167 
00173 class csHashSet
00174 {
00175 private:
00176   csHashMap map;
00177 
00178 public:
00183   csHashSet (uint32 size = 211);
00184 
00189   void Add (csHashObject object);
00190 
00197   void AddNoTest (csHashObject object);
00198 
00202   bool In (csHashObject object);
00203 
00207   void DeleteAll ();
00208 
00214   void Delete (csHashObject object);
00215 
00217   inline csHashMap *GetHashMap () {return ↦}
00218 };
00219 
00220 #endif //__CS_HASHMAP_H__
00221 

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000