本文整理汇总了C#中Set.Copy方法的典型用法代码示例。如果您正苦于以下问题:C# Set.Copy方法的具体用法?C# Set.Copy怎么用?C# Set.Copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Set
的用法示例。
在下文中一共展示了Set.Copy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SimpleValueTests
public void SimpleValueTests()
{
Set<int> empty = new Set<int>();
Set<int> a = new Set<int>(1, 2, 3);
Set<int> b = new Set<int>(3, 4, 5);
Set<int> a_and_b = a + b;
Assert.AreEqual("{}", empty.ToString());
Assert.AreEqual("{ 1, 2, 3 }", a.ToString());
Assert.AreEqual("{ 3, 4, 5 }", b.ToString());
Assert.AreEqual("{ 1, 2, 3, 4, 5 }", a_and_b.ToString());
Assert.AreEqual("{}", (empty * a).ToString());
Assert.AreEqual("{}", (a * empty).ToString());
Assert.IsTrue(a_and_b * a == a);
Assert.IsTrue((a_and_b * a).Equals(a));
Assert.IsTrue(a_and_b - a == new Set<int>(4, 5));
Assert.IsTrue(a - a == new Set<int>());
Assert.IsTrue(a * a == a);
Assert.IsTrue(a.IsSubsetOf(a_and_b));
Assert.IsTrue(b.IsSubsetOf(a_and_b));
Assert.IsTrue(a_and_b.IsSubsetOf(a_and_b));
Assert.IsTrue(a.IsSubsetOf(a));
Assert.IsTrue(b.IsSubsetOf(b));
Assert.IsFalse(a.IsSubsetOf(b));
Assert.IsFalse(b.IsSubsetOf(a));
Assert.IsFalse(a_and_b.IsSubsetOf(a));
Assert.IsFalse(a_and_b.IsSubsetOf(b));
Set<int> a_copy = a.Copy();
Set<int> b_copy = b.Copy();
a.UnionUpdate(b);
Assert.AreEqual(a, a_and_b);
a.DifferenceUpdate(b);
Assert.AreEqual(a, a_and_b - b);
a.UnionUpdate(9);
Assert.AreEqual(a, (a_and_b - b) + new Set<int>(9));
a.DifferenceUpdate(1);
Assert.AreEqual(a, (a_and_b - b) + new Set<int>(9) - new Set<int>(1));
a_copy.IntersectionUpdate(b_copy);
Assert.AreEqual(new Set<int>(3), a_copy);
}
示例2: Evaluate
/// <summary>
/// Evaluates the Algebra in the given context
/// </summary>
/// <param name="context">Evaluation Context</param>
/// <returns></returns>
public BaseMultiset Evaluate(SparqlEvaluationContext context)
{
//First evaluate the inner algebra
BaseMultiset results = context.Evaluate(this._inner);
context.OutputMultiset = new Multiset();
if (results is NullMultiset)
{
context.OutputMultiset = results;
}
else if (results is IdentityMultiset)
{
context.OutputMultiset.AddVariable(this._var);
Set s = new Set();
try
{
INode temp = this._expr.Evaluate(context, 0);
s.Add(this._var, temp);
}
catch
{
//No assignment if there's an error
s.Add(this._var, null);
}
context.OutputMultiset.Add(s.Copy());
}
else
{
if (results.ContainsVariable(this._var))
{
throw new RdfQueryException("Cannot use a BIND assigment to BIND to a variable that has previously been used in the Query");
}
context.OutputMultiset.AddVariable(this._var);
foreach (int id in results.SetIDs.ToList())
{
ISet s = results[id].Copy();
try
{
//Make a new assignment
INode temp = this._expr.Evaluate(context, id);
s.Add(this._var, temp);
}
catch
{
//No assignment if there's an error but the solution is preserved
}
context.OutputMultiset.Add(s);
}
}
return context.OutputMultiset;
}