[poincare] Clean

Change-Id: I6a582a850f440572c99fe215167747626de6da8c
This commit is contained in:
Émilie Feral
2017-11-02 13:44:36 +01:00
parent 4570106dba
commit e41d4a21c0
2 changed files with 31 additions and 26 deletions

View File

@@ -142,7 +142,7 @@ void Addition::factorizeChildren(Expression * e1, Expression * e2, Context & con
}
const Rational Addition::RationalFactor(Expression * e) {
if (e->type() == Type::Multiplication && e->operand(0)->type() == Type::Rational) { // TODO: change integer for Rational
if (e->type() == Type::Multiplication && e->operand(0)->type() == Type::Rational) {
return *(static_cast<const Rational *>(e->operand(0)));
}
return Rational(Integer(1));

View File

@@ -84,6 +84,36 @@ void DynamicHierarchy::removeOperand(const Expression * e, bool deleteAfterRemov
}
}
void DynamicHierarchy::sortOperands(ExpressionOrder order) {
for (int i = numberOfOperands()-1; i > 0; i--) {
bool isSorted = true;
for (int j = 0; j < numberOfOperands()-1; j++) {
if (order(operand(j), operand(j+1)) > 0) {
swapOperands(j, j+1);
isSorted = false;
}
}
if (isSorted) {
return;
}
}
}
Expression * DynamicHierarchy::squashUnaryHierarchy() {
if (numberOfOperands() == 1) {
assert(parent() != nullptr);
Expression * o = editableOperand(0);
replaceWith(o, true);
return o;
}
return this;
}
// Private
void DynamicHierarchy::removeOperandAtIndex(int i, bool deleteAfterRemoval) {
if (deleteAfterRemoval) {
delete m_operands[i];
@@ -130,29 +160,4 @@ int DynamicHierarchy::simplificationOrderGreaterType(const Expression * e) const
return 0;
}
void DynamicHierarchy::sortOperands(ExpressionOrder order) {
for (int i = numberOfOperands()-1; i > 0; i--) {
bool isSorted = true;
for (int j = 0; j < numberOfOperands()-1; j++) {
if (order(operand(j), operand(j+1)) > 0) {
swapOperands(j, j+1);
isSorted = false;
}
}
if (isSorted) {
return;
}
}
}
Expression * DynamicHierarchy::squashUnaryHierarchy() {
if (numberOfOperands() == 1) {
assert(parent() != nullptr);
Expression * o = editableOperand(0);
replaceWith(o, true);
return o;
}
return this;
}
}