70 using ElemPtr = ElemType*;
71 using KeyType = std::vector<std::string>;
72 using KeyTypeIterator =
typename KeyType::iterator;
73 using ValueType = std::pair<int, ElemPtr>;
74 using MapType =
typename std::map<KeyType, ValueType>;
75 using MapTypeIterator =
typename std::map<KeyType, ValueType>::iterator;
76 using value_type =
typename MapType::value_type;
77 using MutableValues =
typename std::vector<int>;
83 bool add(KeyType& keys, ElemPtr elem) {
84 assert(keys.size() == SIZE);
86 return data_.insert(value_type(keys, std::make_pair(index_++, elem)))
90 bool replace(KeyType& keys, ElemPtr elem) {
91 assert(keys.size() == SIZE);
96 if (i != data_.end()) {
97 data_[keys] = std::make_pair((i->second).first, elem);
100 return data_.insert(value_type(keys, std::make_pair(index_++, elem)))
107 assert(keys.size() == SIZE);
110 i = data_.find(keys);
111 if (i != data_.end()) {
return (i->second).second; }
113 KeyType reversedKeys = keys;
114 std::reverse(reversedKeys.begin(), reversedKeys.end());
116 i = data_.find(reversedKeys);
117 if (i != data_.end()) {
118 return (i->second).second;
124 ElemPtr permutedFindSkippingFirstElement(KeyType& keys) {
125 assert(keys.size() == SIZE);
128 KeyType permutedKeys = keys;
131 KeyTypeIterator start;
132 start = permutedKeys.begin();
135 std::sort(start, permutedKeys.end());
138 i = data_.find(permutedKeys);
139 if (i != data_.end()) {
return (i->second).second; }
140 }
while (std::next_permutation(start, permutedKeys.end()));
148 ElemPtr
find(KeyType& keys,
const std::string& wildCard) {
149 assert(keys.size() == SIZE);
151 std::vector<KeyTypeIterator> iterCont;
154 std::vector<ValueType> foundTypes;
157 i = data_.find(replacedKey);
158 if (i != data_.end()) { foundTypes.push_back(i->second); }
162 KeyType reversedKeys = keys;
163 std::reverse(reversedKeys.begin(), reversedKeys.end());
166 if (reversedKeys != keys) {
172 i = data_.find(replacedKey);
173 if (i != data_.end()) { foundTypes.push_back(i->second); }
178 KeyType allWildCards(SIZE, wildCard);
179 i = data_.find(replacedKey);
180 if (i != data_.end()) { foundTypes.push_back(i->second); }
183 typename std::vector<ValueType>::iterator j;
184 j = std::min_element(foundTypes.begin(), foundTypes.end());
186 return j == foundTypes.end() ? NULL : j->second;
189 size_t size() {
return data_.size(); }
191 ElemPtr beginType(MapTypeIterator& i) {
193 return i != data_.end() ? (i->second).second : NULL;
196 ElemPtr nextType(MapTypeIterator& i) {
198 return i != data_.end() ? (i->second).second : NULL;
201 KeyType getKeys(MapTypeIterator& i) {
return i->first; }
bool replaceWithWildCard(std::vector< std::vector< std::string >::iterator > &cont, std::vector< std::string > &sequence, std::vector< std::string > &result, const std::string &wildCard)
iteratively replace the sequence with wild cards