Ejemplo n.º 1
0
        //public Pattern DeleteItems(Pattern ptn, HeadTable ht)
        //{
        //    if (ht.HeadNodes.Count == 0) return new Pattern(new List<int>(), Int32.MaxValue);

        //    List<int> hash = Enumerable.Repeat(0, ht.HeadNodes.Max(x => x.Ptn.Items.Max()) + 1).ToList();

        //    for (int i = 0; i < ht.HeadNodes.Count; i++)
        //    {
        //        hash[ht.HeadNodes[i].Ptn[0]] = 1;
        //    }

        //    List<int> li = new List<int>();

        //    for (int i = 0; i < ptn.Items.Count; i++)
        //    {
        //        if (ptn.Items[i] < hash.Count && hash[ptn.Items[i]] == 1) li.Add(ptn.Items[i]);
        //    }

        //    return new Pattern(li, ptn.PtnCnt);
        // }

        public Pattern DeleteItems(Pattern ptn, HeadTable ht)
        {
            if (ht.HeadNodes.Count == 0)
            {
                return(new Pattern(new List <int>(), Int32.MaxValue));
            }

            List <int> HeadTableItems = new List <int>();

            for (int i = 0; i < ht.HeadNodes.Count; i++)
            {
                HeadTableItems.Add(ht.HeadNodes[i].Ptn[0]);
            }

            List <int> li = new List <int>();

            for (int i = 0; i < ptn.Items.Count; i++)
            {
                if (HeadTableItems.Contains(ptn.Items[i]))
                {
                    li.Add(ptn.Items[i]);
                }
            }

            return(new Pattern(li, ptn.PtnCnt));
        }
Ejemplo n.º 2
0
 public void SortItems(HeadTable ht)//sort pattern by item id support count
 {
     for (int i = 0; i < Items.Count - 1; i++)
     {
         for (int j = 0; j < Items.Count - 1 - i; j++)
         {
             if (ht.Count[Items[j]] < ht.Count[Items[j + 1]])
             {
                 int temp = Items[j];
                 Items[j]     = Items[j + 1];
                 Items[j + 1] = temp;
             }
         }
     }
 }
Ejemplo n.º 3
0
        public void Insert(Node node, Pattern ptn, HeadTable headtable)
        {
            ptn = DeleteItems(ptn, headtable);

            if (ptn.Items.Count == 0)
            {
                return;
            }

            //sort pattern's items
            ptn.SortItems(headtable);

            //insert into tree
            for (int i = 0; i < node.Children.Count; i++)
            {
                if (node.Children[i].Ptn[0] == ptn[0])
                {
                    node.Children[i].Ptn.PtnCnt += ptn.PtnCnt;

                    Insert(node.Children[i], new Pattern(ptn.Items.GetRange(1, ptn.Items.Count - 1), ptn.PtnCnt), headtable);

                    return;
                }
            }

            Node newnode = new Node(new Pattern(new List <int>()
            {
                ptn[0]
            }, ptn.PtnCnt), node);

            node.Children.Add(newnode);

            //update headtable new node link
            newnode.Next = headtable.HeadNodes[headtable.Index[ptn[0]]].FirstNode;
            headtable.HeadNodes[headtable.Index[ptn[0]]].FirstNode = newnode;

            //recursive
            Insert(newnode, new Pattern(ptn.Items.GetRange(1, ptn.Items.Count - 1).ToList(), ptn.PtnCnt), headtable);
        }
Ejemplo n.º 4
0
 public FPTree()
 {
     ConditionalPatternBase = new List <Pattern>();
     HeadTable = new HeadTable();
     Root      = new Node();
 }