/** * Method to fix the node link for an item after inserting a new node. * * @param item the item of the new node * @param newNode the new node thas has been inserted. */ private void fixNodeLinks(Integer item, CFINode newNode) { // get the latest node in the tree with this item CFINode lastNode = mapItemLastNode.get(item); if (lastNode != null) { // if not null, then we add the new node to the node link of the last node lastNode.nodeLink = newNode; } // Finally, we set the new node as the last node mapItemLastNode.put(item, newNode); CFINode headernode = mapItemNodes.get(item); if (headernode == null) { // there is not mapItemNodes.put(item, newNode); } }
@Override /** * Method for getting a string representation of the CP-tree (to be used for debugging purposes). * * @return a string */ public String toString() { return "M" + root.toString(""); }
/** * Add an itemset to the CFI-Tree * * @param itemset the itemset * @param itemsetLength the length of the itemset * @param support the support of the itemset */ public void addCFI(int[] itemset, int itemsetLength, int support) { CFINode currentNode = root; // For each item in the itemset for (int i = 0; i < itemsetLength; i++) { int item = itemset[i]; // look if there is a node already in the FP-Tree CFINode child = currentNode.getChildWithID(item); if (child == null) { // there is no node, we create a new one CFINode newNode = new CFINode(); newNode.itemID = item; newNode.parent = currentNode; // remember at which level in the tree that node appears newNode.level = i + 1; newNode.counter = support; // NEW BY PHILIPPE 2015 // we link the new node to its parrent currentNode.childs.add(newNode); // we take this node as the current node for the next for loop iteration currentNode = newNode; // We update the header table. // We check if there is already a node with this id in the header table fixNodeLinks(item, newNode); } else { // FPCLOSE: // If there is a node already, we update it // with the maximum of the support already in the path // and the support of the current itemset child.counter = Math.max(support, child.counter); currentNode = child; } } // SET THE SUPPORT OF THE CFI (the last item) // currentNode.counter = support; // remember that this is the last added itemset lastAddedItemsetNode = currentNode; }