Skip to content
Snippets Groups Projects
Commit 075c627b authored by Matthew D Jones's avatar Matthew D Jones
Browse files

Re #15287 Use unordered_set for alg factory catagories

parent 4f78ddee
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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, ";",
......
......@@ -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));
......
......@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment