diff --git a/Framework/API/inc/MantidAPI/AlgorithmFactory.h b/Framework/API/inc/MantidAPI/AlgorithmFactory.h index 4e35e283e1f853b1f9a356224c706d8718316ab7..c8c68b4fcb0e2f9bd9182d11d3766ca0cec7781f 100644 --- a/Framework/API/inc/MantidAPI/AlgorithmFactory.h +++ b/Framework/API/inc/MantidAPI/AlgorithmFactory.h @@ -5,7 +5,7 @@ // Includes //---------------------------------------------------------------------- #include <vector> -#include <set> +#include <unordered_set> #include <sstream> #include "MantidAPI/DllConfig.h" #include "MantidKernel/DynamicFactory.h" @@ -126,7 +126,8 @@ public: int highestVersion(const std::string &algorithmName) const; /// Get the algorithm categories - const std::set<std::string> getCategories(bool includeHidden = false) const; + const std::unordered_set<std::string> + getCategories(bool includeHidden = false) const; /// Get the algorithm categories const std::map<std::string, bool> getCategoriesWithState() const; @@ -162,7 +163,7 @@ private: /// creates an algorithm name convolved from an name and version std::string createName(const std::string &, const int &) const; /// fills a set with the hidden categories - void fillHiddenCategories(std::set<std::string> *categorySet) const; + void fillHiddenCategories(std::unordered_set<std::string> *categorySet) const; /// A typedef for the map of algorithm versions typedef std::map<std::string, int> VersionMap; diff --git a/Framework/API/src/AlgorithmFactory.cpp b/Framework/API/src/AlgorithmFactory.cpp index db39e91f5563a33f165fe249335aaefc4e6b03dc..383e4ce677fbc775a881849a2efc2949059d96cd 100644 --- a/Framework/API/src/AlgorithmFactory.cpp +++ b/Framework/API/src/AlgorithmFactory.cpp @@ -178,7 +178,7 @@ AlgorithmFactoryImpl::getKeys(bool includeHidden) const { return names; } else { // hidden categories - std::set<std::string> hiddenCategories; + std::unordered_set<std::string> hiddenCategories; fillHiddenCategories(&hiddenCategories); // strip out any algorithms names where all of the categories are hidden @@ -245,7 +245,7 @@ AlgorithmFactoryImpl::getCategoriesWithState() const { std::map<std::string, bool> resultCategories; // hidden categories - empty initially - std::set<std::string> hiddenCategories; + std::unordered_set<std::string> hiddenCategories; fillHiddenCategories(&hiddenCategories); // get all of the algorithm keys, including the hidden ones for speed purposes @@ -287,20 +287,18 @@ AlgorithmFactoryImpl::getCategoriesWithState() const { * the default is false * @returns The category strings */ -const std::set<std::string> +const std::unordered_set<std::string> AlgorithmFactoryImpl::getCategories(bool includeHidden) const { - std::set<std::string> validCategories; + std::unordered_set<std::string> validCategories; // get all of the information we need - std::map<std::string, bool> categoryMap = getCategoriesWithState(); + auto categoryMap = getCategoriesWithState(); // iterate around the map - std::map<std::string, bool>::const_iterator it_end = categoryMap.end(); - for (std::map<std::string, bool>::const_iterator it = categoryMap.begin(); - it != it_end; ++it) { - bool isHidden = (*it).second; + for (auto const &category : categoryMap) { + bool isHidden = (category).second; if (includeHidden || (!isHidden)) { - validCategories.insert((*it).first); + validCategories.insert((category).first); } } @@ -319,20 +317,18 @@ AlgorithmFactoryImpl::getCategories(bool includeHidden) const { std::vector<Algorithm_descriptor> AlgorithmFactoryImpl::getDescriptors(bool includeHidden) const { // algorithm names - std::vector<std::string> sv; - sv = getKeys(true); + auto sv = getKeys(true); // hidden categories - std::set<std::string> hiddenCategories; - if (includeHidden == false) { + std::unordered_set<std::string> hiddenCategories; + if (!includeHidden) { fillHiddenCategories(&hiddenCategories); } // results vector std::vector<Algorithm_descriptor> res; - for (std::vector<std::string>::const_iterator s = sv.begin(); s != sv.end(); - ++s) { + for (auto s = sv.cbegin(); s != sv.cend(); ++s) { if (s->empty()) continue; Algorithm_descriptor desc; @@ -348,7 +344,7 @@ AlgorithmFactoryImpl::getDescriptors(bool includeHidden) const { continue; boost::shared_ptr<IAlgorithm> alg = create(desc.name, desc.version); - std::vector<std::string> categories = alg->categories(); + auto categories = alg->categories(); desc.alias = alg->alias(); // For each category @@ -387,7 +383,7 @@ AlgorithmFactoryImpl::getDescriptors(bool includeHidden) const { } void AlgorithmFactoryImpl::fillHiddenCategories( - std::set<std::string> *categorySet) const { + std::unordered_set<std::string> *categorySet) const { std::string categoryString = Kernel::ConfigService::Instance().getString( "algorithms.categories.hidden"); Poco::StringTokenizer tokenizer(categoryString, ";", diff --git a/Framework/API/test/AlgorithmFactoryTest.h b/Framework/API/test/AlgorithmFactoryTest.h index a1b841fd2b96bd38fe346cf25dd4d05ec8582d0f..5b8554ffec077924949bcb0eee0cd6eb4e242ac5 100644 --- a/Framework/API/test/AlgorithmFactoryTest.h +++ b/Framework/API/test/AlgorithmFactoryTest.h @@ -189,7 +189,7 @@ public: void testGetCategories() { AlgorithmFactory::Instance().subscribe<CategoryAlgorithm>(); - std::set<std::string> validCategories; + std::unordered_set<std::string> validCategories; TS_ASSERT_THROWS_NOTHING( validCategories = AlgorithmFactory::Instance().getCategories(true)); diff --git a/Framework/API/test/ExperimentInfoTest.h b/Framework/API/test/ExperimentInfoTest.h index 56c7685c3c46c7f34cc93098b6c9c40ef6e973f4..4dac282c5f6c3d4ed00503575252dadb18aa8419 100644 --- a/Framework/API/test/ExperimentInfoTest.h +++ b/Framework/API/test/ExperimentInfoTest.h @@ -466,7 +466,7 @@ public: // Collect all IDF filenames and put them in a multimap where the instrument // identifier is the key std::unordered_multimap<std::string, fromToEntry> idfFiles; - std::set<std::string> idfIdentifiers; + std::unordered_set<std::string> idfIdentifiers; boost::regex regex(".*_Definition.*\\.xml", boost::regex_constants::icase); Poco::DirectoryIterator end_iter; @@ -503,8 +503,7 @@ public: std::pair<std::unordered_multimap<std::string, fromToEntry>::iterator, std::unordered_multimap<std::string, fromToEntry>::iterator> ret; - std::set<std::string>::iterator setIt; - for (setIt = idfIdentifiers.begin(); setIt != idfIdentifiers.end(); + for (auto setIt = idfIdentifiers.begin(); setIt != idfIdentifiers.end(); setIt++) { ret = idfFiles.equal_range(*setIt); for (it1 = ret.first; it1 != ret.second; ++it1) {