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