Skip to content
Snippets Groups Projects
Commit fc92660c authored by Adam Wardyński's avatar Adam Wardyński
Browse files

equals, is_subset_of and intersects for StrSet, changing its to_raw_string to match spec in parser

parent 02c08af5
Branches
No related tags found
No related merge requests found
...@@ -11,15 +11,46 @@ const char* StrSet::type_name = "StrSet"; ...@@ -11,15 +11,46 @@ const char* StrSet::type_name = "StrSet";
std::string StrSet::to_raw_string() const std::string StrSet::to_raw_string() const
{ {
std::stringstream ss; std::stringstream ss;
ss << "{"; ss << "[";
bool comma = false; set_t::const_iterator it = set_.begin();
foreach (const UnicodeString& u, set_) { while(it != set_.end()) {
if (comma) { ss << '\"' << PwrNlp::to_utf8(*it) << '\"'; //TODO escaping
if(++it != set_.end()) {
ss << ", "; ss << ", ";
} }
ss << '\"' << PwrNlp::to_utf8(u) << '\"'; //TODO escaping
} }
ss << "]";
return ss.str(); return ss.str();
} }
bool StrSet::intersects(const StrSet &other) const {
if(empty() || other.empty()) {
return false;
}
//we just want to check if there is an intersection, no
//need to actually compute it to check if it's empty.
//doing it like below sounds faster than, say, sorting
//the sets and using set_intersection
const set_t& smaller = size() < other.size() ? set_ : other.set_;
const set_t& bigger = size() < other.size() ? other.set_ : set_;
foreach (const UnicodeString& u, smaller) {
if(bigger.find(u) != bigger.end()) {
return true;
}
}
return false;
}
bool StrSet::is_subset_of(const StrSet &other) const {
if(empty() || size() > other.size()) {
return false;
}
foreach (const UnicodeString& u, set_) {
if(other.set_.find(u) == other.set_.end()) {
return false;
}
}
return true;
}
} /* end ns Wccl */ } /* end ns Wccl */
...@@ -56,19 +56,12 @@ public: ...@@ -56,19 +56,12 @@ public:
return set_.empty(); return set_.empty();
} }
bool is_subset_of(const StrSet& /*set*/) const { bool is_subset_of(const StrSet& other) const;
//TODO: implement this
return false;
}
bool intersects(const StrSet& /*set*/) const { bool intersects(const StrSet& other) const;
//TODO: implement this
return false;
}
bool equals(const StrSet& /*set*/) const { bool equals(const StrSet& other) const {
//TODO: implement this return set_ == other.set_;
return false;
} }
/// Value override /// Value override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment