mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-22 15:20:39 +01:00
[poincare] Change comparesTo + virtual nodeCompareTo -> virtual compareTo
Change-Id: Ie54b3652ad1d5845f084b4b49ca0eb96198b853a
This commit is contained in:
@@ -111,7 +111,7 @@ public:
|
||||
/* Sorting */
|
||||
virtual bool isCommutative() const { return false; }
|
||||
virtual void sort();
|
||||
int comparesTo(const Expression * e) const;
|
||||
virtual int compareTo(const Expression * e) const;
|
||||
|
||||
/* Layout Engine */
|
||||
ExpressionLayout * createLayout(FloatDisplayMode floatDisplayMode = FloatDisplayMode::Default, ComplexFormat complexFormat = ComplexFormat::Default) const; // Returned object must be deleted
|
||||
@@ -135,7 +135,6 @@ protected:
|
||||
* This behavior makes sense for value-less nodes (addition, product, fraction
|
||||
* power, etc… For nodes with a value (Integer, Complex), this must be over-
|
||||
* -riden. */
|
||||
virtual int nodeComparesTo(const Expression * e) const;
|
||||
private:
|
||||
/* Layout Engine */
|
||||
virtual ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const = 0;
|
||||
|
||||
@@ -32,7 +32,7 @@ public:
|
||||
Type type() const override;
|
||||
Expression * clone() const override;
|
||||
int checksum() const override;
|
||||
int nodeComparesTo(const Expression * e) const override;
|
||||
int compareTo(const Expression * e) const override;
|
||||
bool isEqualTo(const Integer & other) const;
|
||||
bool isLowerThan(const Integer & other) const;
|
||||
|
||||
|
||||
@@ -35,9 +35,9 @@ public:
|
||||
Type type() const override;
|
||||
Expression * clone() const override;
|
||||
int checksum() const override;
|
||||
int compareTo(const Expression * e) const override;
|
||||
bool isMatrixSymbol() const;
|
||||
private:
|
||||
int nodeComparesTo(const Expression * e) const override;
|
||||
Evaluation<float> * privateEvaluate(SinglePrecision p, Context& context, AngleUnit angleUnit) const override { return templatedEvaluate<float>(context, angleUnit); }
|
||||
Evaluation<double> * privateEvaluate(DoublePrecision p, Context& context, AngleUnit angleUnit) const override { return templatedEvaluate<double>(context, angleUnit); }
|
||||
template<typename T> Evaluation<T> * templatedEvaluate(Context& context, AngleUnit angleUnit) const;
|
||||
|
||||
@@ -88,7 +88,7 @@ void Expression::sort() {
|
||||
for (int i = numberOfOperands()-1; i > 0; i--) {
|
||||
bool isSorted = true;
|
||||
for (int j = 0; j < numberOfOperands()-1; j++) {
|
||||
if (operand(j)->comparesTo(operand(j+1)) > 0) {
|
||||
if (operand(j)->compareTo(operand(j+1)) > 0) {
|
||||
swapOperands(j, j+1);
|
||||
isSorted = false;
|
||||
}
|
||||
@@ -104,17 +104,20 @@ int Expression::checksum() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Expression::comparesTo(const Expression * e) const {
|
||||
if (this->nodeComparesTo(e) != 0) {
|
||||
return this->nodeComparesTo(e);
|
||||
int Expression::compareTo(const Expression * e) const {
|
||||
if (e->type() > this->type()) {
|
||||
return 1;
|
||||
}
|
||||
if (e->type() < this->type()) {
|
||||
return -1;
|
||||
}
|
||||
for (int i = 0; i < this->numberOfOperands(); i++) {
|
||||
// The NULL node is the least node type.
|
||||
if (e->numberOfOperands() <= i) {
|
||||
return 1;
|
||||
}
|
||||
if (this->operand(i)->comparesTo(e->operand(i)) != 0) {
|
||||
return this->operand(i)->comparesTo(e->operand(i));
|
||||
if (this->operand(i)->compareTo(e->operand(i)) != 0) {
|
||||
return this->operand(i)->compareTo(e->operand(i));
|
||||
}
|
||||
}
|
||||
// The NULL node is the least node type.
|
||||
@@ -157,16 +160,6 @@ template<typename T> T Expression::epsilon() {
|
||||
return epsilon;
|
||||
}
|
||||
|
||||
int Expression::nodeComparesTo(const Expression * e) const {
|
||||
if (e->type() == this->type()) {
|
||||
return 0;
|
||||
}
|
||||
if (e->type() > this->type()) {
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Expression::recursivelySetAsParentOfChildren() {
|
||||
for (int i=0; i<numberOfOperands(); i++) {
|
||||
Expression * child = const_cast<Expression *>(operand(i));
|
||||
|
||||
@@ -142,8 +142,8 @@ Expression * Integer::clone() const {
|
||||
|
||||
// Comparison
|
||||
|
||||
int Integer::nodeComparesTo(const Expression * e) const {
|
||||
int typeComparison = Expression::nodeComparesTo(e);
|
||||
int Integer::compareTo(const Expression * e) const {
|
||||
int typeComparison = Expression::compareTo(e);
|
||||
if (typeComparison != 0) {
|
||||
return typeComparison;
|
||||
}
|
||||
@@ -160,11 +160,11 @@ int Integer::nodeComparesTo(const Expression * e) const {
|
||||
}
|
||||
|
||||
bool Integer::isEqualTo(const Integer & other) const {
|
||||
return (nodeComparesTo(&other) == 0);
|
||||
return (compareTo(&other) == 0);
|
||||
}
|
||||
|
||||
bool Integer::isLowerThan(const Integer & other) const {
|
||||
return (nodeComparesTo(&other) < 0);
|
||||
return (compareTo(&other) < 0);
|
||||
}
|
||||
|
||||
// Arithmetic
|
||||
|
||||
@@ -57,6 +57,21 @@ int Symbol::checksum() const {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
int Symbol::compareTo(const Expression * e) const {
|
||||
int typeComparison = Expression::compareTo(e);
|
||||
if (typeComparison != 0) {
|
||||
return typeComparison;
|
||||
}
|
||||
assert(e->type() == Expression::Type::Symbol);
|
||||
if (m_name == ((Symbol *)e)->m_name) {
|
||||
return 0;
|
||||
}
|
||||
if ((m_name > ((Symbol *)e)->m_name)) {
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Evaluation<T> * Symbol::templatedEvaluate(Context& context, AngleUnit angleUnit) const {
|
||||
if (context.expressionForSymbol(this) != nullptr) {
|
||||
@@ -104,21 +119,6 @@ ExpressionLayout * Symbol::privateCreateLayout(FloatDisplayMode floatDisplayMode
|
||||
return new StringLayout(&m_name, 1);
|
||||
}
|
||||
|
||||
int Symbol::nodeComparesTo(const Expression * e) const {
|
||||
int typeComparison = Expression::nodeComparesTo(e);
|
||||
if (typeComparison != 0) {
|
||||
return typeComparison;
|
||||
}
|
||||
assert(e->type() == Expression::Type::Symbol);
|
||||
if (m_name == ((Symbol *)e)->m_name) {
|
||||
return 0;
|
||||
}
|
||||
if ((m_name > ((Symbol *)e)->m_name)) {
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool Symbol::isMatrixSymbol() const {
|
||||
if (m_name >= (char)SpecialSymbols::M0 && m_name <= (char)SpecialSymbols::M9) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user