Welcome to mirror list, hosted at ThFree Co, Russian Federation.

hashMapStringInfos.cpp « TERsrc « mert - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0fbb0a98a85051c252e1b39c81cb227e80cebe8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include "hashMapStringInfos.h"

// The following class defines a hash function for strings


using namespace std;

namespace HashMapSpace
{
//     hashMapStringInfos::hashMap();
/*    hashMapStringInfos::~hashMap()
{
//       vector<stringInfosHasher>::const_iterator del = m_hasher.begin();
  for ( vector<stringInfosHasher>::const_iterator del=m_hasher.begin(); del != m_hasher.end(); del++ )
  {
    delete(*del);
  }
}*/
/**
* int hashMapStringInfos::trouve ( long searchKey )
* @param searchKey
* @return
*/
int hashMapStringInfos::trouve ( long searchKey )
{
  long foundKey;
  //       vector<stringInfosHasher>::const_iterator l_hasher=m_hasher.begin();
  for ( vector<stringInfosHasher>:: 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 hashMapStringInfos::trouve ( string key )
{
  long searchKey = hashValue ( key );
  long foundKey;;
  //       vector<stringInfosHasher>::const_iterator l_hasher=m_hasher.begin();
  for ( vector<stringInfosHasher>:: 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 hashMapStringInfos::hashValue ( string key )
* @param key
* @return
*/
long hashMapStringInfos::hashValue ( string key )
{
  locale loc;                 // the "C" locale
  const collate<char>& coll = use_facet<collate<char> > ( loc );
  return coll.hash ( key.data(), key.data() + key.length() );
// 	boost::hash<string> hasher;
// 	return hasher ( key );
}
/**
* void hashMapStringInfos::addHasher ( string key, string value )
* @param key
* @param value
*/
void hashMapStringInfos::addHasher ( string key, vector<string>  value )
{
  if ( trouve ( hashValue ( key ) ) == 0 ) {
    //         cerr << "ICI1" <<endl;
    stringInfosHasher H ( hashValue ( key ), key, value );
    //         cerr <<" "<< hashValue ( key )<<" "<< key<<" "<<value <<endl;
    //         cerr << "ICI2" <<endl;

    m_hasher.push_back ( H );
  }
}
void hashMapStringInfos::addValue ( string key, vector<string>  value )
{
  addHasher ( key, value );
}
stringInfosHasher hashMapStringInfos::getHasher ( string key )
{
  long searchKey = hashValue ( key );
  long foundKey;
  //       vector<stringInfosHasher>::const_iterator l_hasher=m_hasher.begin();
  for ( vector<stringInfosHasher>:: iterator l_hasher = m_hasher.begin() ; l_hasher != m_hasher.end() ; l_hasher++ ) {
    foundKey = ( *l_hasher ).getHashKey();
    if ( searchKey == foundKey ) {
      return ( *l_hasher );
    }
  }
  vector<string> tmp;
  stringInfosHasher defaut ( 0, "", tmp );
  return defaut;
}
vector<string> hashMapStringInfos::getValue ( string key )
{
  long searchKey = hashValue ( key );
  long foundKey;
  vector<string> retour;
  //       vector<stringInfosHasher>::const_iterator l_hasher=m_hasher.begin();
  for ( vector<stringInfosHasher>:: iterator l_hasher = m_hasher.begin() ; l_hasher != m_hasher.end() ; l_hasher++ ) {
    foundKey = ( *l_hasher ).getHashKey();
    if ( searchKey == foundKey ) {
      //         cerr <<"value found : " << key<<"|"<< ( *l_hasher ).getValue()<<endl;
      return ( *l_hasher ).getValue();
    }
  }
  return retour;
}
//     string hashMapStringInfos::searchValue ( string value )
//     {
// //       long searchKey=hashValue ( key );
// //       long foundKey;
//       vector<int> foundValue;
//
// //       vector<stringInfosHasher>::const_iterator l_hasher=m_hasher.begin();
//       for ( vector<stringInfosHasher>:: 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 hashMapStringInfos::setValue ( string key , vector<string>  value )
{
  long searchKey = hashValue ( key );
  long foundKey;
  //       vector<stringInfosHasher>::const_iterator l_hasher=m_hasher.begin();
  for ( vector<stringInfosHasher>:: iterator l_hasher = m_hasher.begin() ; l_hasher != m_hasher.end() ; l_hasher++ ) {
    foundKey = ( *l_hasher ).getHashKey();
    if ( searchKey == foundKey ) {
      ( *l_hasher ).setValue ( value );
      //           return ( *l_hasher ).getValue();
    }
  }
}


/**
*
*/
void hashMapStringInfos::printHash()
{
  for ( vector<stringInfosHasher>:: iterator l_hasher = m_hasher.begin() ; l_hasher != m_hasher.end() ; l_hasher++ ) {
    //         cout << ( *l_hasher ).getHashKey() <<" | "<< ( *l_hasher ).getKey() << " | " << ( *l_hasher ).getValue() << endl;
  }
}
vector< stringInfosHasher > hashMapStringInfos::getHashMap()
{
  return m_hasher;
}



//     long hashValue(string key){}

}