00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00028 #include "vtkAbstractMap.h"
00029 #include "vtkWindows.h"
00030 #ifndef __vtkHashMap_h
00031 #define __vtkHashMap_h
00032
00033 template<class DataType> class vtkVector;
00034 template<class KeyType, class DataType> class vtkHashMapIterator;
00035
00036 template<class KeyType, class DataType>
00037 class vtkHashMap : public vtkAbstractMap<KeyType,DataType>
00038 {
00039 friend class vtkHashMapIterator<KeyType,DataType>;
00040 virtual const char* GetClassNameInternal() const {return "vtkHashMap";}
00041 public:
00042 typedef vtkAbstractMap<KeyType,DataType> Superclass;
00043 typedef vtkHashMapIterator<KeyType,DataType> IteratorType;
00044
00045
00046
00047
00048
00049 void PrintSelf(ostream& os, vtkIndent indent);
00050 static vtkHashMap<KeyType,DataType>* New();
00051
00054 vtkHashMapIterator<KeyType,DataType>* NewIterator();
00055
00059 int SetItem(const KeyType& key, const DataType& data);
00060
00063 int RemoveItem(const KeyType& key);
00064
00066 void RemoveAllItems();
00067
00070 int GetItem(const KeyType& key, DataType& data);
00071
00073 vtkIdType GetNumberOfItems() const;
00074
00076
00080 void SetMaximumLoadFactor(float factor);
00081 float GetMaximumLoadFactor() const;
00083
00085
00088 void SetNumberOfBuckets(vtkIdType n);
00089 vtkIdType GetNumberOfBuckets() const;
00091
00092 protected:
00093 vtkHashMap();
00094 virtual ~vtkHashMap();
00095
00096 typedef vtkAbstractMapItem<KeyType,DataType> ItemType;
00097 typedef vtkVector<ItemType> BucketType;
00098
00099
00100
00101 void CheckLoadFactor();
00102
00103
00104
00105 void RehashItems(vtkIdType newNumberOfBuckets);
00106
00108 vtkIdType HashKey(const KeyType& key, vtkIdType nbuckets);
00109
00110 float MaximumLoadFactor;
00111 vtkIdType NumberOfItems;
00112 vtkIdType NumberOfBuckets;
00113 BucketType** Buckets;
00114
00115 private:
00116 vtkHashMap(const vtkHashMap<KeyType,DataType>&);
00117 void operator=(const vtkHashMap<KeyType,DataType>&);
00118 };
00119
00120 static inline unsigned long vtkHashMapHashMethod(int x)
00121 { return static_cast<unsigned long>(x); }
00122 static inline unsigned long vtkHashMapHashMethod(const char* s)
00123 {
00124 unsigned long h = 0;
00125 for(;*s;++s)
00126 {
00127 h = 5*h + *s;
00128 }
00129 return h;
00130 }
00131
00132 static inline unsigned long vtkHashMapHashMethod(vtkObjectBase* o)
00133 {
00134 #if defined ( _MSC_VER )
00135 return PtrToUlong(o);
00136 #else
00137 return reinterpret_cast<unsigned long>(o);
00138 #endif
00139 }
00140
00141 #ifdef VTK_NO_EXPLICIT_TEMPLATE_INSTANTIATION
00142 #include "vtkHashMap.txx"
00143 #endif
00144
00145 #endif
00146
00147
00148