Implement set-theoretic methods in std::set C# typemaps

These implementations are not optimized, i.e. are done in a naive way in
C#, rather than using C++ functions more efficiently, but are better
than nothing.
This commit is contained in:
Vadim Zeitlin 2019-03-11 23:05:10 +01:00
commit aaa12450c0
3 changed files with 112 additions and 13 deletions

View file

@ -71,16 +71,84 @@ class set {
}
}
public void ExceptWith(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) { throw new global::System.Exception("TODO"); }
public void IntersectWith(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) { throw new global::System.Exception("TODO"); }
public bool IsProperSubsetOf(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) { throw new global::System.Exception("TODO"); }
public bool IsProperSupersetOf(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) { throw new global::System.Exception("TODO"); }
public bool IsSubsetOf(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) { throw new global::System.Exception("TODO"); }
public bool IsSupersetOf(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) { throw new global::System.Exception("TODO"); }
public bool Overlaps(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) { throw new global::System.Exception("TODO"); }
public bool SetEquals(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) { throw new global::System.Exception("TODO"); }
public void SymmetricExceptWith(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) { throw new global::System.Exception("TODO"); }
public void UnionWith(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) { throw new global::System.Exception("TODO"); }
public void ExceptWith(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) {
foreach ($typemap(cstype, T) item in other) {
Remove(item);
}
}
public void IntersectWith(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) {
$csclassname old = new $csclassname(this);
Clear();
foreach ($typemap(cstype, T) item in other) {
if (old.Contains(item))
Add(item);
}
}
private static int count_enum(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) {
int count = 0;
foreach ($typemap(cstype, T) item in other) {
count++;
}
return count;
}
public bool IsProperSubsetOf(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) {
return IsSubsetOf(other) && Count < count_enum(other);
}
public bool IsProperSupersetOf(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) {
return IsSupersetOf(other) && Count > count_enum(other);
}
public bool IsSubsetOf(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) {
int countContained = 0;
foreach ($typemap(cstype, T) item in other) {
if (Contains(item))
countContained++;
}
return countContained == Count;
}
public bool IsSupersetOf(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) {
foreach ($typemap(cstype, T) item in other) {
if (!Contains(item))
return false;
}
return true;
}
public bool Overlaps(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) {
foreach ($typemap(cstype, T) item in other) {
if (Contains(item))
return true;
}
return false;
}
public bool SetEquals(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) {
return IsSupersetOf(other) && Count == count_enum(other);
}
public void SymmetricExceptWith(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) {
foreach ($typemap(cstype, T) item in other) {
if (!Remove(item))
Add(item);
}
}
public void UnionWith(global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)> other) {
foreach ($typemap(cstype, T) item in other) {
Add(item);
}
}
private global::System.Collections.Generic.ICollection<$typemap(cstype, T)> Items {
get {