Esempio n. 1
0
        public FPTreeNode insertChild(int column, int count)
        {
            if (FirstChild == null)
            {
                FirstChild = new FPTreeNode(column, count, this);
                return(FirstChild);
            }
            else
            {
                FPTreeNode child = FirstChild;
                while ((column != child.Column) && child.Brother != null)
                {
                    child = child.Brother;
                }

                if (child.Column == column)
                {
                    child.Count += count;
                }
                else
                {
                    child.Brother = new FPTreeNode(column, count, this);
                    child         = child.Brother;
                }
                return(child);
            }
        }
Esempio n. 2
0
        private FPTreeNode insert(FPTreeNode parent, int column, int count)
        {
            FPTreeNode child = parent.insertChild(column, count);

            add2Header(child);
            return(child);
        }
Esempio n. 3
0
        public FPTreeNode insertChild(int column, int count)
        {
            if (FirstChild == null)
            {
                FirstChild = new FPTreeNode(column, count, this);
                return FirstChild;
            }
            else
            {
                FPTreeNode child = FirstChild;
                while ((column != child.Column) && child.Brother != null)
                {
                    child = child.Brother;
                }

                if (child.Column == column)
                {
                    child.Count += count;
                }
                else
                {
                    child.Brother = new FPTreeNode(column, count, this);
                    child = child.Brother;
                }
                return child;
            }
        }
Esempio n. 4
0
        private FPTree getPatternsAndTree(FPTree tree, int column)
        {
            FPTree result = new FPTree();

            if (tree.header.ContainsKey(column))
            {
                result.root.Count = 0;
                FPTreeNode colNode = tree.header[column];
                while (colNode != null)
                {
                    // get a path
                    int count = colNode.Count;
                    result.root.Count += count;
                    ArrayList  reversePath = new ArrayList();
                    FPTreeNode current     = colNode.Parent;
                    while (current.Column != -1)
                    {
                        reversePath.Add(current.Column);
                        current = current.Parent;
                    }

                    int[] path = new int[reversePath.Count];
                    for (int i = 0; i < path.Length; ++i)
                    {
                        path[i] = (int)reversePath[path.Length - 1 - i];
                    }
                    result.insert(path, count);
                    colNode = colNode.ColumnBrother;
                }
            }
            return(result);
        }
Esempio n. 5
0
        public void insert(int[] record, int count)
        {
            FPTreeNode current = root;

            for (int i = 0; i < record.Length; ++i)
            {
                current = insert(current, record[i], count);
            }
        }
Esempio n. 6
0
 private void add2Header(FPTreeNode node)
 {
     if (header.ContainsKey(node.Column))
     {
         FPTreeNode current = header[node.Column];
         while (current.ColumnBrother != null && current != node)
         {
             current = current.ColumnBrother;
         }
         if(current != node){
             current.ColumnBrother = node;
         }
     }
     else
     {
         header.Add(node.Column, node);
     }
 }
Esempio n. 7
0
 private void add2Header(FPTreeNode node)
 {
     if (header.ContainsKey(node.Column))
     {
         FPTreeNode current = header[node.Column];
         while (current.ColumnBrother != null && current != node)
         {
             current = current.ColumnBrother;
         }
         if (current != node)
         {
             current.ColumnBrother = node;
         }
     }
     else
     {
         header.Add(node.Column, node);
     }
 }
Esempio n. 8
0
        private ArrayList nodeToList(FPTreeNode node)
        {
            ArrayList result = new ArrayList();

            String[] array = new String[4] {
                node.GetHashCode() + "",
                     node.Column >= 0 ? colNames[node.Column] : "Root",
                (node.Parent == null)? "": node.Parent.GetHashCode() + "",
                "Count: " + node.Count
            };

            result.Add(array);

            FPTreeNode child = node.FirstChild;

            while (child != null)
            {
                result.AddRange(nodeToList(child));
                child = child.Brother;
            }

            return(result);
        }
Esempio n. 9
0
 public FPTree()
 {
     root   = new FPTreeNode(-1, -1, null);
     header = new Dictionary <int, FPTreeNode>();
 }
Esempio n. 10
0
 public FPTreeNode(int column, int count, FPTreeNode parent)
 {
     this.Column = column;
     this.Count  = count;
     this.Parent = parent;
 }
Esempio n. 11
0
 public FPTreeNode(int column, int count, FPTreeNode parent)
 {
     this.Column = column;
     this.Count = count;
     this.Parent = parent;
 }
Esempio n. 12
0
        private ArrayList nodeToList(FPTreeNode node)
        {
            ArrayList result = new ArrayList();
            String[] array = new String[4]{
                node.GetHashCode() + "",
                node.Column >= 0 ? colNames[node.Column] : "Root",
                (node.Parent == null)? "": node.Parent.GetHashCode()+"",
                "Count: " + node.Count
            };

            result.Add(array);

            FPTreeNode child = node.FirstChild;
            while (child != null)
            {
                result.AddRange(nodeToList(child));
                child = child.Brother;
            }

            return result;
        }
Esempio n. 13
0
 private FPTreeNode insert(FPTreeNode parent, int column, int count)
 {
     FPTreeNode child = parent.insertChild(column, count);
     add2Header(child);
     return child;
 }
Esempio n. 14
0
 public FPTree()
 {
     root = new FPTreeNode(-1, -1, null);
     header = new Dictionary<int, FPTreeNode>();
 }