|
hashmap.h00001 /* 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 csHashMapReversible; 00025 class csHashIteratorReversible; 00026 00027 class csHashMap; 00028 00030 typedef uint32 csHashKey; 00032 typedef void* csHashObject; 00033 00035 csHashKey csHashCompute(char const*); 00037 csHashKey csHashCompute(char const*, int length); 00038 00042 struct csHashElement 00043 { 00044 csHashKey key; 00045 csHashObject object; 00046 }; 00047 00049 CS_DECLARE_TYPED_VECTOR (csHashBucket, csHashElement); 00051 CS_DECLARE_TYPED_VECTOR (csHashBucketVector, csHashBucket); 00052 00061 class csHashIterator 00062 { 00063 friend class csHashMap; 00064 friend class csHashIteratorReversible; 00065 00066 private: 00068 csHashBucket* bucket; 00070 int element_index; 00072 uint32 bucket_index; 00074 bool do_iterate_key; 00076 csHashKey key; 00078 csHashMap* hash; 00079 00080 private: 00082 void GotoNextSameKey (); 00084 void GotoNextElement (); 00085 00086 public: 00087 00093 csHashIterator (csHashMap* hash); 00099 csHashIterator (csHashMap* hash, csHashKey Key); 00100 00102 bool HasNext (); 00104 csHashObject Next (); 00109 void DeleteNext (); 00110 }; 00111 00118 class csHashMap 00119 { 00120 friend class csHashIterator; 00121 friend class csHashMapReversible; 00122 00123 private: 00125 csHashBucketVector Buckets; 00127 uint32 NumBuckets; 00128 00129 public: 00140 csHashMap (uint32 size = 211); 00141 00146 virtual ~csHashMap (); 00147 00151 void Put (csHashKey key, csHashObject object); 00152 00160 csHashObject Get (csHashKey key) const; 00161 00165 void DeleteAll (csHashKey key); 00166 00170 void DeleteAll (); 00171 }; 00172 00178 class csHashSet 00179 { 00180 private: 00181 csHashMap map; 00182 00183 public: 00188 csHashSet (uint32 size = 211); 00189 00194 void Add (csHashObject object); 00195 00202 void AddNoTest (csHashObject object); 00203 00207 bool In (csHashObject object); 00208 00212 void DeleteAll (); 00213 00219 void Delete (csHashObject object); 00220 00222 inline csHashMap *GetHashMap () {return ↦} 00223 }; 00224 00225 #endif //__CS_HASHMAP_H__ 00226 Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000 |