Skip to content

Commit

Permalink
Use unordered_map and unordered_set with strings
Browse files Browse the repository at this point in the history
  • Loading branch information
fintarin committed Feb 5, 2024
1 parent f3f4dd4 commit bd0091e
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/fintamath/expressions/binary/CompExpression.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "fintamath/expressions/binary/CompExpression.hpp"

#include <functional>
#include <map>
#include <memory>
#include <ranges>
#include <string>
#include <unordered_map>
#include <utility>

#include "fintamath/core/CoreUtils.hpp"
Expand Down Expand Up @@ -111,7 +111,7 @@ void CompExpression::markAsSolution() {
}

std::shared_ptr<IFunction> CompExpression::getOppositeFunction(const IFunction &function) {
static const std::map<std::string, std::shared_ptr<IFunction>, std::less<>> oppositeFunctions = {
static const std::unordered_map<std::string, std::shared_ptr<IFunction>> oppositeFunctions = {
{Eqv{}.toString(), std::make_shared<Eqv>()},
{Neqv{}.toString(), std::make_shared<Neqv>()},
{More{}.toString(), std::make_shared<Less>()},
Expand Down
4 changes: 2 additions & 2 deletions src/fintamath/expressions/binary/DivExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <cstddef>
#include <functional>
#include <ranges>
#include <set>
#include <string>
#include <unordered_set>
#include <utility>

#include "fintamath/core/CoreUtils.hpp"
Expand Down Expand Up @@ -584,7 +584,7 @@ ArgumentPtr DivExpression::secCscSimplify(const IFunction & /*func*/, const Argu
}

bool DivExpression::containsDivTrigFunction(const ArgumentPtr &arg) {
static const std::set<std::string, std::less<>> functionStrings = {
static const std::unordered_set<std::string> functionStrings = {
Tan{}.toString(),
Cot{}.toString(),
Sec{}.toString(),
Expand Down
4 changes: 2 additions & 2 deletions src/fintamath/expressions/unary/FloorCeilExpression.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "fintamath/expressions/unary/FloorCeilExpression.hpp"

#include <functional>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>

#include "fintamath/core/CoreUtils.hpp"
Expand Down Expand Up @@ -55,7 +55,7 @@ ArgumentPtr FloorCeilExpression::negSimplify(const IFunction &func, const Argume
}

std::shared_ptr<IFunction> FloorCeilExpression::getOppositeFunction(const IFunction &function) {
static const std::map<std::string, std::shared_ptr<IFunction>, std::less<>> oppositeFunctions = {
static const std::unordered_map<std::string, std::shared_ptr<IFunction>> oppositeFunctions = {
{Floor{}.toString(), std::make_shared<Ceil>()},
{Ceil{}.toString(), std::make_shared<Floor>()},
};
Expand Down
6 changes: 3 additions & 3 deletions src/fintamath/expressions/unary/HyperbExpression.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "fintamath/expressions/unary/HyperbExpression.hpp"

#include <functional>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>

#include "fintamath/core/CoreUtils.hpp"
Expand All @@ -29,7 +29,7 @@

namespace fintamath {

using SimplifyFunctionMap = std::map<std::string, std::function<ArgumentPtr(const ArgumentPtr &)>, std::less<>>;
using SimplifyFunctionMap = std::unordered_map<std::string, std::function<ArgumentPtr(const ArgumentPtr &)>>;

HyperbExpression::HyperbExpression(const IFunction &inFunc, ArgumentPtr inChild)
: IUnaryExpressionCRTP(inFunc, std::move(inChild)) {
Expand Down Expand Up @@ -112,7 +112,7 @@ ArgumentPtr HyperbExpression::negSimplify(const IFunction &func, const ArgumentP
}

std::shared_ptr<IFunction> HyperbExpression::getOppositeFunction(const IFunction &function) {
static const std::map<std::string, std::shared_ptr<IFunction>, std::less<>> oppositeFunctions = {
static const std::unordered_map<std::string, std::shared_ptr<IFunction>> oppositeFunctions = {
{Sinh{}.toString(), std::make_unique<Asinh>()},
{Cosh{}.toString(), std::make_unique<Acosh>()},
{Tanh{}.toString(), std::make_unique<Atanh>()},
Expand Down
4 changes: 2 additions & 2 deletions src/fintamath/expressions/unary/InvTrigExpression.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "fintamath/expressions/unary/InvTrigExpression.hpp"

#include <functional>
#include <map>
#include <string>
#include <unordered_map>
#include <utility>

#include "fintamath/core/Converter.hpp"
Expand All @@ -26,7 +26,7 @@

namespace fintamath {

using TrigonometryFunctionMap = std::map<std::string, std::function<ArgumentPtr(const Rational &)>, std::less<>>;
using TrigonometryFunctionMap = std::unordered_map<std::string, std::function<ArgumentPtr(const Rational &)>>;

using TrigonometryTable = std::map<Rational, ArgumentPtr>;

Expand Down
4 changes: 2 additions & 2 deletions src/fintamath/expressions/unary/NotExpression.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "fintamath/expressions/unary/NotExpression.hpp"

#include <functional>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>

#include "fintamath/core/CoreUtils.hpp"
Expand Down Expand Up @@ -89,7 +89,7 @@ ArgumentPtr NotExpression::nestedNotSimplify(const IFunction & /*func*/, const A
}

std::shared_ptr<IFunction> NotExpression::getLogicOppositeFunction(const IFunction &function) {
static const std::map<std::string, std::shared_ptr<IFunction>, std::less<>> oppositeFunctions = {
static const std::unordered_map<std::string, std::shared_ptr<IFunction>> oppositeFunctions = {
{Eqv{}.toString(), std::make_shared<Neqv>()},
{Neqv{}.toString(), std::make_shared<Eqv>()},
{More{}.toString(), std::make_shared<LessEqv>()},
Expand Down
8 changes: 4 additions & 4 deletions src/fintamath/expressions/unary/TrigExpression.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "fintamath/expressions/unary/TrigExpression.hpp"

#include <functional>
#include <map>
#include <memory>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>

#include "fintamath/core/Converter.hpp"
Expand Down Expand Up @@ -34,9 +34,9 @@

namespace fintamath {

using SimplifyFunctionMap = std::map<std::string, std::function<ArgumentPtr(const ArgumentPtr &)>, std::less<>>;
using SimplifyFunctionMap = std::unordered_map<std::string, std::function<ArgumentPtr(const ArgumentPtr &)>>;

using TrigonometryFunctionMap = std::map<std::string, std::function<ArgumentPtr(const Rational &)>, std::less<>>;
using TrigonometryFunctionMap = std::unordered_map<std::string, std::function<ArgumentPtr(const Rational &)>>;

using TrigonometryTable = std::map<Rational, ArgumentPtr>;

Expand Down Expand Up @@ -234,7 +234,7 @@ Rational TrigExpression::phaseShiftPeriod(const Rational &rhs) {
}

std::shared_ptr<IFunction> TrigExpression::getOppositeFunction(const IFunction &function) {
static const std::map<std::string, std::shared_ptr<IFunction>, std::less<>> oppositeFunctions = {
static const std::unordered_map<std::string, std::shared_ptr<IFunction>> oppositeFunctions = {
{Sin{}.toString(), std::make_shared<Asin>()},
{Cos{}.toString(), std::make_shared<Acos>()},
{Tan{}.toString(), std::make_shared<Atan>()},
Expand Down

0 comments on commit bd0091e

Please sign in to comment.