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


C# HashSet.ToList方法代码示例

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


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

示例1: Relax

    public static Voronoi Relax(Voronoi voronoi, Vector2 bounds1, Vector2 bounds2, int amount = 100)
    {
        Voronoi newVoronoi;
        HashSet<Vector2> sites = new HashSet<Vector2>();
        Vector2 centroidRemember;

        foreach (KeyValuePair<Vector2, Polygon> poly in voronoi.Polygons)
        {
            centroidRemember = PolygonCentroid(poly.Value);
            if (centroidRemember.x != -Mathf.Infinity && centroidRemember.y != -Mathf.Infinity && centroidRemember.x != Mathf.Infinity && centroidRemember.y != Mathf.Infinity && centroidRemember.x > bounds1.x && centroidRemember.y > bounds1.y && centroidRemember.x < bounds2.x && centroidRemember.y < bounds2.y)
            {
                sites.Add(centroidRemember);
            }
            else
            {
                sites.Add(poly.Value.MidPoint.Point);
            }
        }

        amount--;

        newVoronoi = Delaunay.DeriveVoronoi(sites.ToList(), Delaunay.Triangulate(sites.ToList()));

        if (amount <= 0)
        {
            return newVoronoi;
        }
        else
        {
            return Relax(newVoronoi, bounds1, bounds2, amount);
        }
    }
开发者ID:stijnhero,项目名称:Game,代码行数:32,代码来源:LloydRelaxation.cs

示例2: Translate

        private static Dictionary<string, string> Translate(HashSet<string> toTranslate, string fromCulture, string toCulture)
        {
            var translated = Translation.TranslationClient.Translator.TranslateBatch(toTranslate.ToList(), fromCulture, toCulture);

            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.AddRange(toTranslate.ToList(), translated);
            return dic;
        }
开发者ID:JackWangCUMT,项目名称:extensions,代码行数:8,代码来源:HelpTranslator.cs

示例3: GetAllSchemas

        public static List<XmlSchema> GetAllSchemas(this XmlSchemaSet schemaSet)
        {
            // The method XmlSchemaSet.Schemas() will only include all schemas
            // directly added to th schema set, it does not contain any schema
            // that is only indirectly included or imported.
            //
            // So the first thing is to recursively process all schemas and add
            // all schemas included or imported.

            var schemas = new HashSet<XmlSchema>();
            foreach (XmlSchema schema in schemaSet.Schemas())
            {
                schemas.Add(schema);
                AddIncludedSchemas(schemas, schema);
            }

            // However, now there are still schemas missing: so-called chameleon
            // schemas. A chameleon schema is a schema that does not declare
            // a target namespace. If such a schema is included into another
            // schema that declares a target namespace the included schema
            // "inherits" that target namespace. System.Xml.Schema accomplishes
            // that by cloning the schema object and updating all the
            // namespaces. The problem is that we don't find such a schema
            // via XmlSchemaSet.Schemas() or schema.Includes. Instead we have
            // to look at every declared entity and search up their parents
            // until we find the declaring schema. This is sad and ineffecient
            // but it seems to be the only possible option.

            var topLevelSchemas = schemas.ToList();
            foreach (var schema in topLevelSchemas)
            {
                var allItems = schema.Elements.Values.Cast<XmlSchemaObject>()
                       .Concat(schema.Attributes.Values.Cast<XmlSchemaObject>())
                       .Concat(schema.Groups.Values.Cast<XmlSchemaObject>())
                       .Concat(schema.AttributeGroups.Values.Cast<XmlSchemaObject>())
                       .Concat(schema.SchemaTypes.Values.Cast<XmlSchemaObject>())
                       .Concat(schema.Notations.Values.Cast<XmlSchemaObject>());

                foreach (var item in allItems)
                {
                    var declaredSchema = item.GetSchema();
                    if (declaredSchema != null)
                        schemas.Add(declaredSchema);
                }
            }

            return schemas.ToList();
        }
开发者ID:sergey-steinvil,项目名称:xsddoc,代码行数:48,代码来源:XmlSchemaSetExtensions.cs

示例4: LadderLength

        public int LadderLength(string start, string end, string[] dict)
        {
            int result = 0;

            HashSet<string> hashSet = new HashSet<string>(dict);
            HashSet<string> currentStarts = new HashSet<string>() { start }; // change to List will slow down perf

            while (currentStarts.Count > 0)
            {
                currentStarts.ToList().ForEach(x => hashSet.Remove(x));

                result++;

                HashSet<string> nextStarts = new HashSet<string>();
                foreach (string word in currentStarts)
                {
                    if (word == end)
                    {
                        return result;
                    }
                    GetAllValidMoves(word, hashSet, nextStarts);
                }

                currentStarts = nextStarts;
            }
            return 0;
        }
开发者ID:bluesteyes,项目名称:LeetSharp,代码行数:27,代码来源:Q127_WordLadder.cs

示例5: CleanDuplicatesFromTileCollectionList

        /// <summary>
        /// This method removes duplicates from tile connections. This includes connections
        /// which are a subset of another connection.
        /// </summary>
        /// <param name="tileConnections"></param>
        /// <returns></returns>
        public static List<TileConnection> CleanDuplicatesFromTileCollectionList(List<TileConnection> tileConnections)
        {
            var dupes = new HashSet<TileConnection>();

            //compare every tile connection against every other to find the duplicates. This is slow.
            for (var tci = 0; tci < tileConnections.Count; tci++) {
                var tc = tileConnections[tci];
                for (var tci2 = tci + 1; tci2 < tileConnections.Count; tci2++) {
                    var tc2 = tileConnections[tci2];
                    if (!dupes.Contains(tc2) && tc2.IsDuplicateOrSubsetOf(tc)) {
                        dupes.Add(tc2);

                    } else if (!dupes.Contains(tc) && tc.IsDuplicateOrSubsetOf(tc2)) {
                        //By using else if we ensure that we don't add both tileconnections
                        //if they are exact duplicates
                        dupes.Add(tc);
                    }
                }
            }

            //remove all the duplicates
            dupes.ToList().ForEach( dup => {
                tileConnections.Remove(dup);
            });

            return tileConnections;
        }
开发者ID:trbarrett,项目名称:Four-in-a-Row,代码行数:33,代码来源:AIHelper.cs

示例6: Main

        private static void Main()
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var n = input[0];
            var coord0 = new Coord(input[1], input[2]);
            var rgcoord = new HashSet<Coord>();
            for (var i = 0; i < n; i++)
            {
                input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                rgcoord.Add(new Coord(input[0], input[1]));
            }

            var d = 0;
            while (rgcoord.Any())
            {
                d++;
                var coord = rgcoord.First();
                var vX = coord.x - coord0.x;
                var vY = coord.y - coord0.y;

                foreach (var coordT in rgcoord.ToList())
                {
                    if (vY*(coordT.x - coord0.x) == vX*(coordT.y - coord0.y))
                        rgcoord.Remove(coordT);
                }
            }

            Console.WriteLine(d);
        }
开发者ID:encse,项目名称:codeforces,代码行数:29,代码来源:p514B-9833983.cs

示例7: GenerateRandom

    public static List<int> GenerateRandom(int count, int min = 27560000, int max = 27569999)
    {
        if (max <= min || count < 0 ||
                (count > max - min && max - min > 0))
        {
            throw new ArgumentOutOfRangeException("Range or count " + count + " is illegal");
        }

        HashSet<int> candidates = new HashSet<int>();

        for (int top = max - count; top < max; top++)
        {
            if (!candidates.Add(random.Next(min, top + 1)))
            {
                candidates.Add(top);
            }
        }

        List<int> result = candidates.ToList();

        for (int i = result.Count - 1; i > 0; i--)
        {
            int k = random.Next(i + 1);
            int tmp = result[k];
            result[k] = result[i];
            result[i] = tmp;
        }
        return result;
    }
开发者ID:danielet0,项目名称:Projects,代码行数:29,代码来源:EmployeeData.cs

示例8: ParseFiles

    private static string ParseFiles(IEnumerable<string> filePaths)
    {
        var classLines = new List<string>();
        var usingsSet = new HashSet<string>();

        Func<string, bool> isUsingStmt = (x) => x.StartsWith("using");

        var lines = filePaths.Select(x => File.ReadAllLines(x)).SelectMany(x => x).ToList();

        foreach (var line in filePaths.Select(x => File.ReadAllLines(x)).SelectMany(x => x)) {

            if (isUsingStmt(line)) {
                usingsSet.Add(line);

            } else {

                classLines.Add(line);
            }

        }

        var result = usingsSet.ToList();

        result.AddRange(classLines);

        var builder = new StringBuilder();

        result.ForEach(x => builder.AppendLine(x));

        return builder.ToString();
    }
开发者ID:JimLiaskos,项目名称:TankChallenge,代码行数:31,代码来源:Helper.cs

示例9: UndoRedo

 public void UndoRedo(Board board)
 {
     HashSet<int> layersToRecheck = new HashSet<int>();
     foreach (UndoRedoAction action in Actions)
         action.UndoRedo(layersToRecheck);
     layersToRecheck.ToList().ForEach(x => board.Layers[x].RecheckTileSet());
 }
开发者ID:kokose1234,项目名称:HaSuite,代码行数:7,代码来源:UndoRedoBatch.cs

示例10: PrintAllTestFailures

        public static void PrintAllTestFailures()
        {
            var directories = GetBuildDirectories();

            var tests = new HashSet<AggregateTestResult>();

            var totalBuilds = 0;
            var days = 1;

            foreach (var dir in directories.Where(x=>Directory.GetCreationTime(x) > DateTime.Now.AddDays(-1 * days)))
            {
                totalBuilds++;
                var files = Directory.GetFiles(dir, "junitResult.xml");
                if (files.Any())
                {
                    var fileName = files[0];
                    var iterator = GetTestCasesWithErrors(fileName);

                    while (iterator.MoveNext())
                    {
                        var failingTest = GetFailingTestName(iterator);

                        var testResult = GetTestResult(failingTest, tests);

                        UpdateResults(failingTest, dir, tests, testResult);
                    }
                }
            }
            foreach (var failingTest in tests.ToList().OrderBy(x=>x.FailureCount).Reverse())
            {
                Console.WriteLine(failingTest);
            }
            Console.WriteLine("Tests performed during last: " + days + " days");
            Console.WriteLine("Total Builds performed during test run: " + totalBuilds);
        }
开发者ID:asynchrony,项目名称:build-results,代码行数:35,代码来源:PrintCommonFailures.cs

示例11: FindLadders

        public string[][] FindLadders(string start, string end, string[] dict)
        {
            HashSet<string> dictionary = new HashSet<string>(dict);
            HashSet<string> currentStarts = new HashSet<string>() { start };

            List<string[]> results = new List<string[]>();
            Dictionary<string, List<string>> backtrackMap = new Dictionary<string, List<string>>();

            while (currentStarts.Count > 0)
            {
                currentStarts.ToList().ForEach(x => dictionary.Remove(x));
                HashSet<string> nextStarts = new HashSet<string>();

                foreach (string word in currentStarts)
                {
                    if (word == end)
                    {
                        AddPathToResults(backtrackMap, start, end, results);
                    }
                    GetAllValidNextWords(word, dictionary, nextStarts, backtrackMap);
                }

                currentStarts = nextStarts;
            }

            return results.ToArray();
        }
开发者ID:bluesteyes,项目名称:LeetSharp,代码行数:27,代码来源:Q126_WordLadderII.cs

示例12: GenerateLicenseKeys

        public List<string> GenerateLicenseKeys(string rsaXmlString, LicenseBase scutexLicense, LicenseGenerationOptions generationOptions, int count)
        {
            HashSet<string> licenses = new HashSet<string>();
            int doupCount = 0;

            while (licenses.Count < count)
            {
                string key = GenerateLicenseKey(rsaXmlString, scutexLicense, generationOptions);

                if (licenses.Contains(key) == false)
                {
                    licenses.Add(key);
                    //Debug.WriteLine(string.Format("{0} of {1} keys generated", licenses.Count, count));
                }
                else
                {
                    doupCount++;
                    Debug.WriteLine(string.Format("Duplicate key was generated {0}", key));
                }
            }

            if (doupCount > 0)
                Debug.WriteLine(string.Format("{0} duplicate keys were generated at a {1}% chance", doupCount, doupCount * 100m / count));

            return licenses.ToList();
        }
开发者ID:staxmanade,项目名称:Scutex,代码行数:26,代码来源:LicenseKeyService.cs

示例13: UpshotControllerDescription

        public UpshotControllerDescription(HttpControllerDescriptor controllerDescriptor)
        {
            HashSet<Type> entityTypes = new HashSet<Type>();

            _upshotControllerType = controllerDescriptor.ControllerType;

            IEnumerable<MethodInfo> enumerable =
            from p in _upshotControllerType.GetMethods(BindingFlags.Instance | BindingFlags.Public)
            where p.DeclaringType != typeof(UpshotController) && p.DeclaringType != typeof(object) && !p.IsSpecialName
            select p;
            foreach (MethodInfo current in enumerable)
            {
                if (current.GetCustomAttributes(typeof(NonActionAttribute), false).Length <= 0 && (!current.IsVirtual || !(current.GetBaseDefinition().DeclaringType == typeof(UpshotController))))
                {
                    if (current.ReturnType != typeof(void))
                    {
                        Type type = TypeUtility.UnwrapTaskInnerType(current.ReturnType);
                        Type elementType = TypeUtility.GetElementType(type);
                        if (LookUpIsEntityType(elementType))
                        {
                            if (!entityTypes.Contains(elementType))
                            {
                                entityTypes.Add(elementType);
                            }
                        }
                    }
                }
            }
            _entityTypes = new ReadOnlyCollection<Type>(entityTypes.ToList());
        }
开发者ID:cdemaskey,项目名称:UpshotHelper,代码行数:30,代码来源:UpshotControllerDescription.cs

示例14: Can_Execute_Multiple_Times

        public void Can_Execute_Multiple_Times(int iterations)
        {
            var expectedMaxBuildNumber = iterations;

            // Using a set to store each generated build number instead of a list in order to detect duplicates.
            // If an attempt is made to store a duplicate build number in the HashSet instance, an exception will be thrown and the test will fail.
            var set = new HashSet<int>();

            var stopwatch = Stopwatch.StartNew();

            for (var i = 0; i < iterations; ++i)
            {
                var buildNumber = Can_Execute_Test();
                set.Add(buildNumber);
                Thread.Sleep(1); // <-- Used to smooth out race conditions regarding the Date property whereby fast machines can get the date out of order.
            }

            stopwatch.Stop();

            Console.WriteLine("Completed 100 iterations in {0} milliseconds.", stopwatch.ElapsedMilliseconds);

            var list = set.ToList();
            list.ForEach(bn => Console.WriteLine("Build Number: {0}", bn));

            // Assert for the whole set.
            int maxBuildNumber;

            using (var db = new BuildVersioningDataContext(GetConfiguredConnectionString()))
            {
                maxBuildNumber = db.VersionHistoryItems.Max(vhi => vhi.BuildNumber);
            }

            // If there are any duplicates, the max expected build number could not be generated.
            maxBuildNumber.ShouldEqual(expectedMaxBuildNumber);
        }
开发者ID:wade,项目名称:BuildVersioning,代码行数:35,代码来源:CreateVersionCommandTests.cs

示例15: ParseAlbum

        public static List<string> ParseAlbum(Uri albumUrl)
        {
            HashSet<string> uniqueImageUrls = new HashSet<string>();
            string xhtml = HttpUtils.RetrieveTextFromHttp(albumUrl);
            Regex regex = new Regex("\"//i.imgur.com/[^\"]+\"");
            MatchCollection matches = regex.Matches(xhtml);
            foreach (Match match in matches)
            {
                // Format URL's
                string url = match.Value;
                url = url.Trim('"');
                url = "http:" + url;

                // Eliminate small thumbnails
                char lastCharBeforeDot = url[url.LastIndexOf('.') - 1];
                if (lastCharBeforeDot == 's')
                {
                    continue;
                }

                // Eliminate badly-formatted images (e.g. from JavaScript)
                if (url.Remove(0, 19).IndexOf('.') < 1)
                {
                    continue;
                }

                uniqueImageUrls.Add(url);
            }
            return uniqueImageUrls.ToList<string>();
        }
开发者ID:steve-perkins,项目名称:downloaddit,代码行数:30,代码来源:ImgurUtils.cs


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