00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "hashMapInfos.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 hashMapInfos::trouve ( long searchKey )
00045 {
00046 long foundKey;
00047
00048 for ( vector<infosHasher>:: 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 hashMapInfos::trouve ( string key )
00057 {
00058 long searchKey=hashValue ( key );
00059 long foundKey;;
00060
00061 for ( vector<infosHasher>:: 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 }
00069
00075 long hashMapInfos::hashValue ( string key )
00076 {
00077 locale loc;
00078 const collate<char>& coll = use_facet<collate<char> >(loc);
00079 return coll.hash(key.data(),key.data()+key.length());
00080
00081
00082 }
00088 void hashMapInfos::addHasher ( string key, vector<int> value )
00089 {
00090 if ( trouve ( hashValue ( key ) ) ==0 ) {
00091
00092 infosHasher H ( hashValue ( key ),key,value );
00093
00094
00095
00096 m_hasher.push_back ( H );
00097 }
00098 }
00099 void hashMapInfos::addValue ( string key, vector<int> value )
00100 {
00101 addHasher ( key, value );
00102 }
00103 infosHasher hashMapInfos::getHasher ( string key )
00104 {
00105 long searchKey=hashValue ( key );
00106 long foundKey;
00107
00108 for ( vector<infosHasher>:: iterator l_hasher=m_hasher.begin() ; l_hasher!=m_hasher.end() ; l_hasher++ ) {
00109 foundKey= ( *l_hasher ).getHashKey();
00110 if ( searchKey == foundKey ) {
00111 return ( *l_hasher );
00112 }
00113 }
00114 vector<int> temp;
00115 infosHasher defaut(0,"",temp);
00116 return defaut;
00117 }
00118 vector<int> hashMapInfos::getValue ( string key )
00119 {
00120 long searchKey=hashValue ( key );
00121 long foundKey;
00122 vector<int> retour;
00123
00124 for ( vector<infosHasher>:: iterator l_hasher=m_hasher.begin() ; l_hasher!=m_hasher.end() ; l_hasher++ ) {
00125 foundKey= ( *l_hasher ).getHashKey();
00126 if ( searchKey == foundKey ) {
00127
00128 return ( *l_hasher ).getValue();
00129 }
00130 }
00131 return retour;
00132 }
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 void hashMapInfos::setValue ( string key , vector<int> value )
00153 {
00154 long searchKey=hashValue ( key );
00155 long foundKey;
00156
00157 for ( vector<infosHasher>:: iterator l_hasher=m_hasher.begin() ; l_hasher!=m_hasher.end() ; l_hasher++ ) {
00158 foundKey= ( *l_hasher ).getHashKey();
00159 if ( searchKey == foundKey ) {
00160 ( *l_hasher ).setValue ( value );
00161
00162 }
00163 }
00164 }
00165 string hashMapInfos::toString ()
00166 {
00167 stringstream to_return;
00168 for ( vector<infosHasher>:: iterator l_hasher = m_hasher.begin() ; l_hasher != m_hasher.end() ; l_hasher++ ) {
00169 to_return << (*l_hasher).toString();
00170
00171 }
00172 return to_return.str();
00173 }
00174
00178 void hashMapInfos::printHash()
00179 {
00180 for ( vector<infosHasher>:: iterator l_hasher=m_hasher.begin() ; l_hasher!=m_hasher.end() ; l_hasher++ ) {
00181
00182 }
00183 }
00184
00185
00186
00187
00188
00189 }
00190