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


C# HashSet.Distinct方法代码示例

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


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

示例1: ExtractContiguousRanges

        public static IDictionary<IPAddress, IPAddress> ExtractContiguousRanges(IEnumerable<IPAddress> IPs)
        {
            Logger logger = LogManager.GetCurrentClassLogger();
            IDictionary<IPAddress, IPAddress> ranges = new Dictionary<IPAddress, IPAddress>();
            HashSet<uint> IPNumbers = new HashSet<uint>();
            foreach (IPAddress address in IPs)
            {
                IPNumbers.Add(address.ToUint());
            }
            IEnumerable<IEnumerable<uint>> IPNumberGroups = IPNumbers.Distinct()
                .GroupBy(num => NumberUtils.Range(num, uint.MaxValue - num + 1)
                .TakeWhile(IPNumbers.Contains).Last())
                .Where(seq => seq.Count() >= 3)
                .Select(seq => seq.OrderBy(num => num));

            foreach (IEnumerable<uint> group in IPNumberGroups)
            {
                uint low = group.Min();
                uint high = group.Max();
                IPAddress rangeLow = parseUint(low);
                IPAddress rangeHigh = parseUint(high);
                logger.Debug("Selected for exclusion: " + rangeLow + " to " + rangeHigh);
                ranges.Add(rangeLow, rangeHigh);
            }
            return ranges;
        }
开发者ID:randomvariable,项目名称:DHCPD-To-MicrosoftDHCP-Migrator,代码行数:26,代码来源:IPAddressExtensions.cs

示例2: GetSkipFrames

        protected override int[] GetSkipFrames(AVSValue args, ScriptEnvironment env)
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
            string filename = args[1].AsString();
            HashSet<int> f = new HashSet<int>();
            int lineNo = 0;
            string line = "xx";
            try
            {
                using (StreamReader sr = new StreamReader(filename))
                {
                    while ((line = sr.ReadLine()) != null)
                    {
                        lineNo++;
                        f.Add(int.Parse(line));
                    }
                }
            }
            catch (Exception ex)
            {
                env.ThrowError(string.Format("line: {0:4} | {1} {2}\n", lineNo, ex.Message, line));
            }

            return f.Distinct().OrderBy(key => key).ToArray<int>();
        }
开发者ID:hiroyuk,项目名称:ApplyDelFrm,代码行数:25,代码来源:Class1.cs

示例3: BenchmarkSettings

        public BenchmarkSettings(TestMode testMode, RunMode runMode, int numberOfIterations, int runTimeMilliseconds,
            IEnumerable<GcBenchmarkSetting> gcBenchmarks,
            IEnumerable<MemoryBenchmarkSetting> memoryBenchmarks,
            IEnumerable<CounterBenchmarkSetting> counterBenchmarks, string description, string skip)
        {
            TestMode = testMode;
            RunMode = runMode;
            NumberOfIterations = numberOfIterations;
            RunTime = TimeSpan.FromMilliseconds(runTimeMilliseconds == 0 ? DefaultRuntimeMilliseconds : runTimeMilliseconds);
            Description = description;
            Skip = skip;

            // Strip out any duplicates here
            // TODO: is it better to move that responsibility outside of the BenchmarkSettings class?

            GcBenchmarks = new HashSet<GcBenchmarkSetting>(gcBenchmarks).ToList();
            MemoryBenchmarks = new HashSet<MemoryBenchmarkSetting>(memoryBenchmarks).ToList();
            CounterBenchmarks = new HashSet<CounterBenchmarkSetting>(counterBenchmarks).ToList();

            DistinctGcBenchmarks =
                GcBenchmarks.Distinct(GcBenchmarkSetting.GcBenchmarkDistinctComparer.Instance).ToList();

            DistinctCounterBenchmarks =
                CounterBenchmarks.Distinct(CounterBenchmarkSetting.CounterBenchmarkDistinctComparer.Instance).ToList();

            DistinctMemoryBenchmarks =
                MemoryBenchmarks.Distinct(MemoryBenchmarkSetting.MemoryBenchmarkDistinctComparer.Instance).ToList();
        }
开发者ID:ThomasBombadil,项目名称:NBench,代码行数:28,代码来源:BenchmarkSettings.cs

示例4: CollectTabs

        public static IEnumerable<string> CollectTabs(this EditorResult editorResult) {
            var set = new HashSet<ShapePosition>();

            foreach (var editor in editorResult.Editors) {
                var positionText = editor.Metadata.Position;

                if (!String.IsNullOrWhiteSpace(positionText)) {
                    var position = ShapePosition.Parse(positionText);
                    set.Add(position);
                }
            }
            return set.Distinct(new ShapePositionDistinctComparer()).OrderBy(x => x.Position).Select(x => x.Name);
        }
开发者ID:RasterImage,项目名称:Orchard,代码行数:13,代码来源:EditorResultExtensions.cs

示例5: PossibleWords

        private static IEnumerable<string> PossibleWords(string word, int level = 1)
        {
            var words = new HashSet<string>();
            Matcher(word, _list).ToList().ForEach(w => words.Add(w));

            if (level < 3)
            {
                var toAdd = new List<string>();
                foreach (var item in words)
                    toAdd.AddRange(PossibleWords(item, level + 1));

                toAdd.ForEach(w => words.Add(w));
            }

            return words.Distinct();
        }
开发者ID:Sharparam,项目名称:DailyProgrammer,代码行数:16,代码来源:Program.cs

示例6: Search

 public void Search()
 {
     /* 2. All items search method.
      * This method simply returns all the items in the collection, without duplicates.
      */
     HashSet<AbstractItem> results = new HashSet<AbstractItem>(coll);
     if (onSearchComplete != null)
     {
         onSearchComplete(results.Distinct().ToList());
     }
 }
开发者ID:Terfin,项目名称:Booklib,代码行数:11,代码来源:DynamicData.cs

示例7: When_running_the_order_is_random

        public void When_running_the_order_is_random()
        {
            var last = "";
            var runs = new HashSet<string>();

            var ex = Experiment
                .On(() => last = "control")
                .Try(() => last = "try");

            for (int i = 0; i < 1000; i++)
            {
                ex.Run();
                runs.Add(last);
            }

            runs.Distinct().Count().ShouldBeGreaterThan(1);
        }
开发者ID:Pondidum,项目名称:NScientist,代码行数:17,代码来源:ExperimentTests.cs

示例8: DisplayResults

        public static string DisplayResults()
        {
            string scope = HostingEnvironment.MapPath("~");

            Regex regex = new Regex(@"([a-fA-F0-9]{64})");
            string connectionString = "Provider=Search.CollatorDSO;Extended Properties=\"Application=Windows\"";
            HashSet<string> imgExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
                {
                    ".jpg", ".jpeg", ".jpe", ".gif", ".png", ".tiff", ".tif", ".svg", ".svgz", ".xbm", ".bmp", ".ico"
                };

            OleDbConnection connection = new OleDbConnection(connectionString);

            string query = @"SELECT TOP 100 System.ItemFolderPathDisplay FROM SystemIndex WHERE scope ='file:" + scope + "' AND System.FileName = 'index.htm' ORDER BY System.DateModified DESC";
            OleDbCommand command = new OleDbCommand(query, connection);
            connection.Open();
            HashSet<string> result = new HashSet<string>();
            OleDbDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                string searchString = reader.GetString(0);
                Match match = regex.Match(searchString);
                if (match.Success)
                {
                    result.Add(match.Value);
                }
            }
            connection.Close();
            if (result.Count > 0)
            {
                string searchHTML = "";
                var uniqueResults = result.Distinct();
                foreach (string s in uniqueResults)
                {
                    var signature = "";
                    var img = "";
                    //var file = "";
                    var msg = "";
                    var date = "";
                    var blockchain = "";
                    var profiles = "";
                    var doc = new HtmlAgilityPack.HtmlDocument();
                    try
                    {
                        doc.Load(scope + s + "\\index.htm");
                    }
                    catch { break; }


                    try
                    {
                        img = doc.GetElementbyId("img0").InnerText;
                        searchHTML = searchHTML + "<div class=\"item\"><div class=\"content\"><table><tr><th rowspan=\"6\"><a href=\"" + s + "/index.htm\"><img src=\"" + s + "/" + img + "\" /></a></th><th></th></tr>";
                    }
                    catch { searchHTML = searchHTML + "<div class=\"item\"><div class=\"content\"><table><tr><th rowspan=\"6\"></th><th></th></tr>"; }
                    try { signature = doc.GetElementbyId("signature").InnerText; }
                    catch { }
                    try { blockchain = doc.GetElementbyId("blockchain").InnerText; }
                    catch { }
                    searchHTML = searchHTML + "<tr><td>" + blockchain + " - " + signature + "</td></tr>";
                    try { date = doc.GetElementbyId("block-date").InnerText; }
                    catch { }
                    try { msg = doc.GetElementbyId("msg1").InnerText; }
                    catch { }
                    try { profiles = doc.GetElementbyId("profiles").InnerHtml; }
                    catch { }
                    searchHTML = searchHTML + "<tr><td><a href=\"" + s + "/index.htm\">" + msg.PadRight(50).Substring(0, 49) + "</a></td></tr>";

                    if (msg.Length > 500)
                    { searchHTML = searchHTML + "<tr><td>" + date + " : " + msg.Substring(0, 499) + "...</td></tr>"; }
                    else { searchHTML = searchHTML + "<tr><td>" + date + " : " + msg + "</td></tr>"; }

                    if (profiles.Length > 0)
                    {
                        searchHTML = searchHTML + "<tr><td>" + profiles + "</td></tr>";
                    }
                    searchHTML = searchHTML + "<tr><td><a href=\"" + s + "/index.htm\"><font size=\"1\">" + s + "</font></a></td></tr></table></div></div>";

                }
                return searchHTML;

            }
            else
            { return "<div class=\"item\"><div class=\"content\">Nothing found</div></div>"; }
        
        }
开发者ID:embiimob,项目名称:bitFossil,代码行数:86,代码来源:recent.aspx.cs

示例9: UpdateNotifications

            public void UpdateNotifications(Domain.Entity.Mill.Pipe pipeSavingState)
            {
                if (isProperlyCreated)
                {
                    //* What can happen at Save Pipe: (NRO - non required inspection operation)
                    //* - pipe is new and have no previous state (to update: NROs from current size type(new))
                    if (initialPipeSizeTypeId == Guid.Empty)
                    {
                        AddPipe(pipeSavingState.PipeTestResult);
                        ProcessOperationForPipeSizeType(pipeSavingState.Type.Id);
                    }

                    //* - pipe is existing and pipe size type changed (to update: NROs from previous size type(remove), NROs from current size type(new))
                    else if (pipeSavingState.Type == null || initialPipeSizeTypeId != pipeSavingState.Type.Id)
                    {
                        RemoveAndUpdatePipe(initialSelectivePipeTestResult);
                        AddAndUpdate(pipeSavingState.PipeTestResult);

                    }

                    //* - pipe is existing and operations were edited (to update: NROs from current size type(track changes))
                    else if (initialPipeSizeTypeId == pipeSavingState.Type.Id)
                    {
                        HashSet<TestResultInfo> savingState = new HashSet<TestResultInfo>(GetTestResultInfoListFromPipeTestResultList(pipeSavingState.PipeTestResult));
                        HashSet<TestResultInfo> initialState = new HashSet<TestResultInfo>(initialSelectiveInfo);

                        savingState.ExceptWith(initialState);

                        foreach (TestResultInfo result in savingState.Distinct())
                        {
                            manager.cache.RemovePipeAmount(result.OperationId);
                            manager.cache.AddPipeAmount(result.OperationId);

                            UpdateNotification(result.OperationId);
                        }
                    }

                    //* - pipe deactivation (to update: NRO (remove))
                    else if (!pipeSavingState.IsActive)
                    {
                        RemoveAndUpdatePipe(pipeSavingState.PipeTestResult);
                    }
                }

                NotificationService.Instance.NotifyInterested();
                SavePipeState(pipeSavingState);
            }
开发者ID:AleksMorozova,项目名称:prizm,代码行数:47,代码来源:SelectiveOperationManager.cs

示例10: getUniques

 public HashSet<Timetable> getUniques(HashSet<Timetable> tables)
 {
     return new HashSet<Timetable>(tables.Distinct(new TimetableBookedTimeEquality()).Select(t => t.RemoveAllFreeTime()).OrderBy(x => x.ToString()));
 }
开发者ID:cverhelst,项目名称:Timetable,代码行数:4,代码来源:TimetableFitter.cs

示例11: GetBinaryPath

        public string GetBinaryPath()
        {
            if (null == assemblies)
               {
               throw new Exception("No mapping assembly specified");
               }
               HashSet<string> paths = new HashSet<string>();
               foreach (MSBuild.BuildItem it in assemblies)
               {
               paths.Add(Path.GetDirectoryName(it.Include).ToLower());
               }
               if (paths.Count == 0)
               {
               throw new Exception("No mapping assembly specified");
               }

               if (paths.Count > 1)
               {
               throw new Exception("Mapping assemblies does not share the same directory.");
               }

               return paths.Distinct().First();
        }
开发者ID:mausch,项目名称:NHWorkbench,代码行数:23,代码来源:ProjectModel.cs

示例12: Ship

        public ActionResult Ship(String id, Guid shipID, Guid newID, Guid? parentID, String portName)
        {
            try
            {
                HoloTableController._lockMap[id] = HoloTableController._lockMap.GetValue(id, new Object());

                lock (HoloTableController._lockMap[id])
                {
                    var model = new DetailModel(id, shipID);

                    // Parents being equipped
                    var parentItems = model.Player.Items.Where(i => i.ID == parentID).ToArray();

                    // Ports being equipped
                    var newShipPorts = model.Player.Ships.Where(s => s.ID == shipID).Where(s => s.Ports != null).Where(s => s.Ports.Items != null).SelectMany(s => s.Ports.Items).Where(p => p.PortName == portName).ToArray();
                    var newItemPorts = model.Player.Items.Where(i => i.ID == parentID).Where(i => i.Ports != null).Where(i => i.Ports.Items != null).SelectMany(i => i.Ports.Items).Where(p => p.PortName == portName).ToArray();
                    var newPorts = newShipPorts.Concat(newItemPorts).ToArray();

                    // Item IDs being replaced
                    var oldItemIDs = new HashSet<Guid>(newPorts.Select(p => p.ItemID));

                    // Items being replaced
                    var oldItems = model.Player.Items.Where(i => oldItemIDs.Contains(i.ID)).ToArray();
                    var oldIDs = new HashSet<Guid>(oldItems.SelectMany(i => this.FlattenIDs(model, i)));

                    // Inventory being moved
                    var oldHangarInventory = model.Player.Inventory.Items.Where(i => oldIDs.Contains(i.ID));
                    var oldShipInventory = model.Player.Ships.Where(s => s.Inventory != null).Where(s => s.Inventory.Items != null).SelectMany(s => s.Inventory.Items.Where(i => oldIDs.Contains(i.ID)));
                    var oldInventory = oldShipInventory.Union(oldHangarInventory).ToArray();

                    // Items being equipped
                    var newItems = model.Player.Items.Where(i => i.ID == newID).ToArray();
                    var newIDs = new HashSet<Guid>(newItems.SelectMany(i => this.FlattenIDs(model, i)));

                    // Inventory being moved
                    var newHangarInventory = model.Player.Inventory.Items.Where(i => newIDs.Contains(i.ID));
                    var newShipInventory = model.Player.Ships.Where(s => s.Inventory != null).Where(s => s.Inventory.Items != null).SelectMany(s => s.Inventory.Items.Where(i => newIDs.Contains(i.ID)));
                    var newInventory = newShipInventory.Union(newHangarInventory).ToArray();

                    // Old ports
                    var oldShipPorts = model.Player.Ships.Where(s => s.Ports != null).Where(s => s.Ports.Items != null).SelectMany(s => s.Ports.Items).Where(p => p.ItemID == newID).Where(p => p.ItemID != Guid.Empty).ToArray();
                    var oldItemPorts = model.Player.Items.Where(i => i.Ports != null).Where(i => i.Ports.Items != null).SelectMany(i => i.Ports.Items).Where(p => p.ItemID == newID).Where(p => p.ItemID != Guid.Empty).ToArray();
                    var oldPorts = oldItemPorts.Concat(oldShipPorts).ToArray();

                    // Configure Ship inventory
                    foreach (var ship in model.Player.Ships.Where(s => s.Inventory != null).Where(s => s.Inventory.Items != null))
                    {
                        ship.Inventory.Items = ship.Inventory.Items.Where(i => !oldIDs.Contains(i.ID)).Where(i => !newIDs.Contains(i.ID)).ToArray();

                        if (ship.ID == shipID)
                        {
                            ship.Inventory.Items = ship.Inventory.Items.Union(newInventory).ToArray();
                        }
                    }

                    // Configure Player inventory
                    var shipItemIDs = new HashSet<Guid>(model.Player.Ships.Where(s => s.Inventory != null).Where(s => s.Inventory.Items != null).SelectMany(s => s.Inventory.Items).Select(i => i.ID));

                    model.Player.Inventory = new Inventory.Inventory
                    {
                        Items = model.Player.Items.Where(i => !shipItemIDs.Contains(i.ID)).Select(i => new Inventory.InventoryItem { ID = i.ID }).ToArray()
                    };

                    var oldPort = oldPorts.SingleOrDefault();

                    if (oldPort != null)
                    {
                        oldPort.ItemID = oldItemIDs.Distinct().SingleOrDefault();
                    }

                    var newPort = newPorts.SingleOrDefault();

                    if (newPort != null)
                    {
                        newPort.ItemID = newID;
                    }

                    foreach (var item in newItems)
                    {
                        if (item.Ports.Items == null) continue;
                        var gameItem = model.GameData_ItemMap[newID];
                        if (gameItem.Ports.Items == null) continue;
                        var itemPorts = item.Ports.Items.ToList();
                        var missingPorts = gameItem.Ports.Items.Where(p => !item.Ports.Items.Select(i => i.PortName).Distinct().Contains(p.Name));

                        foreach (var port in missingPorts)
                        {
                            itemPorts.Add(new Port
                            {
                                ItemID = Guid.Empty,
                                PortName = port.Name,
                            });
                        }

                        item.Ports.Items = itemPorts.ToArray();
                    }

                    // TODO: Validate parts - can't because CIG breaks the rules

                    // Set current ship (Optional)
//.........这里部分代码省略.........
开发者ID:dolkensp,项目名称:HoloXPLOR,代码行数:101,代码来源:HoloTableController.cs

示例13: Main

        static void Main(string[] args)
        {
            List<List<int>> possibles = new List<List<int>>();
            for (int a = 1000; a < 10000; a++)
            {
                if (IsValid(a))
                {
                    int[] digits = a.Digits().ToArray();
                    int startA = GetCycleStart(a);
                    if (startA < 1000) continue;
                    for (int b = startA; b < startA + 100; b++)
                    {
                        if (IsValid(b))
                        {
                            int startB = GetCycleStart(b);
                            if (startB < 1000) continue;
                            for (int c = startB; c < startB + 100; c++)
                            {
                                if (IsValid(c))
                                {
                                    int startC = GetCycleStart(c);
                                    if (startC < 1000) continue;
                                    for (int d = startC; d < startC + 100; d++)
                                    {
                                        if (IsValid(d))
                                        {
                                            int startD = GetCycleStart(d);
                                            if (startD < 1000) continue;
                                            for (int e = startD; e < startD + 100; e++)
                                            {
                                                if (IsValid(e))
                                                {
                                                    int startE = GetCycleStart(e);
                                                    if (startE < 1000) continue;
                                                    for (int k = startE; k < startE + 100; k++)
                                                    {
                                                        List<int> sequence = new List<int>();
                                                        if (IsValid(k))
                                                        {
                                                            sequence.Add(a);
                                                            sequence.Add(b);
                                                            sequence.Add(c);
                                                            sequence.Add(d);
                                                            sequence.Add(e);
                                                            sequence.Add(k);
                                                            int[] kDigits = k.Digits().ToArray();
                                                            if (digits[0] == kDigits[2] && digits[1] == kDigits[3])
                                                            {

                                                                if (IsValidSequence(sequence))
                                                                {
                                                                    possibles.Add(sequence);
                                                                    /*
                                                                    Console.WriteLine(a + "  " + b + "  " + c + "  " + d + "  " + e + "  " + k);
                                                                    Console.WriteLine(a + b + c + d + e + k);*/
                                                                }

                                                                //Console.WriteLine(a + "  " + b + "  " + c + "  " + d + "  " + e + "  " + k);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                        }
                    }
                }
            }
            HashSet<int> sums = new HashSet<int>();
            foreach (var sequence in possibles)
            {
                if (!sums.Contains(sequence.Sum()))
                {
                    sums.Add(sequence.Sum());
                    Console.WriteLine(sequence.ToStringPretty());
                }

                //Console.WriteLine(sequence.ToStringPretty());
                /*
                if (IsOrdered(sequence))
                {
                    Console.WriteLine(sequence.ToStringPretty());
                    Console.WriteLine(sequence.Sum());
                }*/
            }
            //The answer is the 4th index in this, don't ask me why
            Console.WriteLine(sums.Distinct().ToStringPretty());
            Console.ReadKey();
        }
开发者ID:jamiees2,项目名称:Euler,代码行数:93,代码来源:Program.cs

示例14: filesFromDpl

 static IEnumerable<string> filesFromDpl(string dplUrl, Langs[] langs) {
   var dplPath = pathFromUrl(dplUrl);
   var cfg = Newtonsoft.Json.JsonConvert.DeserializeObject<deplyConfig>(File.ReadAllText(dplPath));
   HashSet<string> res = new HashSet<string>();
   var relDir = dplUrl.Substring(0, dplUrl.LastIndexOf('/'));
   Func<string, string> fullUrl = url => (url.StartsWith("/") ? url : relDir + "/" + url).ToLower();
   if (dplUrl.IndexOf("{loc}") > 0) {
     foreach (var inc in cfg.includes) foreach (var lng in langs) res.Add(string.Format(fullUrl(inc), swLang(lng)));
   } else {
     //** includes x excludes x regExs
     if (cfg.includes != null)
       foreach (var inc in cfg.includes) {
         if (inc.StartsWith("@")) {
           var regEx = inc.Substring(1);
           var urls = Directory.GetFiles(commonDir, "*.*", SearchOption.AllDirectories).Select(f => urlFromPath(f)).ToArray();
           var rx = new Regex(regEx, RegexOptions.IgnoreCase);
           foreach (var url in urls) if (rx.IsMatch(url)) res.Add(url);
         } else if (inc.EndsWith(".json")) res.UnionWith(filesFromDpl(fullUrl(inc), langs));
         else if (inc.StartsWith("!")) res.Remove(fullUrl(inc));
         else res.Add(fullUrl(inc));
       }
   }
   return res.Distinct();
 }
开发者ID:PavelPZ,项目名称:NetNew,代码行数:24,代码来源:FileSources.cs


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