Skip to content

Instantly share code, notes, and snippets.

@sslotsky
Last active October 13, 2015 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sslotsky/0d393049e722abd38a07 to your computer and use it in GitHub Desktop.
Save sslotsky/0d393049e722abd38a07 to your computer and use it in GitHub Desktop.
class Item {
public int Id;
public ArrayList<int> TransactionIds;
}
class Node {
public ArrayList<Item> Items;
public ArrayList<Node> Children = new ArrayList<Node>();
public Node(ArrayList<Item> items) {
this.Items = items;
}
}
class Tree {
public Node Root;
public Tree() {
this.Root = new Node();
}
public void Build(ArrayList<item> items) {
ArrayList<Node> nodes = new ArrayList<Node>();
foreach (Item item in items) {
ArrayList<Item> items = new ArrayList<item>();
items.Add(item);
nodes.Add(new Node(items));
}
this.Filter(this.Root, nodes);
}
public void Filter(Node node, ArrayList<Node> candidates) {
foreach (Node candidate in nodes) {
if(this.PassCondition(candidate)) {
node.Children.Add(candidate);
this.Filter(candidate, this.Permutations(candidates));
}
}
}
public bool PassesCondition(Node node) {
// check your supports here? do you need any other information other than the single node?
}
public List<Node> Permutations(Node node, ArrayList<Node> candidates) {
ArrayList<Node> nodes = new ArrayList<Node>();
for (int index = candidates.indexOf(node) + 1; index < candidates.Count(); index++) {
nodes.Add(new Node(node.Items.Union(candidates[index].Items));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment