mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-25 16:50:50 +01:00
[poincare] Sort selectors before creating rules
Change-Id: I51da663d83f5759c499c14f603511e3b9cb3f92f
This commit is contained in:
@@ -15,62 +15,62 @@ class Evaluation;
|
||||
class Expression {
|
||||
public:
|
||||
enum class Type : uint8_t {
|
||||
Integer = 0,
|
||||
Complex,
|
||||
Symbol,
|
||||
Parenthesis,
|
||||
Opposite,
|
||||
AbsoluteValue = 0,
|
||||
Addition,
|
||||
Subtraction,
|
||||
Multiplication,
|
||||
Division,
|
||||
Power,
|
||||
Sum,
|
||||
Product,
|
||||
DivisionQuotient,
|
||||
DivisionRemainder,
|
||||
GreatCommonDivisor,
|
||||
LeastCommonMultiple,
|
||||
Floor,
|
||||
Ceiling,
|
||||
Round,
|
||||
FracPart,
|
||||
AbsoluteValue,
|
||||
Factorial,
|
||||
ImaginaryPart,
|
||||
RealPart,
|
||||
ComplexArgument,
|
||||
Conjugate,
|
||||
Logarithm,
|
||||
NaperianLogarithm,
|
||||
SquareRoot,
|
||||
NthRoot,
|
||||
Cosine,
|
||||
Sine,
|
||||
Tangent,
|
||||
ArcCosine,
|
||||
ArcSine,
|
||||
ArcTangent,
|
||||
HyperbolicCosine,
|
||||
HyperbolicSine,
|
||||
HyperbolicTangent,
|
||||
BinomialCoefficient,
|
||||
Ceiling,
|
||||
Complex,
|
||||
ComplexArgument,
|
||||
ComplexMatrix,
|
||||
ConfidenceInterval,
|
||||
Conjugate,
|
||||
Cosine,
|
||||
Derivative,
|
||||
Determinant,
|
||||
Division,
|
||||
DivisionQuotient,
|
||||
DivisionRemainder,
|
||||
ExpressionMatrix,
|
||||
Factorial,
|
||||
Floor,
|
||||
FracPart,
|
||||
GreatCommonDivisor,
|
||||
HyperbolicArcCosine,
|
||||
HyperbolicArcSine,
|
||||
HyperbolicArcTangent,
|
||||
Derivative,
|
||||
HyperbolicCosine,
|
||||
HyperbolicSine,
|
||||
HyperbolicTangent,
|
||||
ImaginaryPart,
|
||||
Integer,
|
||||
Integral,
|
||||
BinomialCoefficient,
|
||||
PermuteCoefficient,
|
||||
ConfidenceInterval,
|
||||
PredictionInterval,
|
||||
ExpressionMatrix,
|
||||
ComplexMatrix,
|
||||
LeastCommonMultiple,
|
||||
Logarithm,
|
||||
MatrixDimension,
|
||||
MatrixInverse,
|
||||
MatrixTrace,
|
||||
MatrixTranspose,
|
||||
Determinant,
|
||||
Multiplication,
|
||||
NaperianLogarithm,
|
||||
NthRoot,
|
||||
Opposite,
|
||||
Parenthesis,
|
||||
PermuteCoefficient,
|
||||
Power,
|
||||
PredictionInterval,
|
||||
Product,
|
||||
RealPart,
|
||||
Round,
|
||||
Sine,
|
||||
SquareRoot,
|
||||
Store,
|
||||
Subtraction,
|
||||
Sum,
|
||||
Symbol,
|
||||
Tangent,
|
||||
Undefined = 255
|
||||
};
|
||||
enum class FloatDisplayMode {
|
||||
|
||||
@@ -26,6 +26,7 @@ void Node::identifyAnonymousChildren(int * index) {
|
||||
// Generation
|
||||
|
||||
void Node::generateSelector(Rule * rule) {
|
||||
sort();
|
||||
int i = 0;
|
||||
|
||||
for (Node * child : *m_children) {
|
||||
@@ -110,6 +111,93 @@ int Node::intValue() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
int Node::compareTo(Node * n) const {
|
||||
if (m_name->compare("Any")) {
|
||||
if (n->m_name->compare("Any")) {
|
||||
if (identifier().compare(n->identifier()) == 0) {
|
||||
return 0;
|
||||
} else if (identifier().compare(n->identifier()) > 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} else if (n->m_name->compare("SameAs")) {
|
||||
if (identifier().compare(n->value()) == 0) {
|
||||
return -1;
|
||||
} else if (identifier().compare(n->value()) > 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
} else if (m_name->compare("SameAs")) {
|
||||
if (n->m_name->compare("Any")) {
|
||||
if (value().compare(n->identifier()) == 0) {
|
||||
return 1;
|
||||
} else if (value().compare(n->identifier()) > 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} else if (n->m_name->compare("SameAs")) {
|
||||
if (value().compare(n->value()) == 0) {
|
||||
return 0;
|
||||
} else if (value().compare(n->value()) > 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if (n->m_name->compare("Any")) {
|
||||
return -1;
|
||||
} else if (n->m_name->compare("SameAs")) {
|
||||
return -1;
|
||||
} else {
|
||||
if (name().compare(n->name()) != 0) {
|
||||
if (name().compare(n->name()) > 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (intValue() == n->intValue()) {
|
||||
return 0;
|
||||
} else if (intValue() > n->intValue()) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Node::sort() {
|
||||
if (m_children->size() == 0) {
|
||||
return;
|
||||
}
|
||||
for (Node * child : *m_children) {
|
||||
child->sort();
|
||||
}
|
||||
for (int i = m_children->size()-1; i > 0; i--) {
|
||||
bool isSorted = true;
|
||||
for (int j = 0; j < m_children->size()-1; j++) {
|
||||
if (m_children->at(j)->compareTo(m_children->at(j+1)) > 0) {
|
||||
std::swap(m_children->at(j), m_children->at(j+1));
|
||||
isSorted = false;
|
||||
}
|
||||
}
|
||||
if (isSorted) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
std::string Node::generateSelectorConstructor(Rule * context) {
|
||||
|
||||
@@ -24,6 +24,8 @@ public:
|
||||
std::string value() const;
|
||||
int intValue() const;
|
||||
int numberOfChildren() { return m_children->size(); }
|
||||
int compareTo(Node * node) const;
|
||||
void sort();
|
||||
private:
|
||||
int selectorCaptureIndexInRule(Rule * rule);
|
||||
int selectorIndexInRule(Rule * rule);
|
||||
|
||||
Reference in New Issue
Block a user