00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef HASH_H
00016 #define HASH_H
00017
00018 #include <stddef.h>
00019 #include <vector>
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 using namespace std;
00031
00032 template <class H, class T> class hashVector : public vector<T>
00033 {
00034 public:
00035
00036 hashVector(size_t max, size_t (*f)(const H &));
00037 hashVector(size_t max, size_t (*f)(const H &), T & initialValue);
00038 hashVector(const hashVector<H, T> & v);
00039
00040
00041 T & operator [] (const H & index);
00042 const T & operator [] (const H & index) const;
00043
00044 private:
00045
00046 size_t (*hashfun)(const H &);
00047 };
00048
00049
00050
00051
00052
00053 template <class H, class T>
00054 inline hashVector<H, T>::hashVector(size_t max, size_t (*f)(const H &))
00055 : vector<T>(max), hashfun(f)
00056 {
00057
00058 }
00059
00060
00061
00062 template <class H, class T>
00063 inline hashVector<H, T>::hashVector(size_t max, size_t (*f)(const H&), T& initialValue)
00064 : vector<T>(max, initialValue), hashfun(f)
00065 {
00066
00067 }
00068
00069
00070
00071 template <class H, class T>
00072 inline hashVector<H, T>::hashVector(const hashVector<H,T> & v)
00073 : vector<T>(v), hashfun(v.hashfun)
00074 {
00075
00076 }
00077
00078
00079
00080 template <class H, class T>
00081 inline T & hashVector<H, T>::operator[] (const H & index)
00082 {
00083
00084
00085 return vector<T>::operator[] ((*hashfun)(index) % size());
00086 }
00087
00088
00089 template <class H, class T>
00090 inline const T & hashVector<H, T>::operator[] (const H & index) const
00091 {
00092
00093
00094 return vector<T>::operator[] ((*hashfun)(index) % size());
00095 }
00096
00097
00098
00099
00100
00101 #endif