Skip to content
Snippets Groups Projects
Commit 511b1550 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

operator< using linear number of methods

parent 87d68935
No related branches found
No related tags found
No related merge requests found
...@@ -93,10 +93,6 @@ bool Alternation::operator>(const RegExpElement& other) const { ...@@ -93,10 +93,6 @@ bool Alternation::operator>(const RegExpElement& other) const {
} }
   
   
bool Alternation::operator<(const Concatenation&) const {
return true;
}
bool Alternation::operator<(const Alternation& other) const { bool Alternation::operator<(const Alternation& other) const {
int thisSize = this->elements.size(); int thisSize = this->elements.size();
int otherSize = other.elements.size(); int otherSize = other.elements.size();
...@@ -113,6 +109,18 @@ bool Alternation::operator<(const Alternation& other) const { ...@@ -113,6 +109,18 @@ bool Alternation::operator<(const Alternation& other) const {
return **thisIter < **otherIter; return **thisIter < **otherIter;
} }
   
bool Alternation::operator==(const Alternation& other) const {
if(this->elements.size() != other.elements.size()) return false;
auto thisIter = this->elements.begin();
auto otherIter = other.elements.begin();
for(; thisIter != this->elements.end(); thisIter++, otherIter++) {
if(**thisIter != **otherIter) return false;
}
return true;
}
bool Alternation::testSymbol( const alphabet::Symbol & symbol ) const { bool Alternation::testSymbol( const alphabet::Symbol & symbol ) const {
for(const auto& child : this->elements) for(const auto& child : this->elements)
if(child->testSymbol(symbol)) return true; if(child->testSymbol(symbol)) return true;
...@@ -131,18 +139,6 @@ void Alternation::computeMinimalAlphabet( std::set<alphabet::Symbol>& alphabet ) ...@@ -131,18 +139,6 @@ void Alternation::computeMinimalAlphabet( std::set<alphabet::Symbol>& alphabet )
child->computeMinimalAlphabet(alphabet); child->computeMinimalAlphabet(alphabet);
} }
   
bool Alternation::operator==(const Alternation& other) const {
if(this->elements.size() != other.elements.size()) return false;
auto thisIter = this->elements.begin();
auto otherIter = other.elements.begin();
for(; thisIter != this->elements.end(); thisIter++, otherIter++) {
if(**thisIter != **otherIter) return false;
}
return true;
}
void Alternation::operator>>(std::ostream& out) const { void Alternation::operator>>(std::ostream& out) const {
out << "(Alternation"; out << "(Alternation";
for(const auto& e : elements) for(const auto& e : elements)
......
...@@ -75,7 +75,6 @@ public: ...@@ -75,7 +75,6 @@ public:
virtual bool operator==(const RegExpElement&) const; virtual bool operator==(const RegExpElement&) const;
virtual bool operator>(const RegExpElement&) const; virtual bool operator>(const RegExpElement&) const;
   
virtual bool operator<(const Concatenation&) const;
virtual bool operator<(const Alternation&) const; virtual bool operator<(const Alternation&) const;
virtual bool operator==(const Alternation&) const; virtual bool operator==(const Alternation&) const;
......
...@@ -87,14 +87,6 @@ bool Iteration::operator>(const RegExpElement& other) const { ...@@ -87,14 +87,6 @@ bool Iteration::operator>(const RegExpElement& other) const {
return other < *this; return other < *this;
} }
   
bool Iteration::operator<(const Concatenation&) const {
return true;
}
bool Iteration::operator<(const Alternation&) const {
return true;
}
bool Iteration::operator<(const Iteration& other) const { bool Iteration::operator<(const Iteration& other) const {
return *(this->element) < *(other.element); return *(this->element) < *(other.element);
} }
......
...@@ -69,8 +69,6 @@ public: ...@@ -69,8 +69,6 @@ public:
virtual bool operator==(const RegExpElement&) const; virtual bool operator==(const RegExpElement&) const;
virtual bool operator>(const RegExpElement&) const; virtual bool operator>(const RegExpElement&) const;
   
virtual bool operator<(const Concatenation&) const;
virtual bool operator<(const Alternation&) const;
virtual bool operator<(const Iteration&) const; virtual bool operator<(const Iteration&) const;
virtual bool operator==(const Iteration&) const; virtual bool operator==(const Iteration&) const;
   
......
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
*/ */
   
#include "RegExpElement.h" #include "RegExpElement.h"
#include <typeinfo>
#include "RegExpElements.h"
   
namespace regexp { namespace regexp {
   
...@@ -31,27 +34,27 @@ bool RegExpElement::operator!=(const RegExpElement& other) const { ...@@ -31,27 +34,27 @@ bool RegExpElement::operator!=(const RegExpElement& other) const {
   
   
bool RegExpElement::operator<(const Concatenation& other) const { bool RegExpElement::operator<(const Concatenation& other) const {
return false; return typeid(this).before(typeid(other));
} }
   
bool RegExpElement::operator<(const Alternation& other) const { bool RegExpElement::operator<(const Alternation& other) const {
return false; return typeid(this).before(typeid(other));
} }
   
bool RegExpElement::operator<(const Iteration& other) const { bool RegExpElement::operator<(const Iteration& other) const {
return false; return typeid(this).before(typeid(other));
} }
   
bool RegExpElement::operator<(const RegExpSymbol& other) const { bool RegExpElement::operator<(const RegExpSymbol& other) const {
return false; return typeid(this).before(typeid(other));
} }
   
bool RegExpElement::operator<(const RegExpEpsilon& other) const { bool RegExpElement::operator<(const RegExpEpsilon& other) const {
return false; return typeid(this).before(typeid(other));
} }
   
bool RegExpElement::operator<(const RegExpEmpty& other) const { bool RegExpElement::operator<(const RegExpEmpty& other) const {
return false; return typeid(this).before(typeid(other));
} }
   
   
......
...@@ -30,24 +30,8 @@ bool RegExpEmpty::operator>(const RegExpElement& other) const { ...@@ -30,24 +30,8 @@ bool RegExpEmpty::operator>(const RegExpElement& other) const {
} }
   
   
bool RegExpEmpty::operator<(const Concatenation&) const { bool RegExpEmpty::operator<(const RegExpEmpty&) const {
return true; return false;
}
bool RegExpEmpty::operator<(const Alternation&) const {
return true;
}
bool RegExpEmpty::operator<(const Iteration&) const {
return true;
}
bool RegExpEmpty::operator<(const RegExpSymbol&) const {
return true;
}
bool RegExpEmpty::operator<(const RegExpEpsilon&) const {
return true;
} }
   
bool RegExpEmpty::operator==(const RegExpEmpty&) const { bool RegExpEmpty::operator==(const RegExpEmpty&) const {
......
...@@ -44,11 +44,7 @@ public: ...@@ -44,11 +44,7 @@ public:
virtual bool operator==(const RegExpElement&) const; virtual bool operator==(const RegExpElement&) const;
virtual bool operator>(const RegExpElement&) const; virtual bool operator>(const RegExpElement&) const;
   
virtual bool operator<(const Concatenation&) const; virtual bool operator<(const RegExpEmpty&) const;
virtual bool operator<(const Alternation&) const;
virtual bool operator<(const Iteration&) const;
virtual bool operator<(const RegExpSymbol&) const;
virtual bool operator<(const RegExpEpsilon&) const;
virtual bool operator==(const RegExpEmpty&) const; virtual bool operator==(const RegExpEmpty&) const;
/** /**
......
...@@ -30,20 +30,8 @@ bool RegExpEpsilon::operator>(const RegExpElement& other) const { ...@@ -30,20 +30,8 @@ bool RegExpEpsilon::operator>(const RegExpElement& other) const {
} }
   
   
bool RegExpEpsilon::operator<(const Alternation&) const { bool RegExpEpsilon::operator<(const RegExpEpsilon&) const {
return true; return false;
}
bool RegExpEpsilon::operator<(const Concatenation&) const {
return true;
}
bool RegExpEpsilon::operator<(const Iteration&) const {
return true;
}
bool RegExpEpsilon::operator<(const RegExpSymbol&) const {
return true;
} }
   
bool RegExpEpsilon::operator==(const RegExpEpsilon&) const { bool RegExpEpsilon::operator==(const RegExpEpsilon&) const {
......
...@@ -45,10 +45,7 @@ public: ...@@ -45,10 +45,7 @@ public:
virtual bool operator==(const RegExpElement&) const; virtual bool operator==(const RegExpElement&) const;
virtual bool operator>(const RegExpElement&) const; virtual bool operator>(const RegExpElement&) const;
   
virtual bool operator<(const Alternation&) const; virtual bool operator<(const RegExpEpsilon&) const;
virtual bool operator<(const Concatenation&) const;
virtual bool operator<(const Iteration&) const;
virtual bool operator<(const RegExpSymbol&) const;
virtual bool operator==(const RegExpEpsilon&) const; virtual bool operator==(const RegExpEpsilon&) const;
/** /**
......
...@@ -26,7 +26,11 @@ RegExpElement* RegExpSymbol::plunder() && { ...@@ -26,7 +26,11 @@ RegExpElement* RegExpSymbol::plunder() && {
} }
   
bool RegExpSymbol::operator==(const alphabet::Symbol& other) const { bool RegExpSymbol::operator==(const alphabet::Symbol& other) const {
return *this == other; return (const alphabet::Symbol&) *this == other;
}
bool operator==(const alphabet::Symbol& first, const RegExpSymbol& second) {
return first == (const alphabet::Symbol&) second;
} }
   
bool RegExpSymbol::operator<(const RegExpElement& other) const { bool RegExpSymbol::operator<(const RegExpElement& other) const {
...@@ -42,18 +46,6 @@ bool RegExpSymbol::operator>(const RegExpElement& other) const { ...@@ -42,18 +46,6 @@ bool RegExpSymbol::operator>(const RegExpElement& other) const {
} }
   
   
bool RegExpSymbol::operator<(const Concatenation&) const {
return true;
}
bool RegExpSymbol::operator<(const Alternation&) const {
return true;
}
bool RegExpSymbol::operator<(const Iteration&) const {
return true;
}
bool RegExpSymbol::operator<(const RegExpSymbol& other) const { bool RegExpSymbol::operator<(const RegExpSymbol& other) const {
return this->symbol < other.symbol; return this->symbol < other.symbol;
} }
......
...@@ -44,15 +44,13 @@ public: ...@@ -44,15 +44,13 @@ public:
RegExpSymbol(const std::string& symbol); RegExpSymbol(const std::string& symbol);
RegExpSymbol(std::string&& symbol); RegExpSymbol(std::string&& symbol);
virtual bool operator==(const alphabet::Symbol&) const; bool operator==(const alphabet::Symbol&) const;
friend bool operator==(const alphabet::Symbol&, const RegExpSymbol&);
   
virtual bool operator<(const RegExpElement&) const; virtual bool operator<(const RegExpElement&) const;
virtual bool operator==(const RegExpElement&) const; virtual bool operator==(const RegExpElement&) const;
virtual bool operator>(const RegExpElement&) const; virtual bool operator>(const RegExpElement&) const;
   
virtual bool operator<(const Concatenation&) const;
virtual bool operator<(const Alternation&) const;
virtual bool operator<(const Iteration&) const;
virtual bool operator<(const RegExpSymbol&) const; virtual bool operator<(const RegExpSymbol&) const;
virtual bool operator==(const RegExpSymbol&) const; virtual bool operator==(const RegExpSymbol&) const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment