Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

SupportCounterMergeTries.hpp

Go to the documentation of this file.
00001 #ifndef SupportCounterMergeTries_HPP
00002 #define SupportCounterMergeTries_HPP
00003 
00004 #include "common.hpp"
00005 #include <vector>
00006 #include "apriori/bodon/Leaf.hpp"
00007 //#include <cstdio>
00008 //#include <iterator>   //for test
00009 
00010 
00011 
00012 namespace Bodon
00013 {
00014 namespace dynamic_trie
00015 {
00016    template <class TRIE_OEL, class TRIE_OI, 
00017              class PATRICIA>
00018    class SupportCounterMergeTries
00019    {
00020       protected:
00021          TRIE_OEL& cand_trie;
00022          PATRICIA& patricia;
00023          typedef Bodon::Leaf LEAF;
00024 
00025       public:
00026          SupportCounterMergeTries( TRIE_OEL& cand_trie,
00027                                    PATRICIA& patricia ) :
00028             cand_trie(cand_trie), 
00029             patricia(patricia){}
00030          
00031          void countSupport(const unsigned int candidate_size )
00032          {
00033 //          kiir(patricia.getRoot());
00034             mergeTries(&this->cand_trie, patricia.getRoot(), 
00035                        candidate_size-1, this->cand_trie.edgelist.begin());
00036          }
00037          void kiir(typename PATRICIA::nodeptr_t subpatricia)
00038          {
00039             std::cout<<"Counter: "<<subpatricia->getCounter()<<std::endl;
00040             std::cout<<"Labels: "<<std::endl;
00041             for( typename PATRICIA::nodeiter_t patr_iter = subpatricia.childrenBegin();
00042                  patr_iter != subpatricia.childrenEnd(); ++patr_iter)
00043             {
00044                std::cout<<"label: "<<(*patr_iter).first<<std::endl;
00045             }
00046             for( typename PATRICIA::nodeiter_t patr_iter = subpatricia.childrenBegin();
00047                  patr_iter != subpatricia.childrenEnd(); ++patr_iter)
00048             {
00049                kiir((*patr_iter).second);
00050             }
00051          }
00052          
00053       private:
00054          template <class TRIE> void mergeTries(
00055             TRIE* subtrie, typename PATRICIA::nodeptr_t subpatricia, 
00056             unsigned int step_to_leaf_par,
00057             typename TRIE::iterator first_larger_edge);
00058 
00059          template <class TRIE> bool mergeTriesRemoveInfreqP(
00060             TRIE* subtrie, typename PATRICIA::nodeptr_t subpatricia, 
00061             unsigned int step_to_leaf_par,
00062             typename TRIE::iterator first_larger_edge);
00063 
00064    };
00065 
00066    template <class TRIE_OEL, class TRIE_OI, 
00067              class PATRICIA> 
00068    template <class TRIE> inline void
00069    SupportCounterMergeTries<TRIE_OEL, TRIE_OI, 
00070                             PATRICIA>::
00071    mergeTries( TRIE* subtrie, typename PATRICIA::nodeptr_t subpatricia, 
00072                unsigned int step_to_leaf_par, 
00073                typename TRIE::iterator first_larger_edge)
00074    {      
00075       for( typename PATRICIA::nodeiter_t patr_iter = subpatricia.childrenBegin();
00076            patr_iter != subpatricia.childrenEnd(); ++patr_iter)
00077       {
00078          while( first_larger_edge != subtrie->edgelist.end() &&
00079                 (*first_larger_edge).first < (*patr_iter).first  )
00080             ++first_larger_edge;
00081          if( first_larger_edge != subtrie->edgelist.end() &&
00082              (*first_larger_edge).first >= (*patr_iter).first  )
00083          {
00084             mergeTries( subtrie, (*patr_iter).second, 
00085                         step_to_leaf_par, first_larger_edge );
00086             if( (*patr_iter).first == (*first_larger_edge).first )
00087             {
00088                if(step_to_leaf_par > 0)
00089                {
00090                   if(static_cast<LEAF*>((*first_larger_edge).second)->getCounter() & TWO_POW31)
00091                      mergeTries( 
00092                         static_cast<TRIE_OEL*>((*first_larger_edge).second), 
00093                         (*patr_iter).second, step_to_leaf_par - 1,
00094                         static_cast<TRIE_OEL*>((*first_larger_edge).second)->edgelist.begin());
00095                   else
00096                      mergeTries( 
00097                         static_cast<TRIE_OI*>((*first_larger_edge).second), 
00098                         (*patr_iter).second, step_to_leaf_par - 1,
00099                         static_cast<TRIE_OI*>((*first_larger_edge).second)->edgelist.begin());
00100                }
00101                else
00102                {
00103                   static_cast<LEAF*>((*first_larger_edge).second)
00104                      ->increaseCounter((*patr_iter).second->getCounter());
00105                }
00106                ++first_larger_edge;
00107             }
00108          }
00109          else break;
00110       }
00111    }
00112 }
00113 }
00114 #endif

Generated on Sun Sep 17 17:50:40 2006 for FIM environment by  doxygen 1.4.4