void IndexFactory::dropIndex(const listAlgorithmsTypePtr& algs, const std::set<std::string>& keys) { IndexAlgorithm* result = NULL; for (listAlgorithmsType::iterator i = algs->begin(); i != algs->end(); i++) { IndexAlgorithm* impl = *i; std::set<std::string> implKeys = impl->keys(); std::set<std::string>::const_iterator iKeys = keys.begin(); std::set<std::string>::const_iterator implItKeys = implKeys.begin(); while (true) { if ((iKeys != keys.end()) && (implItKeys != implKeys.end())) { std::string key1 = *iKeys; std::string key2 = *implItKeys; if (key1.compare(key2) != 0) { break; } iKeys++; implItKeys++; // get to the end of both sides and all the keys are equal if ((iKeys == keys.end()) && (implItKeys == implKeys.end())) { algs->erase(i); delete impl; break; } } } } }
IndexAlgorithm* IndexFactory::findIndex(const listAlgorithmsTypePtr& algs, const std::set<std::string>& keys) { IndexAlgorithm* result = NULL; for (listAlgorithmsType::const_iterator i = algs->begin(); i != algs->end(); i++) { IndexAlgorithm* impl = *i; std::set<std::string> implKeys = impl->keys(); std::set<std::string>::const_iterator iKeys = keys.begin(); std::set<std::string>::const_iterator implItKeys = implKeys.begin(); bool found = true; while (true) { if ((iKeys != keys.end()) && (implItKeys != implKeys.end())) { std::string key1 = *iKeys; std::string key2 = *implItKeys; if (key1.compare(key2) != 0) { found = false; break; } iKeys++; implItKeys++; // get to the end of both sides and all the keys are equal if ((iKeys == keys.end()) && (implItKeys == implKeys.end())) { break; } } else { found = false; break; } } // If all the keys match the implementation keys then this is an exact index if (found) { result = impl; break; } } return result; }