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


C# HashSet.Contains方法代码示例

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


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

示例1: getTypes

        private static IEnumerable<Type> getTypes(Type sourceType)
        {
            Queue<Type> pending = new Queue<Type>();
            HashSet<Type> visited = new HashSet<Type>();
            pending.Enqueue(sourceType);

            while (pending.Count != 0)
            {
                Type type = pending.Dequeue();
                visited.Add(type);
                yield return type;

                if (type.BaseType != null)
                {
                    if (!visited.Contains(type.BaseType))
                    {
                        pending.Enqueue(type.BaseType);
                    }
                }

                foreach (Type interfaceType in type.GetInterfaces())
                {
                    if (!visited.Contains(interfaceType))
                    {
                        pending.Enqueue(interfaceType);
                    }
                }
            }
        }
开发者ID:khoaho,项目名称:mustache-sharp,代码行数:29,代码来源:UpcastDictionary.cs

示例2: Main

 static void Main(string[] args)
 {
     var letters = new HashSet<char>("the quick brown fox");
     Console.WriteLine(letters.Contains('t')); // true
     Console.WriteLine(letters.Contains('j')); // false
     foreach (char c in letters)
     {
         Console.Write(c); // the quickbrownfx
     }
     letters.IntersectWith("aeiou");
     foreach (char c in letters)
     {
         Console.Write(c); // euio
     }
     var letters2 = new HashSet<char>("the quick brown fox");
     letters2.ExceptWith("aeiou");
     foreach (char c in letters2)
     {
         Console.Write(c); // th qckbrwnfx
     }
     var letters3 = new HashSet<char>("the quick brown fox");
     letters3.SymmetricExceptWith("the lazy brown fox");
     foreach (char c in letters3)
     {
         Console.Write(c); // quicklazy
     }
 }
开发者ID:PhilTheAir,项目名称:CSharp,代码行数:27,代码来源:HashSetContainer.cs

示例3: GetPermissions

        public Task<PermissionSet> GetPermissions(IReadOnlyList<SignatureEvidence> authentication, LedgerPath path, bool recursiveOnly, string recordName)
        {
            HashSet<string> identities = new HashSet<string>(authentication.Select(evidence => keyEncoder.GetPubKeyHash(evidence.PublicKey)), StringComparer.Ordinal);
            LedgerPath pathRecordName;

            // If the path is root and the record name is a tird-party asset owned by the current identity,
            // arbitrary modification of the balance is allowed
            if (LedgerPath.TryParse(recordName, out pathRecordName)
                && thirdPartyAssetPath.IsStrictParentOf(pathRecordName)
                && path.Segments.Count == 0
                && identities.Contains(pathRecordName.Segments[thirdPartyAssetPath.Segments.Count]))
            {
                return Task.FromResult(new PermissionSet(accountNegative: Access.Permit));
            }

            // Account /asset/p2pkh/[addr]/
            if (thirdPartyAssetPath.IsStrictParentOf(path)
                && path.Segments.Count == thirdPartyAssetPath.Segments.Count + 1
                && keyEncoder.IsP2pkh(path.Segments[path.Segments.Count - 1]))
            {
                Access ownAccount = identities.Contains(path.Segments[path.Segments.Count - 1]) && recordName != DynamicPermissionLayout.AclResourceName
                    ? Access.Permit : Access.Unset;

                return Task.FromResult(new PermissionSet(
                    accountModify: Access.Permit,
                    accountCreate: Access.Permit,
                    accountSpend: ownAccount,
                    dataModify: ownAccount));
            }
            else
            {
                return Task.FromResult(new PermissionSet());
            }
        }
开发者ID:juanfranblanco,项目名称:openchain,代码行数:34,代码来源:P2pkhIssuanceImplicitLayout.cs

示例4: WriteDirectory

        /// <summary>
        /// Writes index files into the specified directory.
        /// </summary>
        /// <param name="indexDirectory">The directory into which the index files should be written.</param>
        /// <param name="recordMapper">The mapper for the records.</param>
        /// <param param name="records">The records which should be written.</param>
        public void WriteDirectory(DirectoryInfo indexDirectory, IRecordMapper<string> recordMapper, IEnumerable<IReferenceRecord> records)
        {
            if (!indexDirectory.Exists)
            {
                indexDirectory.Create();
            }

            var directoryNames = new HashSet<string>();
            foreach (var directory in indexDirectory.GetDirectories())
            {
                if (!directoryNames.Contains(directory.Name))
                {
                    directoryNames.Add(directory.Name);
                }
            }
            foreach (var record in records)
            {
                var directoryName = recordMapper.Map(record);
                if (!directoryNames.Contains(directoryName))
                {
                    indexDirectory.CreateSubdirectory(directoryName);
                    directoryNames.Add(directoryName);
                }

                // Write index files into the index directory
            }
        }
开发者ID:gisfromscratch,项目名称:geocoding-samples,代码行数:33,代码来源:IndexDirectoryWriter.cs

示例5: Solve

    long Solve(int N, List<int> A, int I, HashSet<int> used, int need)
    {
        long result = 0;
          for (int i = 1; i <= N; i++) {

         if (used.Contains(i)) {
            continue;
         }

         var n = i - A[I] > 0 ? need - (i - A[I]) : need;
         if (n <= 0) {
            int c = 0;
            for (int j = 1; j <= N; j++) {
               if (!used.Contains(j) && j != i) {
                  c++;
               }
            }
            result += Prod(Enumerable.Range(1, c).ToList());
         } else {
            used.Add(i);
            result += Solve(N, A, I + 1, used, n);
            used.Remove(i);
         }
          }

          return result;
    }
开发者ID:gwominglee,项目名称:competition,代码行数:27,代码来源:592-med.cs

示例6: ConnectedComponents

 public List<Graph> ConnectedComponents()
 {
     List<Graph> ret = new List<Graph>();
     HashSet<int> visited = new HashSet<int>();
     Queue<int> queue = new Queue<int>();
     ForEachVertex((v) =>
         {
             if (!visited.Contains(v))
             {
                 Graph g = new Graph();
                 queue.Enqueue(v);
                 visited.Add(v);
                 while (queue.Count != 0)
                 {
                     int u = queue.Dequeue();
                     g.storage[u] = storage[u];
                     ForEachNeighbor(u, (w) =>
                         {
                             if (!visited.Contains(w))
                             {
                                 queue.Enqueue(w);
                                 visited.Add(w);
                             }
                         });
                 }
                 ret.Add(g);
             }
         });
     return ret;
 }
开发者ID:v-yadli,项目名称:Split-decomposition,代码行数:30,代码来源:Graph.cs

示例7: GetFullSort

        internal IEnumerable<SortingInfo> GetFullSort() {
            var memo = new HashSet<string>();
            var result = new List<SortingInfo>();

            if(HasGroups) {
                foreach(var g in Group) {
                    if(memo.Contains(g.Selector))
                        continue;

                    memo.Add(g.Selector);
                    result.Add(g);
                }
            }

            if(HasSort) {
                foreach(var s in Sort) {
                    if(memo.Contains(s.Selector))
                        continue;

                    memo.Add(s.Selector);
                    result.Add(s);
                }
            }

            IEnumerable<string> requiredSort = new string[0];

            if(HasDefaultSort)
                requiredSort = requiredSort.Concat(new[] { DefaultSort });

            if(HasPrimaryKey)
                requiredSort = requiredSort.Concat(PrimaryKey);

            return Utils.AddRequiredSort(result, requiredSort);
        }
开发者ID:DevExpress,项目名称:DevExtreme.AspNet.Data,代码行数:34,代码来源:DataSourceLoadOptionsBase.cs

示例8: CalculateBudgetUsed

        public int CalculateBudgetUsed()
        {
            this.edges.Sort();
            var graph = BuildGraph();
            var spanningTreeNodes = new HashSet<int>();
            var connectedEdges = this.edges
                .Where(e => e.IsConnected);
            foreach (var connectedEdge in connectedEdges)
            {
                spanningTreeNodes.Add(connectedEdge.StartNode);
                spanningTreeNodes.Add(connectedEdge.EndNode);
            }

            foreach (var edge in edges)
            {
                if (!spanningTreeNodes.Contains(edge.StartNode))
                {
                    Prim(graph, spanningTreeNodes, edge.StartNode);
                }

                if (!spanningTreeNodes.Contains(edge.EndNode))
                {
                    Prim(graph, spanningTreeNodes, edge.EndNode);
                }
            }

            var budgetUsed = this.startBudget - this.leftBudget;
            return budgetUsed;
        }
开发者ID:SoftUniCourses,项目名称:Algorithms,代码行数:29,代码来源:CableNetworkExtender.cs

示例9: Evaluate

        internal override ThreeValuedLogic Evaluate(Strategy strategy)
        {
            var containing = new HashSet<IObject>(this.containingEnumerable);

            if (this.associationType.IsMany)
            {
                var associations = strategy.GetCompositeAssociations(this.associationType);
                foreach (var assoc in associations)
                {
                    if (containing.Contains((IObject)assoc))
                    {
                        return ThreeValuedLogic.True;
                    }
                }

                return ThreeValuedLogic.False;
            }

            var association = strategy.GetCompositeAssociation(this.associationType);
            if (association != null)
            {
                return containing.Contains(association)
                           ? ThreeValuedLogic.True
                           : ThreeValuedLogic.False;
            }

            return ThreeValuedLogic.False;
        }
开发者ID:whesius,项目名称:allors,代码行数:28,代码来源:AssociationContainedInEnumerable.cs

示例10: SimpleMergeSucceeds

        public void SimpleMergeSucceeds()
        {
            var lengths = new[] { 1, 3, 4, 6 };
            var words = new[] { "car", "dog", "free", "sixpack" };

            var uniqueLengths = new HashSet<int>();
            var uniqueWords = new HashSet<string>();
            var pairs = new HashSet<Tuple<int, string>>();

            lengths.Merge(
                words,
                l => l,
                w => w.Length,
                l => uniqueLengths.Add(l),
                w => uniqueWords.Add(w),
                (l, w) => pairs.Add(Tuple.Create(l, w))
            );

            Assert.AreEqual(2, uniqueLengths.Count);
            Assert.IsTrue(uniqueLengths.Contains(1));
            Assert.IsTrue(uniqueLengths.Contains(6));

            Assert.AreEqual(1, uniqueWords.Count);
            Assert.IsTrue(uniqueWords.Contains("sixpack"));

            Assert.AreEqual(3, pairs.Count);
            Assert.IsTrue(pairs.Contains(Tuple.Create(3, "car")));
            Assert.IsTrue(pairs.Contains(Tuple.Create(3, "dog")));
            Assert.IsTrue(pairs.Contains(Tuple.Create(4, "free")));
        }
开发者ID:jeremysimmons,项目名称:sixpack-library,代码行数:30,代码来源:MergeExtensionsTests.cs

示例11: MergeWithNullKeysSucceeds

        public void MergeWithNullKeysSucceeds()
        {
            var wordsA = new[] { "car", "dog", "free", null };
            var wordsB = new[] { "car", "dog", "free", "sixpack" };

            var uniqueA = new HashSet<string>();
            var uniqueB = new HashSet<string>();
            var pairs = new HashSet<string>();

            wordsA.Merge(
                wordsB,
                a => a,
                b => b,
                a => uniqueA.Add(a),
                b => uniqueB.Add(b),
                (a, b) => pairs.Add(a)
            );

            Assert.AreEqual(1, uniqueA.Count);
            Assert.IsTrue(uniqueA.Contains(null));

            Assert.AreEqual(1, uniqueB.Count);
            Assert.IsTrue(uniqueB.Contains("sixpack"));

            Assert.AreEqual(3, pairs.Count);
            Assert.IsTrue(pairs.Contains("car"));
            Assert.IsTrue(pairs.Contains("dog"));
            Assert.IsTrue(pairs.Contains("free"));
        }
开发者ID:jeremysimmons,项目名称:sixpack-library,代码行数:29,代码来源:MergeExtensionsTests.cs

示例12: LongestConsecutiveSolution

        public int LongestConsecutiveSolution(int[] nums)
        {
            int length = nums.Length;
            HashSet<int> set = new HashSet<int>();
            int max=0;
            foreach(int cur in nums)
                set.Add(cur);

            foreach (int cur in nums)
            {
                int len=1;
                int left = cur - 1;
                int right = cur + 1;
                while (set.Contains(left))
                {
                    len++;
                    set.Remove(left);
                    left--;
                }
                while (set.Contains(right))
                {
                    len++;
                    set.Remove(left);
                    right++;
                }

                max = max > len ? max : len;
            }
            return max;
        }
开发者ID:FJuly,项目名称:FLeetCode,代码行数:30,代码来源:LongestConsecutiveSequence+.cs

示例13: Main

        static void Main(string[] args)
        {
            int number = int.Parse(Console.ReadLine());

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

            for (int x = 2; x < number; x++)
            {
                for (int y = x * 2; y < number; y = y + x)
                {
                    if (!NoPrime.Contains(y))
                    {
                        NoPrime.Add(y);
                    }
                }
            }

            Console.Write("2");

            for (int z = 3; z <= number ; z++)
            {
                if (z != number)
                {
                    if (!NoPrime.Contains(z))
                    {
                        Console.Write(", " + z);
                    }
                }
            }
            Console.WriteLine();
        }
开发者ID:georgidhristov,项目名称:Advanced-Csharp,代码行数:31,代码来源:Program.cs

示例14: Solve

        public override string Solve()
        {
            var denominators = new List<BigInteger>();
            var numbersToSkip = new HashSet<decimal> { 10, 20, 30, 40, 50, 60, 70, 80, 90 };
            for (decimal numerator = 10; numerator < 100; numerator++) {
                for (decimal denominator = 10; denominator < 100; denominator++) {
                    if (numbersToSkip.Contains(numerator) && numbersToSkip.Contains(denominator)) {
                        continue;
                    }
                    if (numerator == denominator) {
                        continue;
                    }

                    decimal? numberInBoth = GetNumberInboth(numerator, denominator);
                    if (numberInBoth != null) {
                        var one = numerator / denominator;
                        if (one > 1) continue;

                        var newDenominator = RemoveNumber(numberInBoth.Value, denominator);

                        if (newDenominator == 0) {
                            continue;
                        }
                        var newNumerator = RemoveNumber(numberInBoth.Value, numerator);
                        var two = newNumerator / newDenominator;
                        if (one == two) {
                            denominators.Add(BigInteger.Parse(newDenominator.ToString()));
                        }
                    }
                }
            }

            var product = denominators[0] * denominators[1] * denominators[2];
            return product.ToString();
        }
开发者ID:apalumbi,项目名称:Euler,代码行数:35,代码来源:Problem33.cs

示例15: Reset

    public void Reset(IEnumerable<ItemReference> refsToKeep)
    {
      if (refsToKeep.Any())
      {
        var refsToKeepHash = new HashSet<ItemReference>(refsToKeep);

        // Clean up the definitions as necessary
        var defnsToRemove = (from p in _allDefinitions where !refsToKeepHash.Contains(p.Value) select p.Key).ToList();
        foreach (var defnToRemove in defnsToRemove)
        {
          _allDefinitions.Remove(defnToRemove);
        }

        // Clean up the dependencies as necessary
        foreach (var depend in _allDependencies)
        {
          depend.Value.RemoveAllButMasterList(refsToKeepHash);
        }

        // Remove dependency information
        var itemsToRemove = (from p in _allItemDependencies where !refsToKeepHash.Contains(p.Key) select p.Key).ToList();
        foreach (var itemToRemove in itemsToRemove)
        {
          _allItemDependencies.Remove(itemToRemove);
        }
      }
      else
      {
        this.Reset();
      }
    }
开发者ID:rneuber1,项目名称:InnovatorAdmin,代码行数:31,代码来源:DependencyAnalyzer.cs


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