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


C# HashSet.Count方法代码示例

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


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

示例1: PrintChanges

        /// <summary>
        /// Locates the changes between the prior and post state of the modules..
        /// </summary>
        /// <param name="modules_prior">List of the available modules prior to the update.</param>
        /// <param name="modules_post">List of the available modules after the update.</param>
        private void PrintChanges(List<CkanModule> modules_prior, List<CkanModule> modules_post)
        {
            var prior = new HashSet<CkanModule>(modules_prior, new NameComparer());
            var post = new HashSet<CkanModule>(modules_post, new NameComparer());


            var added = new HashSet<CkanModule>(post.Except(prior, new NameComparer()));
            var removed = new HashSet<CkanModule>(prior.Except(post, new NameComparer()));


            var unchanged = post.Intersect(prior);//Default compare includes versions
            var updated = post.Except(unchanged).Except(added).Except(removed).ToList();

            // Print the changes.
            user.RaiseMessage("Found {0} new modules, {1} removed modules and {2} updated modules.", added.Count(), removed.Count(), updated.Count());

            if (added.Count > 0)
            {
                PrintModules("New modules [Name (CKAN identifier)]:", added);
            }

            if (removed.Count > 0)
            {
                PrintModules("Removed modules [Name (CKAN identifier)]:", removed);
            }

            if (updated.Count > 0)
            {
                PrintModules("Updated modules [Name (CKAN identifier)]:", updated);
            }
        }
开发者ID:Zor-X-L,项目名称:CKAN,代码行数:36,代码来源:Update.cs

示例2: Main

        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string pattern = @"(\D+)(\d+)";
            var regex = new Regex(pattern);

            MatchCollection matches = Regex.Matches(input,pattern);

            StringBuilder builder = new StringBuilder();

            foreach (Match match in matches)
            {
                StringBuilder sb = new StringBuilder();
                var message = match.Groups[1].Value.ToUpper();
                var numberOfRepetitions = int.Parse(match.Groups[2].Value);

                for (int i = 0; i < numberOfRepetitions; i++)
                {
                    sb.Append(message);
                }

                builder.Append(sb);
            }
            var set = new HashSet<char>();

            foreach (char ch in builder.ToString())
            {
                set.Add(ch);
            }
            Console.WriteLine("Unique symbols used: {0}", set.Count());
            Console.WriteLine(builder);
        }
开发者ID:Margi13,项目名称:SoftUni,代码行数:32,代码来源:RageQuit.cs

示例3: extract

        public HashSet<String> extract()
        {
            HashSet<String> hashes = new HashSet<String>();
            int totalCount = 0;

            uint maxMemoryChunk = 10 * 1024 * 1024; // 10 megabytes
            byte[] buffer = new byte[maxMemoryChunk];
            while (true)
            {
                int bytesRead = reader.readNextMemoryRegion(buffer, maxMemoryChunk);
                if (0 == bytesRead)
                {
                    Console.WriteLine("Finished reading all regions");
                    break;
                }

                int n = bytesRead - 8;
                for (int i = 0; i < bytesRead; ++i)
                {
                    if ('s' == buffer[i] && isMagic(buffer, i, server.Magic))
                    {
                        totalCount++;
                        hashes.Add(BitConverter.ToString(buffer, i + 8, 32).ToLower().Replace("-", ""));
                    }
                }
            }

            Console.WriteLine("Number of unique s2gs hash strings found: " + hashes.Count());
            Console.WriteLine("Number of total s2gs hash strings found: " + totalCount);

            return hashes;
        }
开发者ID:gibybo,项目名称:S2GS-Extractor,代码行数:32,代码来源:S2GSExtractor.cs

示例4: textBox1_TextChanged

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

            //Unsorted 
            HashSet<int> set = new HashSet<int>();
            List<int> list = new List<int>();
            SortedSet<int> sortset = new SortedSet<int>();
            StringBuilder s = new StringBuilder();
            Random rand = new Random();

            //Add random numbers to a list (not ordered)
            for (int i = 0; i < 10000; i++) { list.Add(rand.Next(1, 20000)); }

            //Place unique numbers from the list previously generated into a hashset
            for (int i = 0; i < 10000; i++) { set.Add(list[i]); }

            //Sorts the list of random numbers through the use of a Sortedset
            for (int i = 0; i < 10000; i++) { sortset.Add(list[i]); }

            //count distinct characters in the list 
            int unique = (from i in list select i).Distinct().Count();

            //String formatting
            s.Append("1. Hashset method: " + set.Count().ToString() + " unique numbers." +
            "The time complexity of this code is O(nlog(n) + 2n), because the intialization of variables " +
            "is O(1) and the add function for the hashset and list is O(1). Therefore the algorithm executes" +
            "10000 times twice and we'll mark this up to be (2n)." +
            "This gives us a time complexity for the aglorithm to be O(2n). Then the add time complexity for the sortedset is nlogn which consequatnly"+
            "gives us O(nlog(n) + 2n)");
            s.Append("\r\n2. " + unique.ToString() + " unique numbers.");
            s.Append("\r\n3. " + sortset.Count().ToString() + " unique numbers");
            textBox1.Text = s.ToString();                  
        }
开发者ID:russvick,项目名称:CS322,代码行数:33,代码来源:Form1.cs

示例5: problem

 public static void problem(int[] numbers, int raznica)
 {
     HashSet<int> lilu = new HashSet<int>(numbers);
     int counter = lilu
         .Count(p => lilu.Contains(p + raznica));
     Console.WriteLine(counter);
 }
开发者ID:Elta20042004,项目名称:Training,代码行数:7,代码来源:Program.cs

示例6: UndoRedoPerformed

		public override void UndoRedoPerformed(List<GameObject> modified)
		{
			modifiedMeshes = new HashSet<Mesh>(modifiedMeshes.Where(x => x != null));

			if(z_ReflectionUtil.ProBuilderExists())
			{
				// delete & undo causes cases where object is not null but the reference to it's pb_Object is
				HashSet<object> remove = new HashSet<object>();

				foreach(object pb in modifiedPbMeshes)
				{
					try
					{
						z_ReflectionUtil.Invoke(pb, "ToMesh");
						z_ReflectionUtil.Invoke(pb, "Refresh");
						z_ReflectionUtil.Invoke(null, z_Pref.PB_EDITOR_MESH_UTILITY_TYPE, "Optimize", BindingFlags.Public | BindingFlags.Static, z_Pref.PB_EDITOR_ASSEMBLY, pb);
					}
					catch
					{
						remove.Add(pb);
					}

				}

				if(remove.Count() > 0)
					modifiedPbMeshes.SymmetricExceptWith(remove);
			}

			foreach(Mesh m in modifiedMeshes)
				m.vertices = m.vertices;

			base.UndoRedoPerformed(modified);
		}
开发者ID:alex-carlson,项目名称:PixelitisGGJ,代码行数:33,代码来源:z_BrushModeMesh.cs

示例7: GetRandomAuthors

        public ICollection<AuthorModel> GetRandomAuthors(int rightAuthorId)
        {
            var authorIds = this.data.Authors
             .All()
             .Select(a => a.Id)
             .ToList();

            var randomAuthorIds = new HashSet<int>();
            randomAuthorIds.Add(rightAuthorId);

            while (randomAuthorIds.Count() < GlobalConstants.NumberOfAuthorsToChoose)
            {
                var randomAuthorId = this.GetRandomAuthorId(authorIds);
                randomAuthorIds.Add(randomAuthorId);
            }

            var randomAuthors = this.data.Authors
                .All()
                .Where(a => randomAuthorIds.Contains(a.Id))
                .OrderBy(a => a.FullName)
                .ProjectTo<AuthorModel>()
                .ToList();

            return randomAuthors;
        }
开发者ID:dragandraganov,项目名称:FamousQuoteQuiz,代码行数:25,代码来源:RandomFactory.cs

示例8: TestEdbLogging

        public void TestEdbLogging()
        {
            Init();

            var queryArgs = new Dictionary<string, string>
            {
                { "@source.environment", TestName },
                { "@source.groupId", CurrentGroupId },
                { "@source.path", "EDB_expected_event_sources.log" }
            };

            var expectedLines = File.ReadAllText(@"Expected\EdbLoggingTest.txt").Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            var expected = new HashSet<string>(expectedLines);

            GetAndValidateRecords(queryArgs, new [] { "@message" }, expected.Count(),
                records =>
                {
                    foreach (var record in records)
                    {
                        var message = (JContainer)JsonConvert.DeserializeObject(record.Fields["@message"]);
                        message.Children().First().Remove();
                        var lineText = JsonConvert.SerializeObject(message);
                        Assert.IsTrue(expected.Contains(lineText));
                    }
                }, 3);
        }
开发者ID:geffzhang,项目名称:LogSearchShipper,代码行数:26,代码来源:EdbLoggingTest.cs

示例9: Main

        string Main()
        {
            int position = 1;
            int smallGap = 2;
            int bigGap = 4;
            int totalPrimeCount = 0;

            HashSet<int> diagonals = new HashSet<int>();
            diagonals.Add(1);

            while (true)
            {
                for (int i = 0; i < 4; i++)
                {
                    position += smallGap;
                    diagonals.Add(position);
                    if (UsefulFunctions.IsPrime(position))
                        totalPrimeCount++;
                }

                double average = (double)totalPrimeCount / diagonals.Count();

                if (average < .10)
                {
                    break;
                }

                smallGap += 2;
                bigGap += 2;
            }
            return (bigGap - 1).ToString();
        }
开发者ID:colvinm0037,项目名称:Euler,代码行数:32,代码来源:Euler_058_Version_2.cs

示例10: Solve

        public long Solve()
        {
            var primes = new Prime((long)Math.Sqrt(Limit) + 1).PrimeList;

            var squerePrimes = new List<long>();
            var cubePrimes = new List<long>();
            var fourthPrimes = new List<long>();

            var cubeLimit = false;
            var fourthLimit = false;
            foreach (var prime in primes)
            {
                var squere = prime * prime;
                squerePrimes.Add(squere);

                if (!cubeLimit)
                {
                    var cube = squere * prime;

                    if (cube > Limit)
                    {
                        cubeLimit = true;
                        continue;
                    }
                    cubePrimes.Add(cube);
                }

                if (!fourthLimit)
                {
                    var fourth = squere * squere;
                    if (fourth > Limit)
                    {
                        fourthLimit = true;
                        continue;
                    }
                    fourthPrimes.Add(fourth);
                }
            }

            Console.WriteLine(squerePrimes.Count);
            Console.WriteLine(cubePrimes.Count);
            Console.WriteLine(fourthPrimes.Count);

            var numbers = new HashSet<long>();

            foreach (var cubePrime in cubePrimes)
            {
                foreach (var squerePrime in squerePrimes)
                {
                    foreach (var fourthPrime in fourthPrimes)
                    {
                        numbers.Add(cubePrime + squerePrime + fourthPrime);
                    }
                }
            }

            return numbers.Count(t => t < Limit);
        }
开发者ID:joeazbest,项目名称:Euler,代码行数:58,代码来源:Problem087.cs

示例11: RearsegmentBackups

 public RearsegmentBackups(IEnumerable<Segment> segments,
     HashSet<NodeEndpoint> endpoints,
     int numberOfBackCopiesToKeep)
 {
     this.segments = segments;
     this.endpoints = endpoints;
     this.numberOfBackCopiesToKeep = numberOfBackCopiesToKeep;
     fairDistribution = (segments.Count() * numberOfBackCopiesToKeep) / endpoints.Count() + 1;
     currentDistribution = PrepareDistributions();
 }
开发者ID:vebin,项目名称:rhino-dht,代码行数:10,代码来源:RearrangeBackups.cs

示例12: GetRequestedByFromChangeset

        private static string GetRequestedByFromChangeset(IEnumerable<IBuildInformationNode> changesets)
        {
            var users = new HashSet<String>();
            foreach (var changeset in changesets)
                users.Add(changeset.Fields["CheckedInBy"]);

            var count = users.Count();
            if (count > 1)
                return "(Multiple Users)";
            return users.First();
        }
开发者ID:dirkrombauts,项目名称:SirenOfShame,代码行数:11,代码来源:CheckinInfoGetterService.cs

示例13: Solve

        public long Solve()
        {
            var primes = new List<int> { 2, 3, 5, 7 };
            var truncatePrimes = new HashSet<int>();
            var posibleLeftPrimes = new List<int>();
            var posibleRightPrimes = new List<int>();

            while (truncatePrimes.Count() < 11)
            {
            }

            return 0;
        }
开发者ID:joeazbest,项目名称:Euler,代码行数:13,代码来源:Problem037.cs

示例14: ShuffleDeck

 public void ShuffleDeck()
 {
     if (this.cards.Count() != 0) throw new Exception();
     HashSet<int> indicesTaken = new HashSet<int>();
     while (this.cards.Count() < allCards.Count) {
         int idxToTake = rng.Next(0, allCards.Count);
         if (!indicesTaken.Contains(idxToTake)) {
             this.cards.Push(allCards[idxToTake]);
             indicesTaken.Add(idxToTake);
         }
     }
     if (indicesTaken.Count() != allCards.Count) throw new Exception();
 }
开发者ID:Amichai,项目名称:Set,代码行数:13,代码来源:Deck.cs

示例15: IsConnected

        public bool IsConnected()
        {
            HashSet<Point> allPathablePoints = new HashSet<Point>();
            foundPathablePoints = new HashSet<Point>();

            for (int i = 0; i < thisMap.Width; i++)
            {
                for (int j = 0; j < thisMap.Height; j++)
                {
                    if(CountsAsWalkable(thisMap.getCell(i, j)))
                        allPathablePoints.Add(new Point(i, j));
                }
            }

            if(allPathablePoints.Count() == 0)
                return true;

            Stack<Point> workNodes = new Stack<Point>();

            workNodes.Push(allPathablePoints.First());

            while (workNodes.Count() > 0)
            {
                var thisNode = workNodes.Pop();
                if (CountsAsWalkable(thisMap.getCell(thisNode.x, thisNode.y)))
                {
                    foundPathablePoints.Add(thisNode);
                    var neighbours = Get4WayNeighbours(thisNode);
                    foreach (var p in neighbours)
                        workNodes.Push(p);
                }
            }

            if (allPathablePoints.Intersect(foundPathablePoints).Count() == allPathablePoints.Count())
                return true;

            return false;
        }
开发者ID:Sinellil,项目名称:roguelike-cs,代码行数:38,代码来源:RoomFilling.cs


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