| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | #include "hashMap.h" |
| |
|
| | |
| |
|
| |
|
| | using namespace std; |
| |
|
| | namespace TERCPPNS_HashMapSpace |
| | { |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | int hashMap::trouve ( long searchKey ) |
| | { |
| | long foundKey; |
| | |
| | for ( vector<stringHasher>:: iterator l_hasher=m_hasher.begin() ; l_hasher!=m_hasher.end() ; l_hasher++ ) { |
| | foundKey= ( *l_hasher ).getHashKey(); |
| | if ( searchKey == foundKey ) { |
| | return 1; |
| | } |
| | } |
| | return 0; |
| | } |
| | int hashMap::trouve ( string key ) |
| | { |
| | long searchKey=hashValue ( key ); |
| | long foundKey;; |
| | |
| | for ( vector<stringHasher>:: iterator l_hasher=m_hasher.begin() ; l_hasher!=m_hasher.end() ; l_hasher++ ) { |
| | foundKey= ( *l_hasher ).getHashKey(); |
| | if ( searchKey == foundKey ) { |
| | return 1; |
| | } |
| | } |
| | return 0; |
| | } |
| | |
| | |
| | |
| | |
| | |
| | long hashMap::hashValue ( string key ) |
| | { |
| | locale loc; |
| | const collate<char>& coll = use_facet<collate<char> >(loc); |
| | return coll.hash(key.data(),key.data()+key.length()); |
| | |
| | |
| | } |
| | |
| | |
| | |
| | |
| | |
| | void hashMap::addHasher ( string key, string value ) |
| | { |
| | if ( trouve ( hashValue ( key ) ) ==0 ) { |
| | |
| | stringHasher H ( hashValue ( key ),key,value ); |
| | |
| | |
| |
|
| | m_hasher.push_back ( H ); |
| | } |
| | } |
| | stringHasher hashMap::getHasher ( string key ) |
| | { |
| | long searchKey=hashValue ( key ); |
| | long foundKey; |
| | stringHasher defaut(0,"",""); |
| | |
| | for ( vector<stringHasher>:: iterator l_hasher=m_hasher.begin() ; l_hasher!=m_hasher.end() ; l_hasher++ ) { |
| | foundKey= ( *l_hasher ).getHashKey(); |
| | if ( searchKey == foundKey ) { |
| | return ( *l_hasher ); |
| | } |
| | } |
| | return defaut; |
| | } |
| | string hashMap::getValue ( string key ) |
| | { |
| | long searchKey=hashValue ( key ); |
| | long foundKey; |
| | |
| | for ( vector<stringHasher>:: iterator l_hasher=m_hasher.begin() ; l_hasher!=m_hasher.end() ; l_hasher++ ) { |
| | foundKey= ( *l_hasher ).getHashKey(); |
| | if ( searchKey == foundKey ) { |
| | |
| | return ( *l_hasher ).getValue(); |
| | } |
| | } |
| | return ""; |
| | } |
| | string hashMap::searchValue ( string value ) |
| | { |
| | |
| | |
| | string foundValue; |
| |
|
| | |
| | for ( vector<stringHasher>:: iterator l_hasher=m_hasher.begin() ; l_hasher!=m_hasher.end() ; l_hasher++ ) { |
| | foundValue= ( *l_hasher ).getValue(); |
| | if ( foundValue.compare ( value ) == 0 ) { |
| | return ( *l_hasher ).getKey(); |
| | } |
| | } |
| | return ""; |
| | } |
| |
|
| |
|
| | void hashMap::setValue ( string key , string value ) |
| | { |
| | long searchKey=hashValue ( key ); |
| | long foundKey; |
| | |
| | for ( vector<stringHasher>:: iterator l_hasher=m_hasher.begin() ; l_hasher!=m_hasher.end() ; l_hasher++ ) { |
| | foundKey= ( *l_hasher ).getHashKey(); |
| | if ( searchKey == foundKey ) { |
| | ( *l_hasher ).setValue ( value ); |
| | |
| | } |
| | } |
| | } |
| |
|
| |
|
| | |
| | |
| | |
| | void hashMap::printHash() |
| | { |
| | for ( vector<stringHasher>:: iterator l_hasher=m_hasher.begin() ; l_hasher!=m_hasher.end() ; l_hasher++ ) { |
| | cout << ( *l_hasher ).getHashKey() <<" | "<< ( *l_hasher ).getKey() << " | " << ( *l_hasher ).getValue() << endl; |
| | } |
| | } |
| |
|
| |
|
| |
|
| | |
| |
|
| | } |
| |
|
| |
|