00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "hashMap.h"
00022
00023
00024
00025
00026 using namespace std;
00027
00028 namespace TERCPPNS_HashMapSpace
00029 {
00030
00031
00032
00033
00034
00035
00036
00037
00038
00044 int hashMap::trouve ( long searchKey )
00045 {
00046 long foundKey;
00047
00048 for ( vector<stringHasher>:: iterator l_hasher=m_hasher.begin() ; l_hasher!=m_hasher.end() ; l_hasher++ ) {
00049 foundKey= ( *l_hasher ).getHashKey();
00050 if ( searchKey == foundKey ) {
00051 return 1;
00052 }
00053 }
00054 return 0;
00055 }
00056 int hashMap::trouve ( string key )
00057 {
00058 long searchKey=hashValue ( key );
00059 long foundKey;;
00060
00061 for ( vector<stringHasher>:: iterator l_hasher=m_hasher.begin() ; l_hasher!=m_hasher.end() ; l_hasher++ ) {
00062 foundKey= ( *l_hasher ).getHashKey();
00063 if ( searchKey == foundKey ) {
00064 return 1;
00065 }
00066 }
00067 return 0;
00068 }
00074 long hashMap::hashValue ( string key )
00075 {
00076 locale loc;
00077 const collate<char>& coll = use_facet<collate<char> >(loc);
00078 return coll.hash(key.data(),key.data()+key.length());
00079
00080
00081 }
00087 void hashMap::addHasher ( string key, string value )
00088 {
00089 if ( trouve ( hashValue ( key ) ) ==0 ) {
00090
00091 stringHasher H ( hashValue ( key ),key,value );
00092
00093
00094
00095 m_hasher.push_back ( H );
00096 }
00097 }
00098 stringHasher hashMap::getHasher ( string key )
00099 {
00100 long searchKey=hashValue ( key );
00101 long foundKey;
00102 stringHasher defaut(0,"","");
00103
00104 for ( vector<stringHasher>:: iterator l_hasher=m_hasher.begin() ; l_hasher!=m_hasher.end() ; l_hasher++ ) {
00105 foundKey= ( *l_hasher ).getHashKey();
00106 if ( searchKey == foundKey ) {
00107 return ( *l_hasher );
00108 }
00109 }
00110 return defaut;
00111 }
00112 string hashMap::getValue ( string key )
00113 {
00114 long searchKey=hashValue ( key );
00115 long foundKey;
00116
00117 for ( vector<stringHasher>:: iterator l_hasher=m_hasher.begin() ; l_hasher!=m_hasher.end() ; l_hasher++ ) {
00118 foundKey= ( *l_hasher ).getHashKey();
00119 if ( searchKey == foundKey ) {
00120
00121 return ( *l_hasher ).getValue();
00122 }
00123 }
00124 return "";
00125 }
00126 string hashMap::searchValue ( string value )
00127 {
00128
00129
00130 string foundValue;
00131
00132
00133 for ( vector<stringHasher>:: iterator l_hasher=m_hasher.begin() ; l_hasher!=m_hasher.end() ; l_hasher++ ) {
00134 foundValue= ( *l_hasher ).getValue();
00135 if ( foundValue.compare ( value ) == 0 ) {
00136 return ( *l_hasher ).getKey();
00137 }
00138 }
00139 return "";
00140 }
00141
00142
00143 void hashMap::setValue ( string key , string value )
00144 {
00145 long searchKey=hashValue ( key );
00146 long foundKey;
00147
00148 for ( vector<stringHasher>:: iterator l_hasher=m_hasher.begin() ; l_hasher!=m_hasher.end() ; l_hasher++ ) {
00149 foundKey= ( *l_hasher ).getHashKey();
00150 if ( searchKey == foundKey ) {
00151 ( *l_hasher ).setValue ( value );
00152
00153 }
00154 }
00155 }
00156
00157
00161 void hashMap::printHash()
00162 {
00163 for ( vector<stringHasher>:: iterator l_hasher=m_hasher.begin() ; l_hasher!=m_hasher.end() ; l_hasher++ ) {
00164 cout << ( *l_hasher ).getHashKey() <<" | "<< ( *l_hasher ).getKey() << " | " << ( *l_hasher ).getValue() << endl;
00165 }
00166 }
00167
00168
00169
00170
00171
00172 }
00173