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


C# SortedSet.Contains方法代码示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            var sortedSet = new SortedSet<int>();
            sortedSet.Add(10);
            Console.WriteLine(sortedSet);

            Console.WriteLine(sortedSet.Add(10).ToString());

            sortedSet.Add(5);
            sortedSet.Add(6);
            sortedSet.Add(20);
            sortedSet.Add(13);
            sortedSet.Add(14);

            Console.WriteLine(sortedSet);

            Console.WriteLine(sortedSet.Contains(3));
            Console.WriteLine(sortedSet.Contains(5));
            Console.WriteLine(sortedSet.Contains(10));
            Console.WriteLine(sortedSet.Contains(10));
            Console.WriteLine(sortedSet.Contains(5));
            Console.WriteLine(sortedSet.Contains(6));
            Console.WriteLine(sortedSet.Contains(20));
            Console.WriteLine(sortedSet.Contains(13));
            Console.WriteLine(sortedSet.Contains(14));

            Console.ReadKey();
        }
开发者ID:bdr27,项目名称:c-,代码行数:28,代码来源:Program.cs

示例2: TestCollectionContains

        public void TestCollectionContains()
        {
            var sortedSet = new SortedSet<int>();
            sortedSet.Add(10);
            sortedSet.Add(5);
            sortedSet.Add(6);
            sortedSet.Add(20);
            sortedSet.Add(13);
            sortedSet.Add(14);

            Assert.IsTrue(sortedSet.Contains(10));
            Assert.IsTrue(sortedSet.Contains(5));
            Assert.IsTrue(sortedSet.Contains(6));
            Assert.IsTrue(sortedSet.Contains(20));
            Assert.IsTrue(sortedSet.Contains(13));
            Assert.IsTrue(sortedSet.Contains(14));

            for (int i = 0; i < 4; i++)
            {
                Assert.IsFalse(sortedSet.Contains(i));
            }
            for (int i = 21; i < 50; i++)
            {
                Assert.IsFalse(sortedSet.Contains(i));
            }
        }
开发者ID:bdr27,项目名称:c-,代码行数:26,代码来源:UnitTest1.cs

示例3: RemoveDuplicate

        private static void RemoveDuplicate(HeaderDetail_v1<Handeco_Header, Handeco_Detail> headerDetail)
        {
            //   company.detail.raisonSociale       company.header.name
            if (headerDetail.Header.Name.Equals(headerDetail.Detail.RaisonSociale, StringComparison.InvariantCultureIgnoreCase))
                headerDetail.Header.Name = null;

            SortedSet<string> detailGroupes = new SortedSet<string>(headerDetail.Detail.Groupes);
            headerDetail.Detail.Groupes = detailGroupes.ToArray();
            List<string> headerGroupes = new List<string>();
            foreach (string groupe in headerDetail.Header.Groupes)
            {
                if (!detailGroupes.Contains(groupe))
                    headerGroupes.Add(groupe);
            }
            headerDetail.Header.Groupes = headerGroupes.ToArray();

            //   company.header.activités  company.detail.activités.type
            SortedSet<string> detailActivités = new SortedSet<string>(from activité in headerDetail.Detail.Activités select activité.Type);
            List<string> headerActivités = new List<string>();
            foreach (string activité in headerDetail.Header.Activités)
            {
                if (!detailActivités.Contains(activité))
                    headerActivités.Add(activité);
            }
            headerDetail.Header.Activités = headerActivités.ToArray();
        }
开发者ID:labeuze,项目名称:source,代码行数:26,代码来源:Handeco_Xml.cs

示例4: TestCopyConstructor

        public static void TestCopyConstructor()
        {
            SortedSet<int> sortedSet = new SortedSet<int>();

            List<int> listOfItems = new List<int>();
            for (int i = 0; i < 10000; i++)
            {
                if (!sortedSet.Contains(i))
                {
                    sortedSet.Add(i);
                    listOfItems.Add(i);
                }
            }

            SortedSet<int> newTree1 = new SortedSet<int>(listOfItems);

            Assert.True(newTree1.SetEquals(listOfItems)); //"Expected to be the same set."

            SortedSet<int> newTree2 = new SortedSet<int>(sortedSet);

            Assert.True(sortedSet.SetEquals(newTree2)); //"Expected to be the same set."

            Assert.Equal(sortedSet.Count, newTree1.Count); //"Should be equal."
            Assert.Equal(sortedSet.Count, newTree2.Count); //"Copied tree not the same as base"
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:25,代码来源:SortedSetSpecificTests.cs

示例5: FindLongestPath

        private int FindLongestPath(int maxSalary, int startSalary)
        {
            IDictionary<int, int> longestPaths = new Dictionary<int, int>() { { startSalary, 1 }};
            SortedSet<int> salaries = new SortedSet<int>();
            salaries.Add(startSalary);

            while (salaries.Count != 0)
            {
                int salary = salaries.Min;
                int path = longestPaths[salary];

                foreach (int nextSalary in GetNextSalaries(maxSalary, salary))
                {
                    if (!salaries.Contains(nextSalary))
                    {
                        salaries.Add(nextSalary);
                        longestPaths.Add(nextSalary, path + 1);
                    }
                    else
                        if (longestPaths[nextSalary] < path + 1)
                            longestPaths[nextSalary] = path + 1;
                }

                salaries.Remove(salary);
            }

            return longestPaths.Values.Max();
        }
开发者ID:korzenikov,项目名称:Projects,代码行数:28,代码来源:IntegerPercentage.cs

示例6: RegisterRoutes

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "Setup/{action}/{id}", // URL with parameters
                new { controller = "AppVisumSetup", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

            foreach (Plugin p in AppSys.Instance.InstalledPlugins.Where(p => p.IsContentProvider))
            {
                var cp = p.P<IAppContentProvider>();
                int bindingIndex = 0;
                foreach (string binding in p.Bindings)
                {
                    foreach (Type t in cp.GetControllerTypes())
                    {
                        SortedSet<string> methods = new SortedSet<string>();
                        foreach (var m in t.GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance))
                        {
                            if (!m.ReturnType.IsSubclassOf(typeof(ActionResult)) && m.ReturnType != typeof(ActionResult))
                                continue;

                            if (methods.Contains(m.Name))
                                continue;
                            methods.Add(m.Name);

                            if (m.GetCustomAttributes(typeof(NonActionAttribute), false).Length > 0)
                                continue;

                            RouteAttribute ra = m.GetCustomAttributes(typeof(RouteAttribute), false).Cast<RouteAttribute>().FirstOrDefault();
                            string controllerName = t.FullName.Substring(0, t.FullName.Length - "Controller".Length).Replace('.', '_');
                            if (ra != null)
                            {
                                string routeName = ra.GetName(String.Format("{0}_{1}_{2}", binding, t.Name, m.Name));
                                if (bindingIndex > 0)
                                    routeName += bindingIndex;
                                routes.MapRoute(
                                    routeName,
                                    ra.GetRoute(binding),
                                    Utils.MergeObjects(ra.Defaults, new { plugin = p.DbId, controller = controllerName, action = m.Name }),
                                    ra.Constraints
                                );
                            }
                            else
                            {
                                routes.MapRoute(
                                    String.Format("{0}_{1}_{2}", binding, t.Name, m.Name),
                                    String.Format("{0}/{1}/{2}", binding, t.Name, m.Name),
                                    new { plugin = p.DbId, controller = controllerName, action = m.Name }
                                );
                            }
                        }
                    }
                }
            }

            routes.MapRoute("BackPort", "{controller}/{action}/{id}", new { action = "Index", id = UrlParameter.Optional }, new string[] { "AppVisum.Models" });
        }
开发者ID:Alxandr,项目名称:AppVisum,代码行数:60,代码来源:Global.asax.cs

示例7: RemoveDuplicate

        public static void RemoveDuplicate(Handeco_Company company)
        {
            //   company.detail.raisonSociale       company.header.name
            if (company.header.name.Equals(company.detail.raisonSociale, StringComparison.InvariantCultureIgnoreCase))
                company.header.name = null;
            List<string> groupes = new List<string>();

            //   company.detail.adhésionGroupement  company.header.groupes
            //string detailGroupe = company.detail.adhésionGroupement;
            SortedSet<string> detailGroupes = new SortedSet<string>(company.detail.groupes);
            company.detail.groupes = detailGroupes.ToArray();

            foreach (string groupe in company.header.groupes)
            {
                //if (!groupe.Equals(detailGroupe, StringComparison.InvariantCultureIgnoreCase))
                if (!detailGroupes.Contains(groupe))
                    groupes.Add(groupe);
            }
            company.header.groupes = groupes.ToArray();

            //   company.header.activités  company.detail.activités.type
            //company.header.activités
            //SortedList<string, string> headerActivités = new SortedList<string, string>();
            //SortedSet<string> headerActivités = new SortedSet<string>(company.header.activités);
            SortedSet<string> detailActivités = new SortedSet<string>(from activité in company.detail.activités select activité.type);
            List<string> headerActivités = new List<string>();
            foreach (string activité in company.header.activités)
            {
                if (!detailActivités.Contains(activité))
                    headerActivités.Add(activité);
            }
            company.header.activités = headerActivités.ToArray();
        }
开发者ID:labeuze,项目名称:source,代码行数:33,代码来源:Handeco.cs

示例8: Main

    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        SortedSet<long> numberCollection = new SortedSet<long>();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++)
        {
            long currentNumber = long.Parse(Console.ReadLine());
            if (!numberCollection.Contains(currentNumber))
            {
                numberCollection.Add(currentNumber);
            }
            else
            {
                numberCollection.Remove(currentNumber);
            }

            if (numberCollection.Count == 0)
            {
                sb.AppendLine("There are no numbers");
            }
            else if (numberCollection.Count == 1)
            {
                sb.AppendLine("There is only one number");
            }
            else
            {
                long minDifference = CalculateMinDifference(numberCollection);
                sb.AppendLine(minDifference.ToString());
            }
        }

        Console.Write(sb.ToString());
    }
开发者ID:ROSSFilipov,项目名称:CSharp,代码行数:34,代码来源:GameOfBits.cs

示例9: Search

        public static Stack<Square> Search(Map map, Square source, Square target, Func<Square, Square, int> heuristic)
        {
            Dictionary<Square, Square> parents = new Dictionary<Square, Square>();
            HashSet<Square> closed = new HashSet<Square>();
            SortedSet<Square> open = new SortedSet<Square>();

            source.Score.Cost = 0;
            source.Score.Estimate = heuristic(source, target);
            open.Add(source);

            while (open.Count > 0)
            {

                // Get node with lowest f(x) score
                Square current = open.First();

                if (current == target)
                    break;

                // Transfer node to closed set
                open.Remove(current);
                closed.Add(current);

                // Examine neighbors
                foreach (Square neighbor in map.GetNeighbors(current))
                {
                    // Check if node is already processed or not passable
                    if (closed.Contains(neighbor) || (neighbor != target && !neighbor.IsPassable))
                        continue;

                    // Tentative g score
                    float g = current.Score.Cost + 1;

                    // Add (new) node to open
                    if (!open.Contains(neighbor))
                    {
                        parents[neighbor] = current;
                        neighbor.Score.Cost = g;
                        neighbor.Score.Estimate = heuristic(neighbor, target);
                        open.Add(neighbor);
                    }

                    // Updating existing node in open
                    else if (g < neighbor.Score.Cost)
                    {
                        open.Remove(neighbor);
                        parents[neighbor] = current;
                        neighbor.Score.Cost = g;
                        open.Add(neighbor);
                    }
                }
            }

            return ReconstructPath(parents, target);
        }
开发者ID:tvdburgt,项目名称:ants,代码行数:55,代码来源:AStar.cs

示例10: FindReachableBlocks

 private static SortedSet<IRBlock> FindReachableBlocks(SortedSet<IRBlock> reachable, IRBlock block, int ignoreBlockIndex)
 {
     List<IRBlock> successors = block.GetSuccessors();
     foreach (IRBlock successor in successors)
     {
       if ((!reachable.Contains(successor)) && (successor.GetIndex() != ignoreBlockIndex))
       {
     reachable.Add(successor);
     FindReachableBlocks(reachable, successor, ignoreBlockIndex);
       }
     }
     return reachable;
 }
开发者ID:TribeMedia,项目名称:tcd-swift,代码行数:13,代码来源:DominatorTree.cs

示例11: ExtractManifests

        /// <summary>
        ///     Extracts manifest from .etl file that was produced using System.Diagnostics.Tracing.EventSource
        /// </summary>
        /// <param name="etlFile">Trace file</param>
        /// <returns></returns>
        public static string[] ExtractManifests(string etlFile)
        {
            IObservable<EtwNativeEvent> all = FromFiles(etlFile);

            var manifests = new SortedSet<string>();
            var sb = new StringBuilder();
            var evt = new ManualResetEvent(false);

            IDisposable d = all.Subscribe(e =>
                {
                    if (e.Id != 0xfffe) // 65534
                    {
                        return;
                    }

                    byte format = e.ReadByte();
                    if (format != 1)
                        throw new Exception("Unsuported manifest format found in EventSource event" + format);

                    byte majorVersion = e.ReadByte();
                    byte minorVersion = e.ReadByte();
                    byte magic = e.ReadByte();
                    if (magic != 0x5b)
                        throw new Exception("Unexpected content in EventSource event that was supposed to have manifest");

                    ushort totalChunks = e.ReadUInt16();
                    ushort chunkNumber = e.ReadUInt16();

                    string chunk = e.ReadAnsiString();
                    sb.Append(chunk);

                    if (chunkNumber == totalChunks - 1)
                    {
                        string manifest = sb.ToString();
                        sb = new StringBuilder();

                        if (!manifests.Contains(manifest))
                        {
                            manifests.Add(manifest);
                        }
                    }
                },
                                          () => evt.Set());

            evt.WaitOne();
            d.Dispose();

            return new List<string>(manifests).ToArray();
        }
开发者ID:40a,项目名称:Tx,代码行数:54,代码来源:EtwObservable.cs

示例12: Main

 static void Main()
 {
     var s1 = new Set<int>();
     s1.Added += (sender, args) => Console.WriteLine("Добавлено: " + args);
     s1.Add(8,2,9);
     var ss1 = new SortedSet<int>(2, 5, 7, 4);
     Console.WriteLine("The first SortedSet: " + ss1);
     Console.WriteLine("Приведённое:" + (Set<int>)ss1);
     var ss2 = new SortedSet<int>(2, 9, 7, 4);
     Console.WriteLine("The second SortedSet: " + ss2);
     Console.WriteLine("Intersection: " + ss1.Intersect(ss2));
     Console.WriteLine("Union: " + ss1.Union(ss2));
     Console.WriteLine("Is the first SortedSet contain " + 5 + ": " + ss1.Contains(5));
     Console.ReadKey();
 }
开发者ID:RavingRabbit,项目名称:Labs,代码行数:15,代码来源:Program.cs

示例13: GenerateQuorum

        private static SortedSet<int> GenerateQuorum(Random randGen, int size, int numParties, Dictionary<int, int> partyPositions)
        {
            // we want deterministic quroum generation using C#'s built in random class
            SortedSet<int> quorum = new SortedSet<int>();

            for (int i = 0; i < size; i++)
            {
                int next = partyPositions[randGen.Next() % numParties];
                if (quorum.Contains(next))
                    i--;
                else
                    quorum.Add(next);
            }

            return quorum;
        }
开发者ID:mahdiz,项目名称:mpclib,代码行数:16,代码来源:QuorumGenerator.cs

示例14: MidiChord

        public MidiChord(int channel, MidiChordDef midiChordDef, OutputDevice midiOutputDevice)
            : base(channel, 0, midiChordDef.MsDuration)
        {
            _midiOutputDevice = midiOutputDevice;

            List<BasicMidiChordDef> basicMidiChordDefs = midiChordDef.BasicMidiChordDefs;
            Debug.Assert(basicMidiChordDefs.Count > 0);
            List<int> realBasicMidiChordDurations = MidiChordDef.GetIntDurations(MsDuration, midiChordDef.BasicChordDurations, basicMidiChordDefs.Count);

            var notesToStop = new SortedSet<byte>();
            int i = 0;
            foreach(BasicMidiChordDef basicMidiChordDef in midiChordDef.BasicMidiChordDefs)
            {
                this._basicMidiChords.Add(new BasicMidiChord(channel, this, basicMidiChordDef, realBasicMidiChordDurations[i++]));
                if(basicMidiChordDef.HasChordOff)
                {
                    foreach(byte note in basicMidiChordDef.Pitches)
                    {
                        if(!notesToStop.Contains(note))
                            notesToStop.Add(note);
                    }
                }
            }

            if(midiChordDef.Bank != null)
            {
                _bank = new BankControl(channel, (byte)midiChordDef.Bank);
            }
            if(midiChordDef.Patch != null)
            {
                _patch = new PatchControl(channel, (byte)midiChordDef.Patch);
            }

            // Moritz currently never repeats MidiChords, so the _repeat field is unnecessary.
            // However: the value of midiChordDef.Repeat is saved in SVG-MIDI files,
            // and may be used by the web AssistantPerformer.
            //_repeat = midiChordDef.Repeat;

            if(midiChordDef.PitchWheelDeviation != null)
            {
                _pitchWheelDeviation = new PitchWheelDeviation(channel, (byte)midiChordDef.PitchWheelDeviation);
            }
            if(midiChordDef.MidiChordSliderDefs != null)
                CreateSliders(channel, midiChordDef.MidiChordSliderDefs, MsDuration);

            SetMessagesDict();
        }
开发者ID:suvjunmd,项目名称:Moritz,代码行数:47,代码来源:MidiChord.cs

示例15: StartGeneration

        public void StartGeneration()
        {
            var books = bookCtx.QBooks;

            var taskList = new List<Task>();

            var dictAuth = new SortedSet<string>();
            var newAuthors = new List<Author>();
            long newAutCount = 0;

            foreach (var book in books)
            {
                if (book.Author != null)
                {
                    //Search
                    if(!dictAuth.Contains(book.Author))
                    {
                        //If not contained then create it
                        dictAuth.Add(book.Author);

                        //Insert Author
                        newAuthors.Add(new Author() {Name = book.Author});
                        newAutCount++;

                        if ((newAutCount % 10000) == 0)
                        {
                            Console.WriteLine("Inserting {0} authors.", newAutCount);
                            taskList.Add(autCtx.Authors.InsertManyAsync(newAuthors));
                            newAuthors = new List<Author>();
                        }

                    }
                }
            }

            if (newAuthors.Count > 0)
            {
                Console.WriteLine("\nInserting {0} authors\n", newAutCount);
                taskList.Add(autCtx.Authors.InsertManyAsync(newAuthors));
                newAuthors = new List<Author>();
            }

            //Wait for all tasks to finish
            Console.WriteLine("Waiting for tasks to complete ...");
            Task.WaitAll(taskList.ToArray());
        }
开发者ID:cesaroll,项目名称:MongoDb_C-Net_BookApp,代码行数:46,代码来源:GenerateAuthors.cs


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