当前位置: 首页>>代码示例>>C#>>正文


C# Set.Copy方法代码示例

本文整理汇总了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);
        }
开发者ID:gregorypilar,项目名称:interlace,代码行数:54,代码来源:TestSet.cs

示例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;
        }
开发者ID:jmahmud,项目名称:RDFer,代码行数:58,代码来源:Extend.cs


注:本文中的Set.Copy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。