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


C# Set.Remove方法代码示例

本文整理汇总了C#中Set.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# Set.Remove方法的具体用法?C# Set.Remove怎么用?C# Set.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Set的用法示例。


在下文中一共展示了Set.Remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        public static void Main()
        {
            var set1 = new Set<string>();
            var set2 = new Set<string>();

            set1.Add("one");
            set1.Add("two");
            set1.Add("three");

            set2.Add("three");
            set2.Add("four");

            Console.WriteLine(set1);
            Console.WriteLine(set2);

            Console.WriteLine(set1.Intersect(set2));
            Console.WriteLine(set2.Intersect(set1));

            Console.WriteLine(set1.Union(set2));
            Console.WriteLine(set2.Union(set1));

            set1.Remove("five");
            set1.Remove("two");
            Console.WriteLine(set1);

            Console.WriteLine(set1.Find("one"));
            Console.WriteLine(set1.Find("two"));

            Console.WriteLine(set1.Count);
        }
开发者ID:g-yonchev,项目名称:Data-Structures-and-Algorithms-Homework,代码行数:30,代码来源:Testing.cs

示例2: ShouldRemove

 public void ShouldRemove()
 {
     var collection = new Set<string>();
     collection.Add("1");
     collection.Add("2");
     collection.Remove("1");
     collection.Remove(null);
     Assert.AreEqual(1, collection.Count);
     Assert.AreEqual("2", collection.First());
 }
开发者ID:p69,项目名称:magellan-framework,代码行数:10,代码来源:SetTests.cs

示例3: Remove

 public void Remove()
 {
     Set<string> set = new Set<string>();
       set.Add("olof");
       set.Add("bjarnason");
       set.Remove("djdi");
       Assert.AreEqual(2, set.Count);
       set.Remove("olof");
       Assert.AreEqual(1, set.Count);
       Assert.IsTrue(set.Contains("bjarnason"));
 }
开发者ID:Felixdev,项目名称:dogfight2008,代码行数:11,代码来源:SetFixture.cs

示例4: ShouldRemoveElementsCorrectly

 public void ShouldRemoveElementsCorrectly()
 {
     var set = new Set<int>();
     set.Add(5);
     Assert.AreEqual(1, set.Count);
     set.Remove(5);
     Assert.AreEqual(0, set.Count);
 }
开发者ID:Vyara,项目名称:Telerik-Academy,代码行数:8,代码来源:SetTests.cs

示例5: gibbsAsk

        // function GIBBS-ASK(X, e, bn, N) returns an estimate of <b>P</b>(X|e)
        /**
         * The GIBBS-ASK algorithm in Figure 14.16. For answering queries given
         * evidence in a Bayesian Network.
         * 
         * @param X
         *            the query variables
         * @param e
         *            observed values for variables E
         * @param bn
         *            a Bayesian network specifying joint distribution
         *            <b>P</b>(X<sub>1</sub>,...,X<sub>n</sub>)
         * @param Nsamples
         *            the total number of samples to be generated
         * @return an estimate of <b>P</b>(X|e)
         */

        public CategoricalDistribution gibbsAsk(RandomVariable[] X,
                                                AssignmentProposition[] e, BayesianNetwork bn, int Nsamples)
        {
            // local variables: <b>N</b>, a vector of counts for each value of X,
            // initially zero
            double[] N = new double[ProbUtil
                .expectedSizeOfCategoricalDistribution(X)];
            // Z, the nonevidence variables in bn
            Set<RandomVariable> Z = new Set<RandomVariable>(
                bn.getVariablesInTopologicalOrder());
            foreach (AssignmentProposition ap in e)
            {
                Z.Remove(ap.getTermVariable());
            }
            // <b>x</b>, the current state of the network, initially copied from e
            Map<RandomVariable, Object> x = new LinkedHashMap<RandomVariable, Object>();
            foreach (AssignmentProposition ap in e)
            {
                x.Add(ap.getTermVariable(), ap.getValue());
            }

            // initialize <b>x</b> with random values for the variables in Z
            foreach (RandomVariable Zi in
            Z)
            {
                x.put(Zi, ProbUtil.randomSample(bn.getNode(Zi), x, randomizer));
            }

            // for j = 1 to N do
            for (int j = 0; j < Nsamples; j++)
            {
                // for each Z<sub>i</sub> in Z do
                foreach (RandomVariable Zi in
                Z)
                {
                    // set the value of Z<sub>i</sub> in <b>x</b> by sampling from
                    // <b>P</b>(Z<sub>i</sub>|mb(Z<sub>i</sub>))
                    x.put(Zi,
                          ProbUtil.mbRandomSample(bn.getNode(Zi), x, randomizer));
                }
                // Note: moving this outside the previous for loop,
                // as described in fig 14.6, as will only work
                // correctly in the case of a single query variable X.
                // However, when multiple query variables, rare events
                // will get weighted incorrectly if done above. In case
                // of single variable this does not happen as each possible
                // value gets * |Z| above, ending up with the same ratios
                // when normalized (i.e. its still more efficient to place
                // outside the loop).
                //
                // <b>N</b>[x] <- <b>N</b>[x] + 1
                // where x is the value of X in <b>x</b>
                N[ProbUtil.indexOf(X, x)] += 1.0;
            }
            // return NORMALIZE(<b>N</b>)
            return new ProbabilityTable(N, X).normalize();
        }
开发者ID:PaulMineau,项目名称:AIMA.Net,代码行数:74,代码来源:GibbsAsk.cs

示例6: RemoveTest

 public void RemoveTest()
 {
     Set<int> set = new Set<int>();
     set.Add(1);
     set.Add(2);
     set.Remove(1);
     Assert.IsFalse(set.Contains(1));
     Assert.IsTrue(set.Contains(2));
 }
开发者ID:Kirill-Andreev,项目名称:University,代码行数:9,代码来源:SetTest.cs

示例7: AddRemoveElements

        public void AddRemoveElements()
        {
            var set = new Set<int>(2, 4, 6, 8, 10);

            Assert.AreEqual("{2,4,6,8,10}", set.ToString());

            set.Add(1, 3, 5, 7, 9);
            
            Assert.AreEqual("{2,4,6,8,10,1,3,5,7,9}", set.ToString());

            set.Remove(9);
            
            Assert.AreEqual("{2,4,6,8,10,1,3,5,7}", set.ToString());
        }
开发者ID:furesoft,项目名称:Mathos-Project,代码行数:14,代码来源:SetTest.cs

示例8: AddRemoveElements

        public void AddRemoveElements()
        {
            var set = new Set<int>(2, 4, 6, 8, 10);

            Console.WriteLine(set.ToString());

            set.Add(1, 3, 5, 7, 9);

            Console.WriteLine(set.ToString());

            set.Remove(9);

            Console.WriteLine(set.ToString());
        }
开发者ID:rodriada000,项目名称:Mathos-Project,代码行数:14,代码来源:SetTest.cs

示例9: SwitchFlips

 void SwitchFlips() {
     var queued = new Set<Polyline>(Polylines);
     var queue = new Queue<Polyline>();
     foreach (Polyline e in Polylines)
         queue.Enqueue(e);
     while (queue.Count > 0) {
         Polyline initialPolyline = queue.Dequeue();
         queued.Remove(initialPolyline);
         Polyline changedPolyline = ProcessPolyline(initialPolyline);
         if (changedPolyline != null) {
             //we changed both polylines
             if (!queued.Contains(initialPolyline)) {
                 queued.Insert(initialPolyline);
                 queue.Enqueue(initialPolyline);
             }
             if (!queued.Contains(changedPolyline)) {
                 queued.Insert(changedPolyline);
                 queue.Enqueue(changedPolyline);
             }
         }
     }
 }
开发者ID:danielskowronski,项目名称:network-max-flow-demo,代码行数:22,代码来源:FlipSwitcher.cs

示例10: Main

        static void Main(string[] args)
        {
            Set<TestClass> mySet = new Set<TestClass>();
            HashSet<TestClass> systemSet = new HashSet<TestClass>();

            for (int i = 0; i < 10000000; i++)
            {
                TestClass a = new TestClass(rand.Next(0, 100));
                mySet.Add(a);
                systemSet.Add(a);

                TestClass b = new TestClass(rand.Next(0, 100));
                mySet.Remove(b);
                systemSet.Remove(b);
            }

            TestClass[] systemSetArray = systemSet.ToArray();
            Array.Sort(systemSetArray);

            TestClass[] mySetArray = mySet.ToArray();

            Console.WriteLine(systemSetArray.SequenceEqual(mySetArray) ?
                "test passed" : "test failed");
        }
开发者ID:VladasZ,项目名称:Homework,代码行数:24,代码来源:Program.cs

示例11: HasCycles

        internal bool HasCycles(Point rootPoint) {
            var visited = new Set<Point>();
            var parent = new Dictionary<Point, Point>();

            var rp = AddVisGraphVertex(rootPoint);
            visited.Insert(rp);
            parent[rp] = rp;

            var queue = new List<Point> {rp};

            while (queue.Any()) {
                var p = queue.First();
                queue.Remove(p);

                var v = _visGraph.FindVertex(p);
                var neighb = new Set<Point>();
                neighb.InsertRange(v.OutEdges.Select(e => e.TargetPoint));
                neighb.InsertRange(v.InEdges.Select(e => e.SourcePoint));
                neighb.Remove(parent[p]);

                foreach (var q in neighb) {
                    parent[q] = p;
                    if (visited.Contains(q)) return true;
                    visited.Insert(q);
                    queue.Add(q);
                }
            }

            return false;
        }
开发者ID:danielskowronski,项目名称:network-max-flow-demo,代码行数:30,代码来源:LgPathRouter.cs

示例12: AsCql

        /// <summary>
        ///     Given a set of positive <paramref name="constants" /> generates a simplified negated constant Cql expression.
        ///     Examples:
        ///     - 7, NOT(7, NULL) means NOT(NULL)
        ///     - 7, 8, NOT(7, 8, 9, 10) means NOT(9, 10)
        /// </summary>
        private void AsCql(
            Action trueLiteral, Action varIsNotNull, Action<Constant> varNotEqualsTo, IEnumerable<Constant> constants,
            MemberPath outputMember, bool skipIsNotNull)
        {
            var isNullable = outputMember.IsNullable;
            // Remove all the constants from negated and then print "x <> C1 .. AND x <> C2 .. AND x <> C3 ..."
            var negatedConstants = new Set<Constant>(Elements, EqualityComparer);
            foreach (var constant in constants)
            {
                if (constant.Equals(this))
                {
                    continue;
                }
                Debug.Assert(negatedConstants.Contains(constant), "Negated constant must contain all positive constants");
                negatedConstants.Remove(constant);
            }

            if (negatedConstants.Count == 0)
            {
                // All constants cancel out - emit True.
                trueLiteral();
            }
            else
            {
                var hasNull = negatedConstants.Contains(Null);
                negatedConstants.Remove(Null);

                // We always add IS NOT NULL if the property is nullable (and we cannot skip IS NOT NULL).
                // Also, if the domain contains NOT NULL, we must add it.

                if (hasNull || (isNullable && !skipIsNotNull))
                {
                    varIsNotNull();
                }

                foreach (var constant in negatedConstants)
                {
                    varNotEqualsTo(constant);
                }
            }
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:47,代码来源:NegatedConstant.cs

示例13: ToUserString

        internal void ToUserString(bool invertOutput, StringBuilder builder, MetadataWorkspace workspace)
        {
            // If there is a negated cell constant, get the inversion of the domain
            NegatedConstant negatedConstant = null;
            foreach (Constant constant in Domain.Values)
            {
                negatedConstant = constant as NegatedConstant;
                if (negatedConstant != null)
                {
                    break;
                }
            }

            Set<Constant> constants;
            if (negatedConstant != null)
            {
                // Invert the domain and invert "invertOutput"
                invertOutput = !invertOutput;
                // Add all the values to negatedConstant's values to get the
                // final set of constants
                constants = new Set<Constant>(negatedConstant.Elements, Constant.EqualityComparer);
                foreach (Constant constant in Domain.Values)
                {
                    if (!(constant is NegatedConstant))
                    {
                        Debug.Assert(constants.Contains(constant), "Domain of negated constant does not have positive constant");
                        constants.Remove(constant);
                    }
                }
            }
            else
            {
                constants = new Set<Constant>(Domain.Values, Constant.EqualityComparer);
            }

            // Determine the resource to use
            Debug.Assert(constants.Count > 0, "one of const is false?");
            bool isNull = constants.Count == 1 && constants.Single().IsNull();
            bool isTypeConstant = this is TypeRestriction;

            Func<object, string> resourceName0 = null;
            Func<object, object, string> resourceName1 = null;

            if (invertOutput)
            {
                if (isNull)
                {
                    resourceName0 = isTypeConstant ? (Func<object, string>)Strings.ViewGen_OneOfConst_IsNonNullable : (Func<object, string>)Strings.ViewGen_OneOfConst_MustBeNonNullable;
                }
                else if (constants.Count == 1)
                {
                    resourceName1 = isTypeConstant ? (Func<object, object, string>)Strings.ViewGen_OneOfConst_IsNotEqualTo : (Func<object, object, string>)Strings.ViewGen_OneOfConst_MustNotBeEqualTo;
                }
                else
                {
                    resourceName1 = isTypeConstant ? (Func<object, object, string>)Strings.ViewGen_OneOfConst_IsNotOneOf : (Func<object, object, string>)Strings.ViewGen_OneOfConst_MustNotBeOneOf;
                }
            }
            else
            {
                if (isNull)
                {
                    resourceName0 = isTypeConstant ? (Func<object, string>)Strings.ViewGen_OneOfConst_MustBeNull : (Func<object, string>)Strings.ViewGen_OneOfConst_MustBeNull;
                }
                else if (constants.Count == 1)
                {
                    resourceName1 = isTypeConstant ? (Func<object, object, string>)Strings.ViewGen_OneOfConst_IsEqualTo : (Func<object, object, string>)Strings.ViewGen_OneOfConst_MustBeEqualTo;
                }
                else
                {
                    resourceName1 = isTypeConstant ? (Func<object, object, string>)Strings.ViewGen_OneOfConst_IsOneOf : (Func<object, object, string>)Strings.ViewGen_OneOfConst_MustBeOneOf;
                }
            }

            // Get the constants
            StringBuilder constantBuilder = new StringBuilder();
            Constant.ConstantsToUserString(constantBuilder, constants);

            Debug.Assert((resourceName0 == null) != (resourceName1 == null),
                         "Both resources must not have been set or be null");
            string variableName = m_restrictedMemberSlot.MemberPath.PathToString(false);
            if (isTypeConstant)
            {
                variableName = "TypeOf(" + variableName + ")";
            }

            if (resourceName0 != null)
            {
                builder.Append(resourceName0(variableName));
            }
            else
            {
                builder.Append(resourceName1(variableName, constantBuilder.ToString()));
            }

            if (invertOutput && isTypeConstant)
            {
                InvertOutputStringForTypeConstant(builder, constants, workspace);
            }
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:100,代码来源:MemberRestriction.cs

示例14: processGoal

        internal Set<CompoundTerm> processGoal(ModelProgram mp, Set<CompoundTerm> goals)
        {
            Set<CompoundTerm> processedGoals = Set<CompoundTerm>.EmptySet;
            if (typeof(LibraryModelProgram) == mp.GetType())
            {
                //we ignore it for the moment
                Console.Error.WriteLine("Goals involving LibraryModelPrograms currently not supported. ");
                Console.Error.WriteLine("Currently searching for a match for '" + goals.ToString() + "'. ");
            }
            else if (typeof(FsmModelProgram) == mp.GetType()) {
                FsmModelProgram fsm = (FsmModelProgram)mp;
                foreach (CompoundTerm ct in goals)
                {
                    Console.WriteLine("Checking FSM: " + ct.ToString() + "; " + fsm.Name);
                    if (ct.FunctionSymbol.ToString() == fsm.Name) {
                        processedGoals = processedGoals.Add(CompoundTerm.Parse("FsmState(Set(" + ct.Arguments[0].ToString() + "))"));
                        goals = goals.Remove(ct);
                    }
                    Console.WriteLine("Current processedGoals: " + processedGoals.ToString());
                }

            }
            else if (typeof(ProductModelProgram) == mp.GetType())
            {
                ProductModelProgram pmp = (ProductModelProgram)mp;
                processedGoals = processedGoals.Union(processGoal(pmp.M1,goals));
                processedGoals = processedGoals.Union(processGoal(pmp.M2,goals));

            }
            return processedGoals;
        }
开发者ID:juhan,项目名称:NModel,代码行数:31,代码来源:Reachability.cs

示例15: MatchAndRemove

 /// <summary>
 /// If there is a node in remainingOthers which 'matches' item (in name and
 /// specified keys), remove and return it; otherwise return null.
 /// </summary>
 /// <param name="remainingOthers"></param>
 /// <param name="item"></param>
 /// <returns></returns>
 XmlNode MatchAndRemove(Set<XmlNode> remainingOthers, XmlNode target)
 {
     string elementName = target.Name;
     string[] keyAttrs = null;
     if (m_keyAttrs.ContainsKey(elementName))
         keyAttrs = m_keyAttrs[elementName];
     int ckeys = (keyAttrs == null ? 0 : keyAttrs.Length);
     string[] keyVals = new string[ckeys]; // keys to try to match for each item
     for (int i = 0; i < ckeys; i++)
         keyVals[i] = XmlUtils.GetOptionalAttributeValue(target, keyAttrs[i]);
     foreach (XmlNode item in remainingOthers)
     {
         if (item.Name != elementName)
             continue;
         // See if all the keys match
         int cMatchingAttrs = 0;
         for (; cMatchingAttrs < ckeys; cMatchingAttrs++)
         {
             if (XmlUtils.GetOptionalAttributeValue(item, keyAttrs[cMatchingAttrs]) != keyVals[cMatchingAttrs])
                 break;
         }
         if (cMatchingAttrs == ckeys)
         {
             // Full match!
             remainingOthers.Remove(item);
             return item;
         }
     }
     return null;
 }
开发者ID:sillsdev,项目名称:CarlaLegacy,代码行数:37,代码来源:Inventory.cs


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