Skip to content

Commit

Permalink
Refactor comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
fintarin committed Sep 24, 2023
1 parent e112995 commit 01f0591
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion include/fintamath/expressions/Expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Expression : public IExpressionCRTP<Expression> {
res = maker(args);
}
else if constexpr (isPolynomial) {
if (uint16_t(type) <= args.size()) {
if (size_t(type) <= args.size()) {
res = maker(args);
}
}
Expand Down
2 changes: 1 addition & 1 deletion include/fintamath/functions/IOperator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class IOperator : public IFunction {

static std::unique_ptr<IOperator> parse(const std::string &parsedStr, IOperator::Priority priority = IOperator::Priority::Any) {
Parser::Comparator<const std::unique_ptr<IOperator> &> comp = [priority](const std::unique_ptr<IOperator> &oper) {
return size_t(priority == IOperator::Priority::Any || oper->getOperatorPriority() == priority);
return priority == IOperator::Priority::Any || oper->getOperatorPriority() == priority;
};
return Parser::parse<std::unique_ptr<IOperator>>(getParser(), comp, parsedStr);
}
Expand Down
2 changes: 1 addition & 1 deletion src/fintamath/expressions/Expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ void Expression::fixOperatorTypes(TermVector &terms) {
}

void Expression::collapseFactorials(TermVector &terms) {
for (size_t i = 1; i < terms.size() - 1; i++) {
for (size_t i = 1; i + 1 < terms.size(); i++) {
const auto &term = terms[i];
const auto &termNext = terms[i + 1];

Expand Down
2 changes: 1 addition & 1 deletion src/fintamath/expressions/ExpressionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ std::string functionToString(const IFunction &func, const ArgumentPtrVector &arg
result += arg->toString() + delimiter;
}

result = result.substr(0, result.length() - delimiter.length()) + ")";
result = result.substr(0, result.size() - delimiter.size()) + ")";

return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/fintamath/expressions/FunctionExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace fintamath {
FunctionExpression::FunctionExpression(const IFunction &inFunc, const ArgumentPtrVector &inChildren)
: func(cast<IFunction>(inFunc.clone())) {

if (inChildren.size() != uint16_t(inFunc.getFunctionType())) {
if (inChildren.size() != size_t(inFunc.getFunctionType())) {
throw InvalidInputFunctionException(func->toString(), argumentVectorToStringVector(inChildren));
}

Expand Down
2 changes: 1 addition & 1 deletion src/fintamath/expressions/binary/PowExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ std::vector<Integer> PowExpression::getPartition(Integer bitNumber, const Intege
std::vector<Integer> result;
Integer counter = 0;

while (int64_t(result.size()) < variableCount) {
while (result.size() < variableCount) {
if (bitNumber % 2 == 1) {
counter++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ std::string IPolynomExpression::toString() const {
for (auto i : std::views::iota(1U, children.size())) {
const std::string childStr = childToString(*oper, children[i], children[i - 1]);

if (childStr.length() > 2 && childStr[0] == ' ' && std::isdigit(childStr[1]) && std::isdigit(result.back())) {
if (childStr.size() > 2 && childStr[0] == ' ' && std::isdigit(childStr[1]) && std::isdigit(result.back())) {
result += Mul().toString() + childStr.substr(1);
}
else {
Expand Down
2 changes: 1 addition & 1 deletion src/fintamath/numbers/Complex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Complex &Complex::operator=(const Complex &rhs) {

Complex::Complex(const std::string &str) {
if (!str.empty() && str.back() == 'I') {
im = INumber::parse(str.substr(0, str.length() - 1));
im = INumber::parse(str.substr(0, str.size() - 1));
}
else {
re = INumber::parse(str);
Expand Down
2 changes: 1 addition & 1 deletion src/fintamath/numbers/Rational.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Rational::Rational(const std::string &str) {
intPart = Integer(str.substr(size_t(firstDigitNum), size_t(firstDotNum - firstDigitNum)));
}

if (firstDotNum + 1 < int64_t(str.size())) {
if (firstDotNum + 1 < std::ssize(str)) {
auto numeratorStr = str.substr(size_t(firstDotNum) + 1);
std::string denominatorStr(numeratorStr.size() + 1, '0');
denominatorStr.front() = '1';
Expand Down
2 changes: 1 addition & 1 deletion src/fintamath/numbers/Real.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ std::string Real::toString() const {
}
}
else {
expPos = res.length();
expPos = res.size();
}

if (res.find('.') == std::string::npos) {
Expand Down
10 changes: 5 additions & 5 deletions src/fintamath/parser/Tokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ TokenVector Tokenizer::tokenize(std::string str) {
void Tokenizer::registerToken(const Token &token) {
auto &tokens = getRegisteredTokens();
tokens.insert(std::ranges::upper_bound(tokens, token, [](const Token &lhs, const Token &rhs) {
return lhs.length() > rhs.length();
return lhs.size() > rhs.size();
}),
token);
}
Expand All @@ -53,16 +53,16 @@ bool Tokenizer::appendToken(TokenVector &tokens, Token &token, bool shouldSplit)
}

while (!token.empty()) {
std::string nestedToken = token.substr(0, getRegisteredTokens().front().length());
std::string nestedToken = token.substr(0, getRegisteredTokens().front().size());
bool isNestedTokenFind = false;

for (const auto &registeredToken : getRegisteredTokens()) {
if (nestedToken.length() < registeredToken.length()) {
if (nestedToken.size() < registeredToken.size()) {
continue;
}

if (nestedToken.length() > registeredToken.length()) {
nestedToken = token.substr(0, registeredToken.length());
if (nestedToken.size() > registeredToken.size()) {
nestedToken = token.substr(0, registeredToken.size());
}

if (nestedToken == registeredToken) {
Expand Down

0 comments on commit 01f0591

Please sign in to comment.