Skip to content

Commit

Permalink
Renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
fintarin committed Feb 13, 2024
1 parent 529a20b commit fd964bd
Show file tree
Hide file tree
Showing 18 changed files with 119 additions and 123 deletions.
12 changes: 6 additions & 6 deletions include/fintamath/core/Cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ class Cache final {
using Function = std::function<Value(const Key &)>;

public:
explicit Cache(const Function &keyToValueFunction) : func(keyToValueFunction) {}
explicit Cache(const Function &inKeyToValueFunction) : keyToValueFunction(inKeyToValueFunction) {}

const Value &operator[](const Key &key) {
if (!map.contains(key)) {
map[key] = func(key);
if (!keyToValueMap.contains(key)) {
keyToValueMap[key] = keyToValueFunction(key);
}

return map.at(key);
return keyToValueMap.at(key);
}

private:
std::unordered_map<Key, Value> map;
std::unordered_map<Key, Value> keyToValueMap;

Function func;
Function keyToValueFunction;
};

}
19 changes: 9 additions & 10 deletions include/fintamath/core/MathObjectTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ namespace detail {
class MathObjectBoundTypes final {
using enum MathObjectType::Id;

using TypeToTypeMap = std::unordered_map<MathObjectType, MathObjectType, boost::hash<MathObjectType>>;
using TypeToBoundTypeMap = std::unordered_map<MathObjectType, MathObjectType, boost::hash<MathObjectType>>;

static TypeToTypeMap &getMutable() {
static TypeToTypeMap ids{
static TypeToBoundTypeMap &getMapMutable() {
static TypeToBoundTypeMap typeToBoundTypeMap{
{IMathObject, None},
{IArithmetic, ILiteral},
{IExpression, IComparable},
Expand All @@ -224,24 +224,23 @@ class MathObjectBoundTypes final {
{IFunction, None},
{IOperator, None},
};

return ids;
return typeToBoundTypeMap;
}

public:
static const TypeToTypeMap &get() {
return getMutable();
static const TypeToBoundTypeMap &getMap() {
return getMapMutable();
}

static void reg(const MathObjectType &type, const MathObjectType &boundType) {
getMutable().emplace(type, boundType);
static void bindTypes(const MathObjectType &type, const MathObjectType &boundType) {
getMapMutable().emplace(type, boundType);
}
};

}

inline bool isBaseOf(const MathObjectType &toType, const MathObjectType &fromType) {
const auto &typeToTypeMap = detail::MathObjectBoundTypes::get();
const auto &typeToTypeMap = detail::MathObjectBoundTypes::getMap();

if (const auto toTypeBoundaries = typeToTypeMap.find(toType); toTypeBoundaries != typeToTypeMap.end()) {
return fromType >= toTypeBoundaries->first && fromType < toTypeBoundaries->second;
Expand Down
10 changes: 5 additions & 5 deletions include/fintamath/core/MultiMethod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ class MultiMethod<Res(ArgsBase...)> final {

using Callback = std::function<Res(ArgsBase...)>;

using Callbacks = std::unordered_map<CallbackId, Callback, boost::hash<CallbackId>>;
using IdToCallbackMap = std::unordered_map<CallbackId, Callback, boost::hash<CallbackId>>;

public:
template <typename... Args>
requires(sizeof...(Args) == sizeof...(ArgsBase))
void add(const auto &func) {
callbacks[CallbackId(Args::getTypeStatic()...)] = [func](const ArgsBase &...args) {
idToCallbackMap[CallbackId(Args::getTypeStatic()...)] = [func](const ArgsBase &...args) {
return func(cast<Args>(args)...);
};
}

template <typename... Args>
requires(sizeof...(Args) == sizeof...(ArgsBase))
Res operator()(Args &&...args) const {
if (auto iter = callbacks.find(CallbackId(args.getType()...)); iter != callbacks.end()) {
if (auto iter = idToCallbackMap.find(CallbackId(args.getType()...)); iter != idToCallbackMap.end()) {
return iter->second(std::forward<Args>(args)...);
}

Expand All @@ -47,11 +47,11 @@ class MultiMethod<Res(ArgsBase...)> final {
template <typename... Args>
requires(sizeof...(Args) == sizeof...(ArgsBase))
bool contains(const Args &...args) const {
return callbacks.contains(CallbackId(args.getType()...));
return idToCallbackMap.contains(CallbackId(args.getType()...));
}

private:
Callbacks callbacks;
IdToCallbackMap idToCallbackMap;
};

}
10 changes: 5 additions & 5 deletions include/fintamath/core/Parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Parser<Return(Args...)> final {

using ConstructorVector = std::vector<StringConstructor>;

using ConstructorMap = std::unordered_multimap<std::string, Constructor>;
using StringToConstructorMap = std::unordered_multimap<std::string, Constructor>;

public:
template <typename... ConstructorArgs>
Expand All @@ -46,8 +46,8 @@ class Parser<Return(Args...)> final {
template <typename... ConstructorArgs>
requires(SameAsUnqual<ConstructorArgs, Args> && ...)
Return parse(const Validator &validator, const std::string &str, ConstructorArgs &&...args) const {
for (const auto &valuePairs = constructorMap.equal_range(str);
const auto &pair : stdv::iota(valuePairs.first, valuePairs.second)) {
for (const auto &pairs = stringToConstructorMap.equal_range(str);
const auto &pair : stdv::iota(pairs.first, pairs.second)) {

if (Return value = pair->second(std::forward<ConstructorArgs>(args)...);
value && validator(value)) {
Expand Down Expand Up @@ -81,7 +81,7 @@ class Parser<Return(Args...)> final {
requires(!StringConstructable<Type, Args...>)
void registerType(Constructor constructor) {
static const std::string name = Type{}.toString();
constructorMap.emplace(name, std::move(constructor));
stringToConstructorMap.emplace(name, std::move(constructor));

Tokenizer::registerToken(name);
}
Expand All @@ -106,7 +106,7 @@ class Parser<Return(Args...)> final {
}

private:
ConstructorMap constructorMap;
StringToConstructorMap stringToConstructorMap;

ConstructorVector extraConstructors;
};
Expand Down
8 changes: 4 additions & 4 deletions include/fintamath/functions/IFunction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace fintamath {

class IFunction : public IMathObject {
using FunctionOrderMap = std::unordered_map<std::string, size_t>;
using FunctionNameToOrderMap = std::unordered_map<std::string, size_t>;

using FunctionParser = detail::Parser<std::unique_ptr<IFunction>()>;

Expand Down Expand Up @@ -57,7 +57,7 @@ class IFunction : public IMathObject {
static void registerType() {
getParser().registerType<T>();

getFunctionOrderMutableMap()[T{}.toString()] = maxFunctionOrder;
getFunctionNameToOrderMutableMap()[T{}.toString()] = maxFunctionOrder;
maxFunctionOrder++;
}

Expand All @@ -70,10 +70,10 @@ class IFunction : public IMathObject {

virtual void validateArgsSize(const ArgumentRefVector &argVect) const;

static const FunctionOrderMap &getFunctionOrderMap();
static const FunctionNameToOrderMap &getFunctionNameToOrderMap();

private:
static FunctionOrderMap &getFunctionOrderMutableMap();
static FunctionNameToOrderMap &getFunctionNameToOrderMutableMap();

static FunctionParser &getParser();

Expand Down
2 changes: 1 addition & 1 deletion include/fintamath/functions/IFunctionCRTP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class IFunctionCRTP_ : public IFunction {

size_t getFunctionOrder() const final {
static const std::string funcStr = Derived{}.toString();
return getFunctionOrderMap().at(funcStr);
return getFunctionNameToOrderMap().at(funcStr);
}

bool doArgsMatch(const ArgumentRefVector &argVect) const override {
Expand Down
4 changes: 2 additions & 2 deletions src/fintamath/expressions/binary/CompExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ void CompExpression::markAsSolution() {
}

std::shared_ptr<IFunction> CompExpression::getOppositeFunction(const IFunction &function) {
static const std::unordered_map<std::string, std::shared_ptr<IFunction>> oppositeFunctions = {
static const std::unordered_map<std::string, std::shared_ptr<IFunction>> nameToOppositeFuncMap = {
{Eqv{}.toString(), std::make_shared<Eqv>()},
{Neqv{}.toString(), std::make_shared<Neqv>()},
{More{}.toString(), std::make_shared<Less>()},
{Less{}.toString(), std::make_shared<More>()},
{MoreEqv{}.toString(), std::make_shared<LessEqv>()},
{LessEqv{}.toString(), std::make_shared<MoreEqv>()},
};
return oppositeFunctions.at(function.toString());
return nameToOppositeFuncMap.at(function.toString());
}

ArgumentPtr CompExpression::constSimplify(const IFunction &func, const ArgumentPtr &lhs, const ArgumentPtr &rhs) {
Expand Down
10 changes: 5 additions & 5 deletions src/fintamath/expressions/binary/DerivativeExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace fintamath {

using namespace detail;

using DerivativeSimplifyMap = std::unordered_map<
using NameToSimplifyFunctionMap = std::unordered_map<
std::string,
std::function<ArgumentPtr(const ArgumentPtrVector &children,
const std::shared_ptr<const Variable> &var)>>;
Expand Down Expand Up @@ -92,8 +92,8 @@ ArgumentPtr DerivativeExpression::derivativeSimplify(const IFunction & /*func*/,
}

ArgumentPtr DerivativeExpression::exprSimplify(const std::shared_ptr<const IExpression> &expr, const std::shared_ptr<const Variable> &var) {
static const DerivativeSimplifyMap derivativeSimplifyMap = [] {
static const DerivativeSimplifyMap map = {
static const NameToSimplifyFunctionMap nameToSimplifyFunctionMap = [] {
static const NameToSimplifyFunctionMap map = {
{Add{}.toString(), &addSimplify},
{Mul{}.toString(), &mulSimplify},
{Div{}.toString(), &divSimplify},
Expand Down Expand Up @@ -127,8 +127,8 @@ ArgumentPtr DerivativeExpression::exprSimplify(const std::shared_ptr<const IExpr
return map;
}();

if (const auto iter = derivativeSimplifyMap.find(expr->getFunction()->toString());
iter != derivativeSimplifyMap.end()) {
if (const auto iter = nameToSimplifyFunctionMap.find(expr->getFunction()->toString());
iter != nameToSimplifyFunctionMap.end()) {

return iter->second(expr->getChildren(), var);
}
Expand Down
4 changes: 2 additions & 2 deletions src/fintamath/expressions/unary/FloorCeilExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ ArgumentPtr FloorCeilExpression::negSimplify(const IFunction &func, const Argume
}

std::shared_ptr<IFunction> FloorCeilExpression::getOppositeFunction(const IFunction &function) {
static const std::unordered_map<std::string, std::shared_ptr<IFunction>> oppositeFunctions = {
static const std::unordered_map<std::string, std::shared_ptr<IFunction>> nameToOppositeFuncMap = {
{Floor{}.toString(), std::make_shared<Ceil>()},
{Ceil{}.toString(), std::make_shared<Floor>()},
};
return oppositeFunctions.at(function.toString());
return nameToOppositeFuncMap.at(function.toString());
}

}
14 changes: 7 additions & 7 deletions src/fintamath/expressions/unary/HyperbExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace fintamath {

using namespace detail;

using SimplifyFunctionMap = std::unordered_map<std::string, std::function<ArgumentPtr(const ArgumentPtr &)>>;
using NameToSimplifyFunctionMap = 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 @@ -66,7 +66,7 @@ ArgumentPtr HyperbExpression::oppositeFunctionsSimplify(const IFunction &func, c
}

ArgumentPtr HyperbExpression::expandSimplify(const IFunction &func, const ArgumentPtr &rhs) {
static const SimplifyFunctionMap expandFunctionMap = {
static const NameToSimplifyFunctionMap nameToExpandFunctionMap = {
{Tanh{}.toString(),
[](const ArgumentPtr &inRhs) {
return divExpr(sinhExpr(inRhs), coshExpr(inRhs));
Expand All @@ -85,15 +85,15 @@ ArgumentPtr HyperbExpression::expandSimplify(const IFunction &func, const Argume
}},
};

if (const auto iter = expandFunctionMap.find(func.toString()); iter != expandFunctionMap.end()) {
if (const auto iter = nameToExpandFunctionMap.find(func.toString()); iter != nameToExpandFunctionMap.end()) {
return iter->second(rhs);
}

return {};
}

ArgumentPtr HyperbExpression::negSimplify(const IFunction &func, const ArgumentPtr &rhs) {
static const SimplifyFunctionMap negFunctionsMap = {
static const NameToSimplifyFunctionMap nameToNegFunctionsMap = {
{Sinh{}.toString(),
[](const ArgumentPtr &inRhs) {
return negExpr(sinhExpr(negExpr(inRhs)));
Expand All @@ -105,7 +105,7 @@ ArgumentPtr HyperbExpression::negSimplify(const IFunction &func, const ArgumentP
};

if (isNegated(rhs)) {
if (const auto iter = negFunctionsMap.find(func.toString()); iter != negFunctionsMap.end()) {
if (const auto iter = nameToNegFunctionsMap.find(func.toString()); iter != nameToNegFunctionsMap.end()) {
return iter->second(rhs);
}
}
Expand All @@ -114,15 +114,15 @@ ArgumentPtr HyperbExpression::negSimplify(const IFunction &func, const ArgumentP
}

std::shared_ptr<IFunction> HyperbExpression::getOppositeFunction(const IFunction &function) {
static const std::unordered_map<std::string, std::shared_ptr<IFunction>> oppositeFunctions = {
static const std::unordered_map<std::string, std::shared_ptr<IFunction>> nameToOppositeFunctionMap = {
{Sinh{}.toString(), std::make_unique<Asinh>()},
{Cosh{}.toString(), std::make_unique<Acosh>()},
{Tanh{}.toString(), std::make_unique<Atanh>()},
{Coth{}.toString(), std::make_unique<Acoth>()},
{Sech{}.toString(), std::make_shared<Asech>()},
{Csch{}.toString(), std::make_shared<Acsch>()},
};
return oppositeFunctions.at(function.toString());
return nameToOppositeFunctionMap.at(function.toString());
}

}
Loading

0 comments on commit fd964bd

Please sign in to comment.