本文整理汇总了C#中SortedSet.IntersectWith方法的典型用法代码示例。如果您正苦于以下问题:C# SortedSet.IntersectWith方法的具体用法?C# SortedSet.IntersectWith怎么用?C# SortedSet.IntersectWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedSet
的用法示例。
在下文中一共展示了SortedSet.IntersectWith方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: JoinArrays
static SortedSet<char> JoinArrays(string[] tokens)
{
char[] leftArray = tokens[0].ToCharArray();
char[] rightArray = tokens[1].ToCharArray();
SortedSet<char> leftSet =
new SortedSet<char>(leftArray);
SortedSet<char> rightSet =
new SortedSet<char>(rightArray);
SortedSet<char> result =
new SortedSet<char>();
result.UnionWith(leftSet);
result.IntersectWith(leftSet);
result.IntersectWith(rightSet);
return result;
}
示例2: TestIntersectWithSortedSet
public static void TestIntersectWithSortedSet()
{
var sortedSet = new SortedSet<int>();
int[] itemsToAdd = new int[] { 5, 13, 8, 11, 5, 1, 12, 9, 14, 4, };
foreach (var item in itemsToAdd)
sortedSet.Add(item);
SortedSet<int> meow = new SortedSet<int>();
int[] itemsToAdd2 = new int[] { 5, 3, 7, 12, 8 };
foreach (var item in itemsToAdd2)
meow.Add(item);
int[] expectedIntersect = new int[] { 5, 12, 8 };
sortedSet.IntersectWith(meow);
Assert.True(sortedSet.SetEquals(expectedIntersect)); //"Expected to be the same set."
}
示例3: GetTagScore
private static double GetTagScore(string tags1, string tags2)
{
// Jaccard distance: http://en.wikipedia.org/wiki/Jaccard_index
if (string.IsNullOrWhiteSpace(tags1) || string.IsNullOrWhiteSpace(tags2)) return 0.0;
var tagSet1 = new SortedSet<string>(tags1.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries));
var tagSet2 = new SortedSet<string>(tags2.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries));
var intersection = new SortedSet<string>(tagSet1);
intersection.IntersectWith(tagSet2);
var union = new SortedSet<string>(tagSet1);
union.UnionWith(tagSet2);
return (double) intersection.Count/union.Count;
}