00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef __hash_fn_h
00017 #define __hash_fn_h
00018
00019 #include "BasicArray.h"
00020 #include "CharString.h"
00021
00022
00023
00024
00025 typedef unsigned long int ub4;
00026 typedef unsigned char ub1;
00027 ub4 bjlookup( register ub1* k, register ub4 length, register ub4 level);
00028
00029
00030
00032
00033 {return bjlookup((ub1*)&val,sizeof(double),level);}
00035 inline unsigned long int hash_bj(const int& val, unsigned long int level=0)
00036 {return bjlookup((ub1*)&val,sizeof(int),level);}
00038 inline unsigned long int hash_bj(const BasicArray<int>& array,
00039 unsigned long int level=0)
00040 {return bjlookup((ub1*)(array.data()),array.size()*sizeof(int),level);}
00042 inline unsigned long int hash_bj(const int* array, const int arraylen,
00043 unsigned long int level=0)
00044 {return bjlookup((ub1*)(array),arraylen*sizeof(int),level);}
00046 inline unsigned long int hash_bj(const BasicArray<double>& array,
00047 unsigned long int level=0)
00048 {return bjlookup((ub1*)(array.data()),array.size()*sizeof(double),level);}
00050 inline unsigned long int hash_bj(const double* array, const int arraylen,
00051 unsigned long int level=0)
00052 {return bjlookup((ub1*)(array),arraylen*sizeof(double),level);}
00053
00054
00055
00057 template <class T>
00058 size_type hash_fn(const T& key, size_type table_size)
00059 {return key.hash(table_size);}
00060 template<class T>
00061 inline size_type hash_fn(const SimpleArray<T>& key, size_type table_size)
00062 {return hash_fn1(*((const BasicArray<T>*)&key),table_size);}
00063
00064
00065
00066
00067
00068
00069 size_type hash_fn1(const CharString& key, size_type table_size);
00070 size_type hash_fn2(const CharString& key, size_type table_size);
00071 size_type hash_fn3(const CharString& key, size_type table_size);
00072 template<>
00073 inline size_type hash_fn(const CharString& key, size_type table_size)
00074 {return hash_fn3(key,table_size);}
00075
00076
00077
00078
00079
00080 size_type hash_fn1(const int& key, size_type table_size);
00081 inline size_type hash_fn2(const int& key, size_type table_size)
00082 {return hash_bj(key) % table_size;}
00083 template<>
00084 inline size_type hash_fn(const int& key, size_type table_size)
00085 {return hash_fn2(key,table_size);}
00086
00087
00088
00089
00090
00091 size_type hash_fn1(const double& key, size_type table_size);
00092 inline size_type hash_fn2(const double& key, size_type table_size)
00093 {return hash_bj(key) % table_size;}
00094 template<>
00095 inline size_type hash_fn(const double& key, size_type table_size)
00096 {return hash_fn2(key,table_size);}
00097
00098
00099
00100
00101
00102 size_type hash_fn1(const BasicArray<int>& key, size_type table_size);
00103 inline size_type hash_fn2(const BasicArray<int>& key, size_type table_size)
00104 {return hash_bj(key) % table_size;}
00105 template<>
00106 inline size_type hash_fn(const BasicArray<int>& key, size_type table_size)
00107 {return hash_fn2(key,table_size);}
00108
00109
00110
00111
00112
00113 size_type hash_fn1(const BasicArray<double>& key, size_type table_size);
00114 size_type hash_fn2(const BasicArray<double>& key, size_type table_size);
00115 inline size_type hash_fn3(const BasicArray<double>& key, size_type table_size)
00116 {return hash_bj(key) % table_size;}
00117 template<>
00118 inline size_type hash_fn(const BasicArray<double>& key, size_type table_size)
00119 {return hash_fn3(key,table_size);}
00120
00121
00122
00123
00124 inline size_type hash_fn1(const SimpleArray<double>& key, size_type table_size)
00125 {return hash_fn1(*((const BasicArray<double>*)&key),table_size);}
00126 inline size_type hash_fn2(const SimpleArray<double>& key, size_type table_size)
00127 {return hash_fn2(*((const BasicArray<double>*)&key),table_size);}
00128 inline size_type hash_fn3(const SimpleArray<double>& key, size_type table_size)
00129 {return hash_fn3(*((const BasicArray<double>*)&key),table_size);}
00130 template<>
00131 inline size_type hash_fn(const SimpleArray<double>& key, size_type table_size)
00132 {return hash_fn3(*((const BasicArray<double>*)&key),table_size);}
00133
00134
00135
00136
00137 inline size_type hash_fn1(const SimpleArray<int>& key, size_type table_size)
00138 {return hash_fn1(*((const BasicArray<int>*)&key),table_size);}
00139 inline size_type hash_fn2(const SimpleArray<int>& key, size_type table_size)
00140 {return hash_fn2(*((const BasicArray<int>*)&key),table_size);}
00141 template<>
00142 inline size_type hash_fn(const SimpleArray<int>& key, size_type table_size)
00143 {return hash_fn2(*((const BasicArray<int>*)&key),table_size);}
00144
00145 #endif