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 merge requests found
......@@ -11,15 +11,46 @@ const char* StrSet::type_name = "StrSet";
std::string StrSet::to_raw_string() const
{
std::stringstream ss;
ss << "{";
bool comma = false;
foreach (const UnicodeString& u, set_) {
if (comma) {
ss << ",";
ss << "[";
set_t::const_iterator it = set_.begin();
while(it != set_.end()) {
ss << '\"' << PwrNlp::to_utf8(*it) << '\"'; //TODO escaping
if(++it != set_.end()) {
ss << ", ";
}
ss << '\"' << PwrNlp::to_utf8(u) << '\"'; //TODO escaping
}
ss << "]";
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 */
......@@ -56,19 +56,12 @@ public:
return set_.empty();
}
bool is_subset_of(const StrSet& /*set*/) const {
//TODO: implement this
return false;
}
bool is_subset_of(const StrSet& other) const;
bool intersects(const StrSet& /*set*/) const {
//TODO: implement this
return false;
}
bool intersects(const StrSet& other) const;
bool equals(const StrSet& /*set*/) const {
//TODO: implement this
return false;
bool equals(const StrSet& other) const {
return set_ == other.set_;
}
/// Value override
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment