-1

I am using Contains method on SortedSet<SortedSet<int>> to check for existence of SortedSet<int>(call it, Itemset). Sample code is as follows:

Itemset j = new Itemset() { 1, 2 };
Itemset i = new Itemset() { 1, 3 };
SortedSet<Itemset> ItemsetCollection = new SortedSet<Itemset>();
ItemsetCollection.Add(i);
ItemsetCollection.Add(j);

If I have an itemset exactly similar to say, i and check for its membership in ItemsetCollection using Contains as shown below the check returns a false as it expects the name to be same as i

Itemset iset = new Itemset(){1,2};
bool b = ItemsetCollection.Contains(iset);

How else can the membership be checked if I am generating itemsets randomly and need to check for its presence in ItemSetCollection?

Aleks Andreev
  • 7,016
  • 8
  • 29
  • 37
ABB
  • 43
  • 1
  • 6
  • A `SortedSet>` makes no sense unless you provide the outer `SortedSet` a custom `IComparer>`. Otherwise how exactly do you think it's sorting the inner sets and do you even really need to sort a collection of sets in the first place? Finally renaming a class type in your code is profoundly confusing. – juharr Mar 31 '18 at 12:16

1 Answers1

2

Try

ItemsetCollection.Any(it => it.Count == iset.Count
                            && it.All(ti => iset.Any(tti => ti == tti)));
tchelidze
  • 8,050
  • 1
  • 29
  • 49