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


C# HashSet.OrderBy方法代码示例

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


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

示例1: Write

        public static void Write(TextWriter writer, IEnumerable<Dictionary<string, string>> records)
        {
            if (records == null) return; //AOT

            var allKeys = new HashSet<string>();
            var cachedRecords = new List<IDictionary<string, string>>();

            foreach (var record in records)
            {
                foreach (var key in record.Keys)
                {
                    if (!allKeys.Contains(key))
                    {
                        allKeys.Add(key);
                    }
                }
                cachedRecords.Add(record);
            }

            var headers = allKeys.OrderBy(key => key).ToList();
            if (!CsvConfig<Dictionary<string, string>>.OmitHeaders)
            {
                WriteRow(writer, headers);
            }
            foreach (var cachedRecord in cachedRecords)
            {
                var fullRecord = headers.ConvertAll(header => 
                    cachedRecord.ContainsKey(header) ? cachedRecord[header] : null);
                WriteRow(writer, fullRecord);
            }
        }
开发者ID:Gunner92,项目名称:Xamarin-Forms-Labs,代码行数:31,代码来源:CsvWriter.cs

示例2: Solution2

        public static int Solution2(Stopwatch timer)
        {
            timer.Restart();

            var a = new HashSet<int>();
            int maxlcm = 1;
            int t = 0;
            var results = new List<int>();

            for (int i = 2; i <= 20; i++)
            {
                int k = i%2 == 0 ? 1 : 2;
                for (int j = k; j < i; j+=2)
                {
                    if (gcd(i, j) == 1)
                    {
                        a.Add(2*i*(i + j));
                    }
                }
            }

            var sortedA = a.OrderBy(v => v).ToArray();

            while (maxlcm < 1000)
            {
                maxlcm = lcm(maxlcm, sortedA[t]);
                results.Add(maxlcm);
                t++;
            }

            int res = results[results.Count - 2];
            timer.Stop();
            return res;
        }
开发者ID:joce,项目名称:EulerProject,代码行数:34,代码来源:Problem039.cs

示例3: UpdateInfo

        public void UpdateInfo()
        {
            if (Application.Session == null)
            {
                this.fileList.Items.Clear();
            }
            else
            {
                HashSet<string> files = new HashSet<string>(PathComparer.OSIndependentPath);

                // Search for source files
                foreach (ObjectCodeFile obj in Application.Session.LoadedImages)
                {
                    foreach (string path in obj.SourceFiles)
                    {
                        files.Add(path);
                    }
                }

                // Add each file item
                foreach (string file in files.OrderBy(x=>x, PathComparer.OSIndependentFilename))
                {
                    // Ignore empty entries
                    if (!string.IsNullOrWhiteSpace(file))
                    {
                        var newItem = new SourceFileItem(file);
                        newItem.MouseDoubleClick += OnFileDoubleClick;

                        this.fileList.Items.Add(newItem);
                    }
                }
            }
        }
开发者ID:jsren,项目名称:DebugOS,代码行数:33,代码来源:SessionView.xaml.cs

示例4: Snapshot

        /// <summary>
        /// 获取一次Tcp端口快照信息
        /// </summary>
        /// <param name="ipVersion">ip版本</param>
        /// <returns></returns>
        public static unsafe PortOwnerPid[] Snapshot(AddressFamily ipVersion)
        {
            var size = 0;
            var TCP_TABLE_OWNER_PID_ALL = 5;
            TcpSnapshot.GetExtendedTcpTable(null, &size, false, ipVersion, TCP_TABLE_OWNER_PID_ALL, 0);

            var pTable = stackalloc byte[size];
            var state = TcpSnapshot.GetExtendedTcpTable(pTable, &size, false, ipVersion, TCP_TABLE_OWNER_PID_ALL, 0);
            if (state != 0)
            {
                return new PortOwnerPid[0];
            }

            var hashSet = new HashSet<PortOwnerPid>();
            var rowLength = *(int*)(pTable);
            var pRow = pTable + Marshal.SizeOf(rowLength);

            for (int i = 0; i < rowLength; i++)
            {
                var row = *(MIB_TCPROW_OWNER_PID*)pRow;
                var port = ByteConverter.ToBytes(row.LocalPort, Endians.Little);

                var portOwner = new PortOwnerPid
                {
                    Port = ByteConverter.ToUInt16(port, 0, Endians.Big),
                    OwerPid = (int)row.OwningPid
                };
                hashSet.Add(portOwner);
                pRow = pRow + Marshal.SizeOf(typeof(MIB_TCPROW_OWNER_PID));
            }

            return hashSet.OrderBy(item => item.Port).ToArray();
        }
开发者ID:dzvane,项目名称:NetworkSocket,代码行数:38,代码来源:TcpSnapshot.cs

示例5: Walk

        public void Walk(IGraphNode<LibraryDescription> root)
        {
            _assemblyFilePaths = new HashSet<string>(StringComparer.Ordinal);
            _dependencyAssemblySources = new Dictionary<string, HashSet<string>>(StringComparer.Ordinal);
            _dependencyPackageSources = new Dictionary<string, HashSet<string>>(StringComparer.Ordinal);

            var libraries = new HashSet<LibraryDescription>();
            root.DepthFirstPreOrderWalk(visitNode: (node, _) => VisitLibrary(node, _, libraries));

            _reports.Information.WriteLine("\n[Target framework {0} ({1})]\n",
                _framework.ToString(), VersionUtility.GetShortFrameworkName(_framework));

            foreach (var assemblyFilePath in _assemblyFilePaths.OrderBy(assemblyName => assemblyName))
            {
                _reports.Information.WriteLine(assemblyFilePath);
                if (_showDetails)
                {
                    var assemblyName = Path.GetFileNameWithoutExtension(assemblyFilePath);

                    HashSet<string> packagesSources;
                    if (_dependencyPackageSources.TryGetValue(assemblyName, out packagesSources) && packagesSources.Any())
                    {
                        _reports.Information.WriteLine("    by package:  {0}", string.Join(", ", packagesSources));
                    }

                    HashSet<string> assemblySources;
                    if (_dependencyAssemblySources.TryGetValue(assemblyName, out assemblySources) && assemblySources.Any())
                    {
                        _reports.Information.WriteLine("    by assembly: {0}", string.Join(", ", assemblySources));
                    }
                }
            }
        }
开发者ID:henghu-bai,项目名称:dnx,代码行数:33,代码来源:AssemblyWalker.cs

示例6: FeatureInteraction

        public FeatureInteraction(HashSet<XgbTreeNode> interaction, double gain, double cover, double pathProbability, double depth, double treeIndex, double fScore = 1)
        {
            SplitValueHistogram = new SplitValueHistogram();
            List<string> features = interaction.OrderBy(x => x.Feature).Select(y => y.Feature).ToList();

            Name = string.Join("|", features);
            Depth = interaction.Count - 1;
            Gain = gain;
            Cover = cover;
            FScore = fScore;
            FScoreWeighted = pathProbability;
            AverageFScoreWeighted = FScoreWeighted / FScore;
            AverageGain = Gain / FScore;
            ExpectedGain = Gain * pathProbability;
            TreeIndex = treeIndex;
            TreeDepth = depth;
            AverageTreeIndex = TreeIndex / FScore;
            AverageTreeDepth = TreeDepth / FScore;
            HasLeafStatistics = false;

            if (Depth == 0)
            {
                SplitValueHistogram.AddValue(interaction.First().SplitValue);
            }
        }
开发者ID:pjpan,项目名称:R,代码行数:25,代码来源:FeatureInteraction.cs

示例7: Main

        public static void Main()
        {
            var generator = new TextGenerator(WordTypes.Name);

            var names = generator.GenerateText(1000);
            var trie = new Trie();
            var words = new HashSet<string>();
            names.Split(' ').ToList().ForEach(
                x =>
                    {
                        words.Add(x);
                        trie.AddWord(x);
                    });

            var result = new StringBuilder();

            foreach (var word in words.OrderBy(x => x))
            {
                int occurenceCount;
                trie.TryFindWord(word, out occurenceCount);
                result.AppendFormat("{0} -> {1} times", word, occurenceCount).AppendLine();
            }

            Console.WriteLine(result);
        }
开发者ID:RuzmanovDev,项目名称:TelerikAcademy,代码行数:25,代码来源:Startup.cs

示例8: button_Click

        //private static void ProcessNode(HtmlNode node, Stack<HtmlNode> stack)
        //{
        //    var depth = stack.Count;
        //    var padding = String.Empty.PadLeft(depth, ' ');
        //    stack.Push(node);
        //    try
        //    {
        //        Debug.WriteLine(padding + "Node: " + node.Name);
        //        foreach (var child in node.ChildNodes)
        //        {
        //            ProcessNode(child, stack);
        //        }
        //    }
        //    finally
        //    {
        //        stack.Pop();
        //    }
        //}

        private void button_Click(object sender, RoutedEventArgs e)
        {
            using (var stream = File.OpenRead(@"C:\Documents\bookmarks_7_27_15.html"))
            {
                var doc = new HtmlDocument();
                doc.Load(stream);

                var rootFolder = new Folder { Name = "<root>" };

                ProcessNode(doc.DocumentNode, rootFolder);
                if (rootFolder.Folders.Count == 1)
                    rootFolder = rootFolder.Folders.Single();

                treeView.Items.Add(GetTree(rootFolder));

                var bookmarks = rootFolder.AllBookmarks.ToList();
                bookmarks.Sort(
                    (l, r) => StringComparer.OrdinalIgnoreCase.Compare(l.Href.ToString(), r.Href.ToString()));
                var lookupItem = new TreeViewItem { Header = "Lookup" };
                var lookup = rootFolder.AllBookmarks.ToLookup(b => b.Href.ToString(), b => b.Folder, StringComparer.OrdinalIgnoreCase);
                foreach (var key in lookup)
                {
                    var folders = new HashSet<string>(key.Select(k => k.FullName), StringComparer.OrdinalIgnoreCase);
                    if (folders.Count > 1)
                    {
                        //folders.Sort((l, r) => StringComparer.OrdinalIgnoreCase.Compare(l.FullName, r.FullName));
                        var keyItem = new TreeViewItem { Header = key.Key + " (" + folders.Count + ")" };
                        foreach (var folder in folders.OrderBy(f => f, StringComparer.OrdinalIgnoreCase))
                            keyItem.Items.Add(new TreeViewItem { Header = folder });
                        lookupItem.Items.Add(keyItem);
                    }
                }
                lookupItem.ExpandSubtree();
                treeView.Items.Add(lookupItem);
                var set = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
                foreach (var bookmark in rootFolder.AllBookmarks)
                    set.Add(bookmark.ToString());
                foreach (var txt in set)
                    Debug.WriteLine(txt);

                using (var output = File.OpenWrite(@"C:\Documents\output.html"))
                {
                    output.SetLength(0);
                    using (var writer = new StreamWriter(output))
                    {

                        writer.WriteLine(@"<!DOCTYPE NETSCAPE-Bookmark-file-1>");
                        writer.WriteLine(@"<!-- This is an automatically generated file.");
                        writer.WriteLine(@"     It will be read and overwritten.");
                        writer.WriteLine(@"     DO NOT EDIT! -->");
                        writer.WriteLine(
                            "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;charset=UTF-8\">");
                        writer.WriteLine(@"<TITLE>Bookmarks</TITLE>");
                        WriteFolder(rootFolder, writer, new HashSet<string>(StringComparer.OrdinalIgnoreCase), "");
                    }
                }

                //Debugger.Break();
            }
        }
开发者ID:zeldafreak,项目名称:Area51,代码行数:79,代码来源:MainWindow.xaml.cs

示例9: Reduce

        /// <summary>
        /// Reduce a list of References to the smallest set of references that
        /// covers the same set as the original.
        /// </summary>
        /// <param name="source">the list of references</param>
        /// <returns>a reduced set of references</returns>
        public static ICollection<Reference> Reduce(this IEnumerable<Reference> source)
        {
            Reference lastReference = null;
            List<Reference> destination = new List<Reference>();

            foreach (Reference check in source.OrderBy(r => r))
            {
                if (lastReference != null)
                {
                    if (lastReference.Book.Equals(check.Book) && lastReference.Chapter == check.Chapter)
                    {
                        HashSet<int> uniqueVerses = new HashSet<int>(lastReference.Verses.Union(check.Verses));
                        lastReference.Verses = uniqueVerses.OrderBy(v => v).ToArray();
                    }
                    else
                    {
                        destination.Add(lastReference);
                        lastReference = null;
                    }
                }

                lastReference = check;
            }

            if (lastReference != null)
            {
                destination.Add(lastReference);
            }

            return destination;
        }
开发者ID:Rivolvan,项目名称:BibleUtilities,代码行数:37,代码来源:ScriptureExtensions.cs

示例10: Main

    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        HashSet<House> Houses = new HashSet<House>();
        long amountOfCable = 0;
        for (int i = 0; i < N; i++)
        {
            string[] inputs = Console.ReadLine().Split(' ');
            Houses.Add(new House { X = int.Parse(inputs[0]), Y = int.Parse(inputs[1]) });
        }

        //Core: Calculate Average House Y index
        double Avg = Houses.Sum(x => x.Y) / N;

        //Core:find the house closest to the Avg Y and use its Y coordinate
        int closest = Houses.OrderBy(x => Math.Abs(x.Y - Avg)).First().Y;

        //lay the mainline
        amountOfCable += (Houses.Max(x => x.X) - Houses.Min(x => x.X));

        //per other House calculate distance from location to mainline
        foreach (var i in Houses)
        {
            amountOfCable += i.Y > closest ? i.Y - closest : closest - i.Y;
        }

        // Write an action using Console.WriteLine()
        // To debug: Console.Error.WriteLine("Debug messages...");

        Console.WriteLine(amountOfCable);
    }
开发者ID:LievenVandeperre,项目名称:codinGame,代码行数:31,代码来源:10.+Network+Cabling.cs

示例11: RelatedEvents

        /// <summary>
        /// Retrieves all events across all aggregates that are related to the specified aggregate ids, in the order in which they were recorded.
        /// </summary>
        /// <param name="events">The events.</param>
        /// <param name="relatedToAggregateIds">The aggregate ids to which the events relate.</param>
        public static async Task<IEnumerable<StorableEvent>> RelatedEvents(
            this IQueryable<StorableEvent> events,
            params Guid[] relatedToAggregateIds)
        {
            var ids = new HashSet<Guid>(relatedToAggregateIds);

            var relatedEvents = new HashSet<StorableEvent>();

            int currentCount;

            do
            {
                currentCount = relatedEvents.Count;

                var unqueriedIds = ids.Where(id => ! relatedEvents.Select(e => e.AggregateId).Contains(id));

                var newEvents = await events.Where(e => unqueriedIds.Any(id => id == e.AggregateId)).ToArrayAsync();

                relatedEvents.UnionWith(newEvents);

                var moreIds = newEvents
                    .SelectMany(e => e.Body.ExtractGuids())
                    .Distinct()
                    .ToArray();

                if (!moreIds.Any())
                {
                    break;
                }

                ids.UnionWith(moreIds);
            } while (currentCount != relatedEvents.Count);

            return relatedEvents.OrderBy(e => e.Id);
        }
开发者ID:halakaraki,项目名称:Its.Cqrs,代码行数:40,代码来源:QueryableExtensions.cs

示例12: Combinations

 private List<int> Combinations(int num)
 {
     _digits = num.ToString().Select(c => Convert.ToInt32(c.ToString())).ToArray();
     _combos = new HashSet<int>();
     Helper(0);
     return _combos.OrderBy(o => o).ToList();
 }
开发者ID:rcluca,项目名称:FunWithCSharp,代码行数:7,代码来源:FollowingInteger.cs

示例13: CalculateKnownVersions

        static Version[] CalculateKnownVersions(ReportRepository repository)
        {
            const int blocks = 4;
            const int versionsPerBlock = 2;

            HashSet<Version> popularVersions = new HashSet<Version>();
            DateTime startDate = repository.Sessions.Min(s => s.StartTime);
            DateTime endDate = repository.Sessions.Max(s => s.StartTime);

            TimeSpan span = endDate - startDate;
            // last week has its own block, other 3 blocks are distributed evenly over the remaining timespan
            if (span > new TimeSpan(30, 0, 0, 0))
                span -= new TimeSpan(7, 0, 0, 0);

            foreach (var groupByBlock in repository.Sessions.AsEnumerable().GroupBy(s => (s.StartTime.Ticks-startDate.Ticks)*(blocks-1)/span.Ticks).OrderBy(g => g.Key)) {
                int versionsAddedThisBlock = 0;
                foreach (var version in groupByBlock.GroupBy(s => s.AppVersion).OrderByDescending(g => g.Count())) {
                    if (popularVersions.Add(version.Key)) {
                        if (++versionsAddedThisBlock >= versionsPerBlock)
                            break;
                    }
                }
            }
            return popularVersions.OrderBy(v => v).ToArray();
        }
开发者ID:AlexZeitler,项目名称:SharpDevelop-Servers,代码行数:25,代码来源:Program.cs

示例14: RenderMismatches

 private void RenderMismatches(string format, HashSet<Tuple<string, string, string>> results)
 {
     foreach (var row in results.OrderBy(r => r.Item1))
     {
         _options.Reports.WriteInformation(string.Format(format, row.Item1, row.Item2, row.Item3));
     }
 }
开发者ID:leloulight,项目名称:dnx,代码行数:7,代码来源:MismatchedDependencyRenderer.cs

示例15: SortPossiblePoint

 /// <summary>
 ///  对可行点进行排序。排序的依据为每个点的评分。
 /// </summary>
 /// <param name="set"></param>
 /// <returns></returns>
 public List<Point> SortPossiblePoint(HashSet<Point> set)
 {
     List<Point >list=new List<Point> ();
        IEnumerable<Point> ie = set.OrderBy(p => p.Evaluate);
        foreach (Point p in ie)
        list.Add(p);
        return list;
 }
开发者ID:SpruceWang,项目名称:BUPT-AI-introduction,代码行数:13,代码来源:ABEngine.cs


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