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


C# HashSet.Union方法代码示例

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


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

示例1: Generate

        public string Generate(Board _board, GameUnit _unit, GameUnit _finishUnit)
        {
            var stringBuilder = new StringBuilder();
            var words = MagicWordsStore.Words
                                       .Concat(SpecialWords)
                                       .ToArray();
            var usedUnits = new HashSet<GameUnit>();
            while (!_unit.Equals(_finishUnit))
            {
                if (TimeLimiter.NeedStop())
                    break;

                foreach (var powerWord in words.OrderByDescending(x => x.Length))
                {
                    if (TimeLimiter.NeedStop())
                        break;

                    var newlyUsedUnits = new HashSet<GameUnit>();
                    var currentUnit = _unit;
                    var fail = false;
                    for (var i = 0; i < powerWord.Length; ++i)
                    {
                        var command = powerWord[i];
                        newlyUsedUnits.Add(currentUnit);
                        var nextUnit = currentUnit.MakeStep(CommandConverter.Convert(command));
                        var locked = !_board.IsValid(nextUnit);
                        if (newlyUsedUnits.Contains(nextUnit) ||
                            usedUnits.Contains(nextUnit) ||
                            (locked && i < powerWord.Length - 1) ||
                            (locked && !nextUnit.Equals(_finishUnit)))
                        {
                            fail = true;
                            break;
                        }
                        if (!locked)
                        {
                            currentUnit = nextUnit;
                        }
                    }
                    var allUsedUnits = new HashSet<GameUnit>(usedUnits.Union(newlyUsedUnits));
                    if (!fail && ReachableStatesGetter.CanReach(_board, currentUnit, false, allUsedUnits, _finishUnit))
                    {
                        _unit = currentUnit;
                        usedUnits = allUsedUnits;
                        stringBuilder.Append(powerWord);
                        break;
                    }
                }
            }
            foreach (var command in Enum.GetValues(typeof(Command)).Cast<Command>().Except(new[] { Command.Empty }))
            {
                if (!_board.IsValid(_unit.MakeStep(command)))
                {
                    stringBuilder.Append(CommandConverter.CovertToAnyChar(command));
                    break;
                }
            }
            return stringBuilder.ToString();
        }
开发者ID:Erop147,项目名称:ICFPC_2015,代码行数:59,代码来源:GreedyPowerWordCommandStringGenerator.cs

示例2: simularity

        public static double simularity(HashSet<string> setA, HashSet<string> setB)
        {
            double interCount = setA.Intersect(setB).Count();
            if (interCount == 0) return 0;

            double unionCount = setA.Union(setB).Count();
            return interCount / unionCount;
        }
开发者ID:hyunjong-lee,项目名称:yes64,代码行数:8,代码来源:NPMIEngine.cs

示例3: GetTransitiveClosure

        private IEnumerable<string> GetTransitiveClosure(string state)
        {
            var result = new HashSet<string> { state };
            while (result.Union(result.SelectMany(s => GetTransitions(s, null))).Distinct().Count() != result.Count)
            {
                result.SelectMany(s => GetTransitions(s, null)).ToArray().ForEach(s => result.Add(s));
            }

            return result;
        }
开发者ID:oliverhanappi,项目名称:computation,代码行数:10,代码来源:FiniteAutomaton.cs

示例4: ResolveControllerType

        public static Type ResolveControllerType(string areaName, string controllerName)
        {
            // controller type to find and return
            Type controllerType;

            // is the type cached?
            var cacheKey = areaName + "_" + controllerName;
            if (cache.TryGetValue(cacheKey, out controllerType))
                return cache[cacheKey];

            lock (syncLock)
            {
                if (cache.TryGetValue(cacheKey, out controllerType))
                    return controllerType;

                // find controller details
                IEnumerable<string> areaNamespaces = FindNamespacesForArea(areaName, RouteTable.Routes);

                var area = areaName;
                var controller = controllerName;
                var controllerBuilder = ControllerBuilder.Current;

                // Find controller type
                HashSet<string> namespaces = null;
                if (areaNamespaces != null)
                {
                    areaNamespaces = (from ns in areaNamespaces
                                      where ns != "Elmah.Mvc"
                                      select ns).ToList();
                    if (areaNamespaces.Any())
                    {
                        namespaces = new HashSet<string>(areaNamespaces, StringComparer.OrdinalIgnoreCase);
                        if (string.IsNullOrEmpty(areaName))
                        {
                            namespaces = new HashSet<string>(
                                namespaces.Union(controllerBuilder.DefaultNamespaces, StringComparer.OrdinalIgnoreCase),
                                StringComparer.OrdinalIgnoreCase
                            );
                        }
                    }
                }
                else if (controllerBuilder.DefaultNamespaces.Count > 0)
                {
                    namespaces = controllerBuilder.DefaultNamespaces;
                }
                controllerType = GetControllerTypeWithinNamespaces(area, controller, namespaces);

                // Cache the result
                cache.Add(cacheKey, controllerType);

                // Return
                return controllerType;
            }
        }
开发者ID:ghost1face,项目名称:Mvc5SiteMapBuilder,代码行数:54,代码来源:ControllerTypeResolver.cs

示例5: Main

        public static void Main(string[] args)
        {
            HashSet<int> first = new HashSet<int>();
            first.Add(1);
            first.Add(2);
            first.Add(3);

            Console.Write("First set: ");
            foreach (var item in first)
            {
                Console.Write(item.Key + " ");
            }

            Console.WriteLine();

            HashSet<int> second = new HashSet<int>();
            second.Add(4);
            second.Add(1);
            second.Remove(1);

            Console.Write("Second set: ");
            foreach (var item in second)
            {
                Console.Write(item.Key + " ");
            }

            Console.WriteLine();

            first.Union(second);

            Console.Write("Sets union: ");
            foreach (var item in first)
            {
                Console.Write(item.Key + " ");
            }

            Console.WriteLine();

            //second.Add(1);

            first.Intersect(second);

            Console.Write("Sets intersection: ");
            foreach (var item in first)
            {
                Console.Write(item.Key + " ");
            }

            Console.WriteLine();
        }
开发者ID:kalinnikol,项目名称:TelerikAcademy-1,代码行数:50,代码来源:HashSetDemo.cs

示例6: Main

        public static void Main()
        {
            var firstSet = new HashSet<int>();
            var secondSet = new HashSet<int>();
            firstSet.Add(1);
            firstSet.Add(2);
            firstSet.Add(7);
            secondSet.Add(7);
            secondSet.Add(13);
            secondSet.Add(19);
            firstSet.Remove(2);

            var unionSet = firstSet.Union(secondSet);
            Console.WriteLine("Union set = {0}", unionSet);

            var intersectSet = firstSet.Intersect(secondSet);
            Console.WriteLine("Intersect set = {0}", intersectSet);
        }
开发者ID:emilti,项目名称:Telerik-Academy-My-Courses,代码行数:18,代码来源:MainProgram.cs

示例7: Main

        static void Main(string[] args)
        {
            HashSet<string> hashSet = new HashSet<string>();

            hashSet.Add("ooo");
            hashSet.Add("qqq");
            hashSet.Add("ppp");
            hashSet.Add("iii");

            foreach (var item in hashSet.Items)
            {
                Console.WriteLine(item);
            }

            hashSet.Remove("iii");
            Console.WriteLine("\nCount after removal: {0}", hashSet.Count);


            Console.WriteLine();
            Console.WriteLine(hashSet.Find("ppp"));


            HashSet<string> secondHashSet = new HashSet<string>();
            secondHashSet.Add("www");
            secondHashSet.Add("qqq");
            secondHashSet.Add("yyy");
            secondHashSet.Add("ooo");

            Console.WriteLine("\nUnion: ");
            HashSet<string> union = hashSet.Union(secondHashSet);
            foreach (var item in union.Items)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("\nIntersection: ");
            HashSet<string> intersection = hashSet.Intersect(secondHashSet);
            foreach (var item in intersection.Items)
            {
                Console.WriteLine(item);
            }
        }
开发者ID:Dyno1990,项目名称:TelerikAcademy-1,代码行数:42,代码来源:SetImplementation.cs

示例8: findSubsetIndices

 // Needs sorted data!
 private static HashSet<List<int>> findSubsetIndices(int sum, int[] data)
 {
     HashSet<List<int>> results = new HashSet<List<int>>();
     int tsum = sum;
     List<int> indicies = new List<int>();
     for (int i = data.Length - 1; i >= 0; --i)
     {
         if (data[i] <= tsum)
         {
             tsum -= data[i];
             indicies.Add(i);
         }
         if (tsum == 0)
         {
             results = new HashSet<List<int>>(results.Union(findSubsetIndices(sum, data, indicies)));
             i = indicies.ElementAt(0);
             indicies = new List<int>();
             tsum = sum;
         }
     }
     return results;
 }
开发者ID:jbondhus,项目名称:Subset-Sum,代码行数:23,代码来源:SubsetSum.cs

示例9: Main

        static void Main(string[] args)
        {
            int NewNumber = 10000000;

            int[] FirstArray = new int[NewNumber];

            int[] SecondArray = new int[NewNumber];

            int[] ThirdArray = new int[NewNumber];

            FirstArray[0] = 1;

            SecondArray[0] = 2;

            ThirdArray[0] = 2;

            for (int i = 1; i < NewNumber; i++)
            {
                FirstArray[i] = 2 * FirstArray[i - 1] + 3;
                SecondArray[i] = 3 * SecondArray[i - 1] + 1;
                ThirdArray[i] = 2 * ThirdArray[i - 1] - 1;
            }

            HashSet<int> hash1 = new HashSet<int>(FirstArray);

            HashSet<int> hash2 = new HashSet<int>(SecondArray);

            HashSet<int> hash3 = new HashSet<int>(ThirdArray);

            HashSet<int> Union1 = new HashSet<int>(hash1.Union(hash2));

            HashSet<int> Union2 = new HashSet<int>(hash2.Intersect(hash3));

            foreach (var item in Union2)
            {
                Console.WriteLine(item);
            }
        }
开发者ID:giorgosrevis,项目名称:C-Homeworks,代码行数:38,代码来源:Program.cs

示例10: Main

        static void Main(string[] args)
        {
            int number = 100000;

           
            int[] arr1 = new int[number];
            int[] arr2 = new int[number];
            int[] arr3 = new int[number];

            arr1[0] = 1;
            arr2[0] = 2;
            arr3[0] = 2;

            for (int i = 1; i < number; i++)
            {
                arr1[i] = 2 * arr1[i - 1] + 3;
                arr2[i] = 3 * arr2[i - 1] + 1;
                arr3[i] = 2 * arr3[i - 1] - 1;
            }

            HashSet<int> hash1 = new HashSet<int>(arr1);
            HashSet<int> hash2 = new HashSet<int>(arr2);
            HashSet<int> hash3 = new HashSet<int>(arr3);
            HashSet<int> Union1 = new HashSet<int>(hash1.Union(hash2)); 
            HashSet<int> Union2 = new HashSet<int>(hash2.Intersect(hash3));


        

            foreach (var item in Union2)
            {
                Console.WriteLine(item);
            }


        }
开发者ID:cologneto,项目名称:.NETCourseHomeworks,代码行数:36,代码来源:Program.cs

示例11: ResolveControllerType

        /// <summary>
        /// Resolves the type of the controller.
        /// </summary>
        /// <param name="areaName">Name of the area.</param>
        /// <param name="controllerName">Name of the controller.</param>
        /// <returns>Controller type</returns>
        public Type ResolveControllerType(string areaName, string controllerName)
        {
            // Is the type cached?
            string cacheKey = areaName + "_" + controllerName;
            if (Cache.ContainsKey(cacheKey))
            {
                return Cache[cacheKey];
            }

            // Find controller details
            IEnumerable<string> areaNamespaces = FindNamespacesForArea(areaName, this.routes);

            string area = areaName;
            string controller = controllerName;

            // Find controller type
            Type controllerType;
            HashSet<string> namespaces = null;
            if (areaNamespaces != null)
            {
                areaNamespaces = (from ns in areaNamespaces
                                  where ns != "Elmah.Mvc"
                                  where !this.areaNamespacesToIgnore.Contains(ns)
                                  select ns).ToList();
                if (areaNamespaces.Any())
                {
                    namespaces = new HashSet<string>(areaNamespaces, StringComparer.OrdinalIgnoreCase);
                    if (string.IsNullOrEmpty(areaName))
                    {
                        namespaces = new HashSet<string>(namespaces.Union(this.controllerBuilder.DefaultNamespaces, StringComparer.OrdinalIgnoreCase), StringComparer.OrdinalIgnoreCase);
                    }
                }
            }
            else if (this.controllerBuilder.DefaultNamespaces.Count > 0)
            {
                namespaces = this.controllerBuilder.DefaultNamespaces;
            }
            controllerType = GetControllerTypeWithinNamespaces(area, controller, namespaces);

            // Cache the result
            Cache.Add(cacheKey, controllerType);

            // Return
            return controllerType;
        }
开发者ID:Guymestef,项目名称:MvcSiteMapProvider,代码行数:51,代码来源:ControllerTypeResolver.cs

示例12: EvaluateSet

        private static ISet<Namespace> EvaluateSet(ExpressionEvaluator ee, Node node)
        {
            var n = (SetExpression)node;
            ISet<Namespace> result;
            if (!ee.GlobalScope.NodeVariables.TryGetValue(node, out result)) {
                var values = new HashSet<Namespace>();
                foreach (var x in n.Items) {
                    values.Union(ee.Evaluate(x));
                }

                result = new DictionaryInfo(values, values, ee.ProjectState, ee.GlobalScope.ShowClr).SelfSet;
                ee.GlobalScope.NodeVariables[node] = result;
            }
            return result;
        }
开发者ID:TerabyteX,项目名称:main,代码行数:15,代码来源:ExpressionEvaluator.cs

示例13: Main

        static void Main(string[] args)
        {
            var BigCities = new HashSet<string>
            {
                "New York",
                "Manchester",
                "Sheffield",
                "Paris"
            };

            string[] citiesInUK =
            {
                "Sheffield",
                "Ripon",
                "Truro",
                "Manchester"
            };

            //// Generic code to find intersecting values.
            //BigCities.IntersectWith(citiesInUK);

            //foreach (string city in BigCities)
            //{
            //    Console.WriteLine(city);
            //}

            // Linq method
            // The linq method does create a new array.
            var IntersectCities = BigCities.Intersect(citiesInUK);
            foreach (string city in IntersectCities)
            {
                Console.WriteLine(city);
            }

            Console.WriteLine();

            // Union takes elements that are in either set and puts every element out once.
            var UnionCities = BigCities.Union(citiesInUK);
            foreach (string city in UnionCities)
            {
                Console.WriteLine(city);
            }

            Console.WriteLine();

            // Every element that is in the first set, but not in the second set.
            var ExceptCities = BigCities.Except(citiesInUK);
            foreach (string city in ExceptCities)
            {
                Console.WriteLine(city);
            }

            Console.WriteLine();

            // Which elements appear in either one but not in both collections.
            BigCities.SymmetricExceptWith(citiesInUK);
            foreach (string city in BigCities)
            {
                Console.WriteLine(city);
            }
        }
开发者ID:johanvergeer,项目名称:ps-c-sharp-collection-fundamentals,代码行数:61,代码来源:Program.cs

示例14: HashSetShouldUnionElementCorrectly

        public void HashSetShouldUnionElementCorrectly()
        {
            var set1 = new HashSet<int>();
            var set2 = new HashSet<int>();
            set1.Add(1);
            set1.Add(2);

            set2.Add(2);
            set2.Add(3);
            set2.Add(4);

            var union = set1.Union(set2);

            Assert.IsTrue(union.Find(1));
            Assert.IsTrue(union.Find(2));
            Assert.IsTrue(union.Find(3));
            Assert.IsTrue(union.Find(4));
            Assert.AreEqual(4, union.Count);
        }
开发者ID:atanas-georgiev,项目名称:Data-Structures-and-Algorithms-Homeworks,代码行数:19,代码来源:TestHashSet.cs

示例15: traversalHasLoop

 private bool traversalHasLoop(AST.Address current_addr, Dictionary<AST.Address, AST.Address> visited, AST.Address from_addr)
 {
     // base case 1: loop check
     if (visited.ContainsKey(current_addr))
     {
         return true;
     }
     // base case 2: an input cell
     if (!_formulas.ContainsKey(current_addr))
     {
         return false;
     }
     // recursive case (it's a formula)
     // check both single inputs and the inputs of any vector inputs
     bool OK = true;
     HashSet<AST.Address> single_inputs = _f2i[current_addr];
     HashSet<AST.Address> vector_inputs = new HashSet<AST.Address>(_f2v[current_addr].SelectMany(addrs => addrs.Addresses()));
     foreach (AST.Address input_addr in vector_inputs.Union(single_inputs))
     {
         if (OK)
         {
             // new dict to mark visit
             var visited2 = new Dictionary<AST.Address, AST.Address>(visited);
             // mark visit
             visited2.Add(current_addr, from_addr);
             // recurse
             OK = OK && !traversalHasLoop(input_addr, visited2, from_addr);
         }
     }
     return !OK;
 }
开发者ID:plasma-umass,项目名称:DataDebug,代码行数:31,代码来源:DAG.cs


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