本文整理汇总了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);
}
}
示例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;
}
示例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;
}
示例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);
}
示例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;
});
}
示例6: Intersection
public static HashSet<char> Intersection(IEnumerable<char> a, IEnumerable<char> b)
{
var set = new HashSet<char>(a);
set.IntersectWith(b);
return set;
}
示例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
}
}
示例8: IntersectWithNullTest
public void IntersectWithNullTest()
{
HashSet<string> names = new HashSet<string>();
names.Add("Pesho");
names.Add("Gosho");
names.IntersectWith(null);
}
示例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);
}
}
示例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));
}
示例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");
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}