Commit 7b0c71e8 authored by Matthew D Jones's avatar Matthew D Jones
Browse files

Re #15287 Replace std::set with std::unordered_set

parent ed83c290
......@@ -10,7 +10,7 @@
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
namespace Mantid {
namespace API {
......@@ -56,7 +56,7 @@ public:
Expression(const std::vector<std::string> &ops);
/// contructor
Expression(const std::vector<std::string> &binary,
const std::set<std::string> &unary);
const std::unordered_set<std::string> &unary);
/// copy contructor
Expression(const Expression &expr);
/// Assignment operator
......@@ -104,7 +104,7 @@ public:
/// This method returns first sub-expression without brackets
const Expression &bracketsRemoved() const;
/// Return a list of all variable names in this expression
std::set<std::string> getVariables() const;
std::unordered_set<std::string> getVariables() const;
/**
* Rename all variables with a given name
* @param oldName :: The old name
......@@ -192,10 +192,10 @@ private:
struct Operators {
std::vector<std::string>
binary; ///< Binary operators in reverse precedence order
std::set<std::string> unary; ///< Unary operators
std::unordered_set<std::string> unary; ///< Unary operators
std::map<std::string, size_t>
precedence; ///< Map of the operator precedence order
std::set<char>
std::unordered_set<char>
symbols; ///< All the symbols that are used in the binary operators
std::map<std::string, char> op_number; ///< map of operators
};
......@@ -215,7 +215,7 @@ private:
* Adds new unary operators to the expression
* @param ops :: A vector with unary operators
*/
void add_unary(const std::set<std::string> &ops);
void add_unary(const std::unordered_set<std::string> &ops);
/**
* Check if a string is a unary operator
* @param op :: The string to check
......
......@@ -24,7 +24,7 @@ Expression::Expression() {
add_operators(ops);
// Define unary operators
std::set<std::string> unary;
std::unordered_set<std::string> unary;
unary.insert("+");
unary.insert("-");
......@@ -39,7 +39,7 @@ Expression::Expression(const std::vector<std::string> &ops) {
/// contructor
Expression::Expression(const std::vector<std::string> &binary,
const std::set<std::string> &unary) {
const std::unordered_set<std::string> &unary) {
m_operators.reset(new Operators());
add_operators(binary);
add_unary(unary);
......@@ -86,7 +86,7 @@ void Expression::add_operators(const std::vector<std::string> &ops) {
}
}
void Expression::add_unary(const std::set<std::string> &ops) {
void Expression::add_unary(const std::unordered_set<std::string> &ops) {
m_operators->unary = ops;
for (const auto &op : ops) {
m_operators->symbols.insert(op.cbegin(), op.cend());
......@@ -479,8 +479,8 @@ const Expression &Expression::bracketsRemoved() const {
/**
* Return a list of all variable names in this expression
*/
std::set<std::string> Expression::getVariables() const {
std::set<std::string> out;
std::unordered_set<std::string> Expression::getVariables() const {
std::unordered_set<std::string> out;
if (!isFunct()) {
std::string s = name();
if (!s.empty() && !isdigit(s[0])) {
......@@ -489,7 +489,7 @@ std::set<std::string> Expression::getVariables() const {
} else {
for (const auto &e : *this) {
if (e.isFunct()) {
std::set<std::string> tout = e.getVariables();
std::unordered_set<std::string> tout = e.getVariables();
out.insert(tout.begin(), tout.end());
} else {
std::string s = e.name();
......
......@@ -171,7 +171,7 @@ public:
TS_ASSERT_EQUALS(e4[1].name(), "+");
std::vector<std::string> bin_ops{"="};
std::set<std::string> un_ops{"!", "%%"};
std::unordered_set<std::string> un_ops{"!", "%%"};
Expression e5(bin_ops, un_ops);
TS_ASSERT_THROWS_NOTHING(e5.parse("x=!1"));
......@@ -206,7 +206,7 @@ public:
TS_ASSERT_EQUALS(e8[1].name(), "%%");
std::vector<std::string> bin_ops1{"=="};
std::set<std::string> un_ops1{"!", "%%"};
std::unordered_set<std::string> un_ops1{"!", "%%"};
Expression e9(bin_ops1, un_ops1);
TS_ASSERT_THROWS_NOTHING(e9.parse("x==!1"));
......@@ -247,7 +247,7 @@ public:
TS_ASSERT_THROWS(e14.parse("x==%% "), std::runtime_error);
std::vector<std::string> bin_ops2{"-", "--"};
std::set<std::string> un_ops2{"-", "--"};
std::unordered_set<std::string> un_ops2{"-", "--"};
Expression e15(bin_ops2, un_ops2);
TS_ASSERT_THROWS_NOTHING(e15.parse("x--1"));
......@@ -339,7 +339,7 @@ public:
void testGetVariables() {
Expression e;
e.parse("a+b*sin(x)*fun1(fun2(a+c))");
std::set<std::string> vars = e.getVariables();
std::unordered_set<std::string> vars = e.getVariables();
TS_ASSERT_EQUALS(vars.size(), 4);
TS_ASSERT(vars.find("a") != vars.end());
TS_ASSERT(vars.find("b") != vars.end());
......
......@@ -14,6 +14,7 @@
#include <boost/assign/list_of.hpp>
#include <boost/algorithm/string/join.hpp>
#include <unordered_set>
using namespace Mantid;
using namespace Mantid::API;
......@@ -46,11 +47,10 @@ std::string createAbsoluteDirectory(const std::string &dirPath) {
* @param filenames :: the names of the files to create.
* @param dirPath :: the directory in which to create the files.
*/
void createFilesInDirectory(const std::set<std::string> &filenames,
void createFilesInDirectory(const std::unordered_set<std::string> &filenames,
const std::string &dirPath) {
for (auto filename = filenames.begin(); filename != filenames.end();
++filename) {
Poco::File file(dirPath + "/" + *filename);
for (const auto &filename : filenames) {
Poco::File file(dirPath + "/" + filename);
file.createFile();
}
}
......@@ -74,7 +74,7 @@ private:
std::string m_oldDefaultInstrument;
std::string m_dummyFilesDir;
std::string m_dirWithWhitespace;
std::set<std::string> m_tempDirs;
std::unordered_set<std::string> m_tempDirs;
std::vector<std::string> m_exts;
Mantid::Kernel::ConfigServiceImpl &g_config;
......@@ -105,7 +105,7 @@ public:
m_tempDirs.insert(m_dummyFilesDir);
m_tempDirs.insert(m_dirWithWhitespace);
std::set<std::string> dummyFilenames = boost::assign::list_of
std::unordered_set<std::string> dummyFilenames = boost::assign::list_of
// Standard raw file runs.
("TSC00001.raw")("TSC00002.raw")("TSC00003.raw")("TSC00004.raw")(
"TSC00005.raw")
......@@ -132,7 +132,7 @@ public:
// when multifileloading is turned off via the preferences file.
("_test_multiFileLoadingSwitchedOff_tempFileWithA+AndA,InTheName.txt");
std::set<std::string> whiteSpaceDirFilenames =
std::unordered_set<std::string> whiteSpaceDirFilenames =
boost::assign::list_of("file with whitespace.txt");
createFilesInDirectory(dummyFilenames, m_dummyFilesDir);
......@@ -146,9 +146,8 @@ public:
*/
~MultipleFilePropertyTest() {
// Remove temp dirs.
for (auto tempDir = m_tempDirs.begin(); tempDir != m_tempDirs.end();
++tempDir) {
Poco::File dir(*tempDir);
for (const auto &tempDir : m_tempDirs) {
Poco::File dir(tempDir);
dir.remove(true);
}
}
......
......@@ -102,7 +102,6 @@ void SaveMask::exec() {
const auto detids = spec->getDetectorIDs();
// b) get detector id & Store
detid_t detid;
for (const auto &det_id : detids) {
// c) store
detid0s.push_back(det_id);
......
......@@ -215,8 +215,8 @@ void UserFunctionDialog::checkParameters(QString& expr)
{
return;
}
std::set<std::string> vars1 = e1.getVariables();
std::set<std::string> vars2 = e2.getVariables();
auto vars1 = e1.getVariables();
auto vars2 = e2.getVariables();
vars1.erase("x");
vars2.erase("x");
......@@ -278,10 +278,10 @@ void UserFunctionDialog::updateFunction()
m_uiForm.leParams->setText("");
return;
}
std::set<std::string> vars = e.getVariables();
auto vars = e.getVariables();
vars.erase("x");
QString params;
for(std::set<std::string>::iterator it=vars.begin();it!=vars.end();++it)
for(auto it=vars.begin();it!=vars.end();++it)
{
if (it != vars.begin())
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment