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


C# ISet.Contains方法代码示例

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


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

示例1: WalkCircularDependency

        private static IEnumerable<BuildItem> WalkCircularDependency(BuildItem item, IDictionary<BuildItem, List<BuildItem>> scriptsToDependencies, ISet<BuildItem> visitedItems, out bool isCircularPath)
        {
            if(visitedItems.Contains(item))
            {
                isCircularPath = true;
                return Enumerable.Repeat(item, 1);
            }
            if (!scriptsToDependencies.ContainsKey(item))
            {
                isCircularPath = false;
                return Enumerable.Empty<BuildItem>();
            }

            visitedItems.Add(item);
            foreach (var d in scriptsToDependencies[item])
            {
                bool currentIsCircular;
                var currentPath = WalkCircularDependency(d, scriptsToDependencies, visitedItems, out currentIsCircular);
                if(currentIsCircular)
                {
                    isCircularPath = true;
                    return Enumerable.Repeat(item, 1).Concat(currentPath);
                }
            }

            isCircularPath = false;
            return Enumerable.Empty<BuildItem>();
        }
开发者ID:Zocdoc,项目名称:ZocBuild.Database,代码行数:28,代码来源:CircularDependencyError.cs

示例2: GetVariableName

		public string GetVariableName(string desiredName, ISet<string> usedNames) {
			string baseName = (desiredName != null ? desiredName.Replace("<>", "$") : "$t");
			if (desiredName != null && !usedNames.Contains(baseName) && !Saltarelle.Compiler.JSModel.Utils.IsJavaScriptReservedWord(desiredName) && baseName != "ss")
				return baseName;
			int i = 1;
			string name;
			do {
				name = baseName + (i++).ToString(CultureInfo.InvariantCulture);
			} while (usedNames.Contains(name));

			return name;
		}
开发者ID:ShuntaoChen,项目名称:SaltarelleCompiler,代码行数:12,代码来源:Namer.cs

示例3: WordBreak

    public bool WordBreak(string s, ISet<string> wordDict)
    {
        // Check Bad Input Values
        if (wordDict == null || wordDict.Count == 0)
            return false;
        if (string.IsNullOrEmpty(s))
            return wordDict.Contains(s);

        // Check the whole word first
        if (wordDict.Contains(s))
            return true;

        int n = s.Length;
        // Suppose i is the start of a word and j it's end with 0 < i <= j< n
        // Lets create a table C (n*n) that check if s(i,j) is breakable
        // We have this formula for C[i,j]
        // C[i,j] = C[i,j-1] and s[j,j] is in the dictionary
        // C[i,j] = s(i,j) is in dictionary
        // C[i,j] = C[i,k] and s(k+1,j) is in dictonary, 0<k<j
        bool[,] C = new bool[n, n]; // initialiazed to false;

        // Fill the diagonal by checking if a word i,i is in the dictionary
        for (int i = 0; i < n; ++i)
        {
            C[i, i] = wordDict.Contains(s.Substring(i, 1));
        }

        // Compute C[0,j] here
        for (int j = 1; j < n; ++j)
        {
            C[0, j] = C[0, j] ||
              (C[0, j - 1] && C[j, j]) || // C[i,j-1] and s[j,j] is in the dictionary
              wordDict.Contains(s.Substring(0, j + 1));//s(i,j) is in dictionary
            if (!C[0, j])
            {
                // Search for k: C[i,j] = C[i,k] and s(k+1,j) is in dictonary, 0<k<j
                int k = 0;
                while (k < j - 1 && !C[0, j])
                {
                    C[k + 1, j] = wordDict.Contains(s.Substring(k + 1, j - k));
                    C[0, j] = C[0, k] && C[k + 1, j];
                    ++k;
                }
            }
        }

        // Return true if s(0,n-1) is breakable
        return C[0, n - 1];
    }
开发者ID:einstenwolfgang,项目名称:leetcode-exercise,代码行数:49,代码来源:Word+Break.cs

示例4: MakeParametersUnique

        private static int MakeParametersUnique(ScriptAction action, ISet<Tuple<string, string>> properties, int sequence)
        {
            if (action.ConfigurationVariables == null)
            {
                return sequence;
            }

            foreach (var configVar in action.ConfigurationVariables)
            {
                var tuple = Tuple.Create(CleanInvalidCharacters(configVar.OriginalName), configVar.Value);
                if (!properties.Contains(tuple))
                {
                    if (properties.Any(p => p.Item1 == tuple.Item1 && p.Item2 != tuple.Item2))
                    {
                        var newVariableName = configVar.RemappedName + sequence;
                        sequence++;
                        action.Arguments = action.Arguments?.Replace(configVar.RemappedName, newVariableName);
                        configVar.RemappedName = newVariableName;
                    }
                }

                properties.Add(tuple);
            }

            return sequence;
        }
开发者ID:DanielBMann9000,项目名称:Migrate-assets-from-RM-server-to-VSTS,代码行数:26,代码来源:UniquePropertyResolver.cs

示例5: B_Relation

        private static RelationMatrix B_Relation( IGrammar grammar, ISet<GrammaticalSymbol> epsilon_grammaticals )
        {
            var relation = new RelationMatrix(grammar.Terminals.Count + grammar.Grammaticals.Count);
            foreach( var rule in grammar.Rules )
                for( int i = 1; i < rule.RightHandSide.Count; ++i )
                {
                    relation[
                        grammar.GlobalIndexOf(rule.RightHandSide[i - 1]),
                        grammar.GlobalIndexOf(rule.RightHandSide[i])] = true;

                    for( int j = i + 1; j < rule.RightHandSide.Count; ++j )
                        if( rule.RightHandSide[j - 1] is GrammaticalSymbol &&
                            epsilon_grammaticals.Contains((GrammaticalSymbol)rule.RightHandSide[j - 1]) )
                        {
                            relation[
                                grammar.GlobalIndexOf(rule.RightHandSide[i - 1]),
                                grammar.GlobalIndexOf(rule.RightHandSide[j])] = true;
                        }
                        else
                        {
                            break;
                        }
                }

            return relation;
        }
开发者ID:mqrelly,项目名称:Syntan,代码行数:26,代码来源:FollowSets.cs

示例6: WordBreakDFS

        private void WordBreakDFS(string s, ISet<string> wordDict, List<string> ret, List<string> list, int index, int len, bool[] canBreak)
        {
            if (!canBreak[index])
            {
                return;
            }

            //to the end of string
            if (index == len)
            {
                StringBuilder sb = new StringBuilder();
                foreach (string item in list)
                {
                    sb.Append(item);
                    sb.Append(" ");
                }

                sb = sb.Remove(sb.Length - 1, 1);
                ret.Add(sb.ToString());
            }

            for (int i = index; i < s.Length; i++)
            {
                string sub = s.Substring(index, i - index + 1);
                if (!wordDict.Contains(sub))
                {
                    continue;
                }

                list.Add(sub);
                WordBreakDFS(s, wordDict, ret, list, i + 1, len, canBreak);
                list.RemoveAt(list.Count - 1);
            }
        }
开发者ID:feifeiyu777,项目名称:Algorithm,代码行数:34,代码来源:DPProblem.cs

示例7: ReadAssets

            private IList<ValueTuple<Checksum, object>> ReadAssets(
                Stream stream, int sessionId, ISet<Checksum> checksums, CancellationToken cancellationToken)
            {
                var results = new List<ValueTuple<Checksum, object>>();

                using (var reader = new ObjectReader(stream))
                {
                    var responseSessionId = reader.ReadInt32();
                    Contract.ThrowIfFalse(sessionId == responseSessionId);

                    var count = reader.ReadInt32();
                    Contract.ThrowIfFalse(count == checksums.Count);

                    for (var i = 0; i < count; i++)
                    {
                        var responseChecksum = new Checksum(reader.ReadArray<byte>());
                        Contract.ThrowIfFalse(checksums.Contains(responseChecksum));

                        var kind = reader.ReadString();

                        // in service hub, cancellation means simply closed stream
                        var @object = _owner.RoslynServices.AssetService.Deserialize<object>(kind, reader, cancellationToken);

                        results.Add(ValueTuple.Create(responseChecksum, @object));
                    }

                    return results;
                }
            }
开发者ID:genlu,项目名称:roslyn,代码行数:29,代码来源:SnapshotService.JsonRpcAssetSource.cs

示例8: CreatesNewLife

        public static bool CreatesNewLife(this Cell cell, ISet<Cell> cells, out ISet<Cell> newLife)
        {
            var emptyNeighbors = cellTransform.Select(t => cell + t).Where(c => !cells.Contains(c));
            newLife = new HashSet<Cell>(emptyNeighbors.Where(n => GetNeighbors(n, cells).Count() == 3));

            return newLife.Any();
        }
开发者ID:thomas-holmes,项目名称:GameOfLife,代码行数:7,代码来源:CellExtensions.cs

示例9: AddFromProperties

        private void AddFromProperties(IEnumerable<PropertyInfo> properties, String accessType, ISet<String> persistentProperties)
        {
            //ORIG: foreach (XProperty property in properties) {
            foreach (PropertyInfo property in properties) {
                // If this is not a persistent property, with the same access type as currently checked,
                // it's not audited as well.
                if (persistentProperties.Contains(property.Name)) {
                    IValue propertyValue = _persistentPropertiesSource.GetProperty(property.Name).Value;

                    PropertyAuditingData propertyData;
                    bool isAudited;
                    if (propertyValue is Component) {
                        ComponentAuditingData componentData = new ComponentAuditingData();
                        isAudited = FillPropertyData(property, componentData, accessType);

                        IPersistentPropertiesSource componentPropertiesSource = new ComponentPropertiesSource(
                                (Component) propertyValue);
                        new AuditedPropertiesReader(ModificationStore.FULL, componentPropertiesSource, componentData,
                                _globalCfg,
                                _propertyNamePrefix + MappingTools.createComponentPrefix(property.Name))
                                .read();

                        propertyData = componentData;
                    } else {
                        propertyData = new PropertyAuditingData();
                        isAudited = FillPropertyData(property, propertyData, accessType);
                    }

                    if (isAudited) {
                        // Now we know that the property is audited
                        _auditedPropertiesHolder.addPropertyAuditingData(property.Name, propertyData);
                    }
                }
            }
        }
开发者ID:hazzik,项目名称:nhcontrib-all,代码行数:35,代码来源:AuditedPropertiesReader.cs

示例10: Build

        /// <summary>
        /// Calculates the first sets of all grammaticals of the given <paramref name="grammar"/>.
        /// </summary>
        /// <param name="grammar">The grammaticals which are to examen, are in this grammar.</param>
        /// <param name="epsilon_grammaticals">Set of the epsilon capable grammaticals of the given 
        /// <paramref name="grammar"/>. (see <see cref="EpsilonGrammaticals"/>)</param>
        /// <returns>The first sets for all the grammaticals of the given <paramref name="grammar"/>.</returns>
        /// <exception cref="ArgumentNullException"> if any of the parameters is <c>null</c>.</exception>
        public static IDictionary<GrammaticalSymbol, ISet<TerminalSymbol>> Build(
            ExtendedGrammar grammar, ISet<GrammaticalSymbol> epsilon_grammaticals)
        {
            if( grammar == null )
                throw new ArgumentNullException("grammar");
            if( epsilon_grammaticals == null )
                throw new ArgumentNullException("epsilon_grammaticals");

            // Relation matrix
            var f_plus = new RelationMatrix(grammar.Terminals.Count + grammar.Grammaticals.Count);
            RelationMatrix.TransitiveClosure(F_Relation(grammar), f_plus);

            // Build the first_sets
            var first_sets = new Dictionary<GrammaticalSymbol, ISet<TerminalSymbol>>();
            foreach( var gr in grammar.Grammaticals )
            {
                int gr_index = grammar.GlobalIndexOf(gr);

                // Put all terminals being in relation with gr into gr's first_set
                var first_set = new HashSet<TerminalSymbol>();
                foreach( var tr in grammar.Terminals )
                    if( f_plus[gr_index, grammar.GlobalIndexOf(tr)] )
                        first_set.Add(tr);

                if( epsilon_grammaticals.Contains(gr) )
                    first_set.Add(EpsilonSymbol.Instance);

                first_sets.Add(gr, first_set);
            }

            return first_sets;
        }
开发者ID:mqrelly,项目名称:Syntan,代码行数:40,代码来源:FirstSets.cs

示例11: WordBreak2

        public bool WordBreak2(string s, ISet<string> wordDict)
        {
            if (s.Length == 0)
                return true;

            int len = s.Length;
            bool[] map = new bool[len + 1];

            map[0] = true;

            for(int start=0; start < len; start++)
            {
                map[start+1] = false;
                for (int slen = 0; slen <= start; slen++)
                {
                    var substr = s.Substring(slen, start - slen + 1);
                    if (map[slen] && wordDict.Contains(substr))
                    {
                        map[start+1] = true;
                        break;
                    }
                }
            }
            return map[len];
        }
开发者ID:aribeth97,项目名称:leetcode-CSharp,代码行数:25,代码来源:Solution139.cs

示例12: DFS

 public List<string> DFS(string s, ISet<string> wordDict, bool[] map)
 {
     List<string> re = new List<string>();
     if (s.Length == 0)
     {
         re.Add("");
         return re;
     }
     for(int start=s.Length-1; start>=0; start--)
     {
         var substr = s.Substring(start, s.Length-start);
         if (map[start] && wordDict.Contains(substr))
         {
             var subre = DFS(s.Substring(0, start), wordDict, map);
             foreach(var item in subre)
             {
                 if (string.IsNullOrEmpty(item))
                     re.Add(substr);
                 else
                     re.Add(item + " " + substr);
             }
         }
     }
     return re;
 }
开发者ID:aribeth97,项目名称:leetcode-CSharp,代码行数:25,代码来源:Solution140.cs

示例13: LadderLength

 public int LadderLength(string start, string end, ISet<string> dict)
 {
     var queue = new Queue<string>();
     queue.Enqueue(start);
     dict.Add(end);
     int step = 0;
     while (queue.Count != 0)
     {
         var level = new Queue<string>();
         step++;
         while (queue.Count != 0)
         {
             String q = queue.Dequeue();
             if (q.Equals(end))
                 return step;
             for (int i = 0; i < start.Length; i++)
             {
                 for (char c = 'a'; c <= 'z'; c++)
                 {
                     String s = q.Substring(0, i) + c + q.Substring(i + 1, start.Length - 1 - i);
                     if (dict.Contains(s))
                     {
                         level.Enqueue(s);
                         dict.Remove(s);
                     }
                 }
             }
         }
         queue = level;
     }
     return 0;
 }
开发者ID:YouenZeng,项目名称:LeetCode,代码行数:32,代码来源:WordLadderSolution.cs

示例14: FindRecursive

        private static void FindRecursive(TrieNode node, ISet<string> results, string letters, string prefix, int? maxResults)
        {
            if (maxResults != null && results.Count == maxResults)
            {
                return;
            }

            if (node == null)
            {
                if (!results.Contains(letters))
                {
                    results.Add(letters);
                    return;
                }
            }

            letters += node.Letter.ToString();

            if (prefix.Length > 0)
            {
                if (node.ContainsKey(prefix[0]))
                {
                    FindRecursive(node[prefix[0]], results, letters, prefix.Remove(0, 1), maxResults);
                }
            }
            else
            {
                foreach (char key in node.Keys)
                {
                    FindRecursive(node[key], results, letters, prefix, maxResults);
                }
            }
        }
开发者ID:nramin,项目名称:APS.NET-C--Azure-Trie-Object-for-autocomplete,代码行数:33,代码来源:Trie.cs

示例15: WordBreak

        public IList<string> WordBreak(string s, ISet<string> wordDict)
        {
            // 首先确认s可以break
            // 状态转移方程: d(i)= 存在j使得 d(j) && s.SubString(i, i -j) 在 wordDict中
            // dps[i] 表示 从s.SubString(0, i)是否是可以break的
            List<bool> dps = new List<bool>();
            for(int i = 0; i <= s.Length; i++)
            {
                dps.Add(false);
            }
            dps[0] = true;

            for(int i = 0; i < s.Length; ++i)
            {
                if(dps[i])
                {
                    for(int j = 1; i + j < s.Length + 1; ++j)
                    {
                        if(wordDict.Contains(s.Substring(i, j)))
                        {
                            dps[i + j] = true;
                        }
                    }
                }
            }

            List<string> solutions = new List<string>();

            if(dps[s.Length])
            {
                Break(solutions, 0, dps, s, wordDict, "");
            }
            return solutions;
        }
开发者ID:crysisfair,项目名称:AlgorithmLearning,代码行数:34,代码来源:WordBreakII.cs


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