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:
parent
f0067b6bbf
commit
aaa12450c0
3 changed files with 112 additions and 13 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue