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


C# HashSet.IntersectWith方法代码示例

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


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

示例1: Main

    static void Main()
    {
        InitializeWordsByChar();

        int textLinesCount = int.Parse(Console.ReadLine().ToLower());
        for (int i = 0; i < textLinesCount; i++)
        {
            GetWords(Console.ReadLine().ToLower());
        }

        int wordsCount = int.Parse(Console.ReadLine());
        for (int i = 0; i < wordsCount; i++)
        {
            string word = Console.ReadLine();
            string wordLowerCase = word.ToLower();
            HashSet<string> currentWords = new HashSet<string>();
            currentWords.UnionWith(wordsByChar[wordLowerCase[0]]);
            for (int j = 1; j < wordLowerCase.Length; j++)
            {
                currentWords.IntersectWith(wordsByChar[wordLowerCase[j]]);
            }

            Console.WriteLine("{0} -> {1}", word, currentWords.Count);
        }
    }
开发者ID:vladislav-karamfilov,项目名称:TelerikAcademy,代码行数:25,代码来源:Words.cs

示例2: searchRtrees

        static long searchRtrees(ArrayList words)
        {
            long word_c = 0;

            int ii = 0;
            foreach (String w in words)
            {
                DateTime tt0 = DateTime.Now;
                List<Rectangle> rects = getPoint(w, 1);
                HashSet<string> allwords = new HashSet<string>();
                foreach (string s in words) allwords.Add(s);
                int i = 0;
                foreach (Rectangle r in rects)
                {
                    List<string> objects = rts[i].Intersects(r);
                    i++;
                    HashSet<string> o = new HashSet<string>();
                    foreach (string s in objects) { o.Add(s); }
                    allwords.IntersectWith(o);
                }
                TimeSpan tts1 = DateTime.Now - tt0;
                Console.WriteLine(w + " :" + allwords.Count + " " + tts1);
                word_c += allwords.Count;
                ii++;
                if (ii > 10000) break;
            }
            return word_c;
        }
开发者ID:Khalefa,项目名称:Editdistance-c-,代码行数:28,代码来源:engine.cs

示例3: Window_Loaded

		private async void Window_Loaded(object sender, EventArgs e) {
			this.Loaded-=Window_Loaded;
			HashSet<uint> allIds=new HashSet<uint>();
			var selectedIds=new HashSet<uint>(Settings.Default.Channels.Select(c => c.Id));
			Color defaultColor=0x99A2A8.ToColor(); // Retos gadījumos skanošo sarakstā ir kanāls, kuru nerāda ar krāsainām saitēm.
			// Iegūst pamata datus: nosaukumu, īsu aprakstu un identifikatoru.
			foreach (Match match in channelRx.Matches(await client.DownloadStringTaskAsync("http://live.pieci.lv/"))) {
				string idString=match.Groups["id"].Value;
				uint id=idString.Length == 0 ? PieciStation.EmptyId:uint.Parse(idString);
				channels.Add(new ChannelItem(id, match.Groups["caption"].Value, defaultColor,
					match.Groups["description"].Value, match.Groups["name"].Value, selectedIds.Contains(id)));
				allIds.Add(id);
			}
			// Iegūst krāsas. Lielākai daļai kanālu tās ir zināmas (un tāpēc ir iekļautas ikonas), bet dažiem sezonāliem kanāliem nevar paredzēt, tāpēc izgūst no atskaņotāja lapas.
			foreach (Match match in colorRx.Matches(await client.DownloadStringTaskAsync("http://fm.pieci.lv"))) {
				uint id=uint.Parse(match.Groups["id"].Value);
				channels.Single(c => c.Id == id).SetColor(match.Groups["color"].Value);
			}
			list.ItemsSource=channels;

			// Izņem no saraksta zudušos kanālus.
			int beforeCount=selectedIds.Count;
			selectedIds.IntersectWith(allIds);
			HasChanges=beforeCount != selectedIds.Count;
		}
开发者ID:drdax,项目名称:Radio,代码行数:25,代码来源:ChannelsWindow.xaml.cs

示例4: DicesCoeffienct

        private double DicesCoeffienct(string in1, string in2)
        {
            HashSet<string> nx = new HashSet<string>();
            HashSet<string> ny = new HashSet<string>();

            for(int i = 0; i < in1.Length - 1; i++)
            {
                char x1 = in1[i];
                char x2 = in1[i + 1];
                string temp = x1.ToString() + x2.ToString();
                nx.Add(temp);
            }
            for(int j = 0; j < in2.Length - 1; j++)
            {
                char y1 = in2[j];
                char y2 = in2[j + 1];
                string temp = y1.ToString() + y2.ToString();
                ny.Add(temp);
            }

            HashSet<string> intersection = new HashSet<string>(nx);
            intersection.IntersectWith(ny);

            double dbOne = intersection.Count;
            return (2 * dbOne) / (nx.Count + ny.Count);
        }
开发者ID:rstokes,项目名称:fuzzysearch,代码行数:26,代码来源:FuzzySearchService.cs

示例5: FindModulesAsync

        /// <summary>
        /// Determines whether the interpreter factory contains the specified
        /// modules.
        /// </summary>
        /// <returns>The names of the modules that were found.</returns>
        public static async Task<HashSet<string>> FindModulesAsync(this IPythonInterpreterFactory factory, params string[] moduleNames) {
            var withDb = factory as PythonInterpreterFactoryWithDatabase;
            if (withDb != null && withDb.IsCurrent) {
                var db = withDb.GetCurrentDatabase();
                var set = new HashSet<string>(moduleNames.Where(m => db.GetModule(m) != null));
                return set;
            }

            var expected = new HashSet<string>(moduleNames);

            if (withDb != null) {
                var paths = PythonTypeDatabase.GetCachedDatabaseSearchPaths(withDb.DatabasePath) ??
                    await PythonTypeDatabase.GetUncachedDatabaseSearchPathsAsync(withDb.Configuration.InterpreterPath).ConfigureAwait(false);
                var db = PythonTypeDatabase.GetDatabaseExpectedModules(withDb.Configuration.Version, paths)
                    .SelectMany()
                    .Select(g => g.ModuleName);
                expected.IntersectWith(db);
                return expected;
            }

            return await Task.Run(() => {
                var result = new HashSet<string>();
                foreach (var mp in ModulePath.GetModulesInLib(factory)) {
                    if (expected.Count == 0) {
                        break;
                    }

                    if (expected.Remove(mp.ModuleName)) {
                        result.Add(mp.ModuleName);
                    }
                }
                return result;
            });
        }
开发者ID:smallwave,项目名称:PTVS,代码行数:39,代码来源:PythonInterpreterFactoryExtensions.cs

示例6: Intersection

        public static HashSet<char> Intersection(IEnumerable<char> a, IEnumerable<char> b)
        {
            var set = new HashSet<char>(a);
            set.IntersectWith(b);

            return set;
        }
开发者ID:drusepth,项目名称:SudokuSprint,代码行数:7,代码来源:Helper.cs

示例7: 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

示例8: IntersectWithNullTest

        public void IntersectWithNullTest()
        {
            HashSet<string> names = new HashSet<string>();
            names.Add("Pesho");
            names.Add("Gosho");

            names.IntersectWith(null);
        }
开发者ID:vladislav-karamfilov,项目名称:TelerikAcademy,代码行数:8,代码来源:IntersectWithOperationTests.cs

示例9: Main

        static void Main()
        {
            #if DEBUG
            Console.SetIn(new System.IO.StreamReader("../../input.txt"));
            #endif

            Dictionary<string, HashSet<string>> words = new Dictionary<string, HashSet<string>>();
            for (char i = 'a'; i <= 'z'; i++)
            {
                words[i.ToString()] = new HashSet<string>();
            }

            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                string input = Console.ReadLine().ToLower();
                input += " ";
                string word = string.Empty;

                for (int j = 0; j < input.Length; j++)
                {
                    if (input[j] >= 'a' && input[j] <= 'z')
                    {
                        word += input[j];
                    }
                    else if(word.Length > 0)
                    {
                        foreach (var w in word)
                        {
                            if (w == 'a')
                            {

                            }
                            words[w.ToString()].Add(word);

                            //words.AddSafeReturn(w, new HashSet<string>()).Add(word);
                        }
                        word = string.Empty;
                    }
                }
            }

            n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                string input = Console.ReadLine();
                string inputToLower = input.ToLower();
                HashSet<string> result = new HashSet<string>(words[inputToLower[0].ToString()]);

                for (int j = 1; j < inputToLower.Length; j++)
                {
                    result.IntersectWith(words[inputToLower[j].ToString()]);
                }

                Console.WriteLine("{0} -> {1}", input, result.Count);
            }
        }
开发者ID:nim-ohtar,项目名称:TelerikAkademy,代码行数:58,代码来源:Program.cs

示例10: GetDistance

 public double GetDistance(string a, string b)
 {
     HashSet<string> seta = new HashSet<string>(StringUtils.GetLuceneTokens(a));
     int na = seta.Count;
     HashSet<string> setb = StringUtils.GetLuceneTokens(b);
     int nb = setb.Count;
     seta.IntersectWith(setb);
     return 1.0d-((double) seta.Count*seta.Count/(na*nb));
 }
开发者ID:KommuSoft,项目名称:MLTag,代码行数:9,代码来源:CosineDistanceMetric.cs

示例11: Main

        static void Main()
        {
            HashSet<char> firstString = new HashSet<char>(
                Console.ReadLine().ToCharArray());
            HashSet<char> secondString = new HashSet<char>(
                Console.ReadLine().ToCharArray());

            firstString.IntersectWith(secondString);
            Console.WriteLine(firstString.Count > 1 ? "yes" : "no");
        }
开发者ID:evgeni-tsn,项目名称:Fundamentals-SoftwareUniversity,代码行数:10,代码来源:CommonStrings.cs

示例12: GetDistance

 public double GetDistance(string a, string b)
 {
     List<string> tokensa = new List<string>(StringUtils.GetLuceneTokens(a));
     List<string> tokensb = new List<string>(StringUtils.GetLuceneTokens(b));
     HashSet<string> inter = new HashSet<string>(tokensa);
     inter.IntersectWith(tokensb);
     HashSet<string> union = new HashSet<string>(tokensa);
     union.UnionWith(tokensb);
     return (double) (union.Count-inter.Count);///union.Count;
 }
开发者ID:KommuSoft,项目名称:MLTag,代码行数:10,代码来源:JacardDistanceMetric.cs

示例13: Process

 public override void Process(IEnumerable<string> expected, IEnumerable<string> result)
 {
     d++;
     HashSet<string> delta = new HashSet<string>(expected);
     delta.UnionWith(result);
     HashSet<string> section = new HashSet<string>(expected);
     section.IntersectWith(result);
     delta.ExceptWith(section);
     score += (double) delta.Count;
 }
开发者ID:KommuSoft,项目名称:MLTag,代码行数:10,代码来源:HammingLossMetric.cs

示例14: Process

 public override void Process(IEnumerable<string> expected, IEnumerable<string> result)
 {
     HashSet<string> section = new HashSet<string>(result);
     int z = section.Count;
     if(z != 0) {
         d++;
         section.IntersectWith(expected);
         score += (double) section.Count/z;
     }
 }
开发者ID:KommuSoft,项目名称:MLTag,代码行数:10,代码来源:PrecisionMetric.cs

示例15: IntersectSets

 private static HashSet<int> IntersectSets(HashSet<int> set1, HashSet<int> set2)
 {
     HashSet<int> intersection = new HashSet<int>();
     foreach (int element in set1)
     {
         intersection.Add(element);
     }
     intersection.IntersectWith(set2);
     return intersection;
 }
开发者ID:AndreyKost,项目名称:C-Homework,代码行数:10,代码来源:Program.cs


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