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

inhomogeneous_trie/trie_manipulators/sequence/SimplePruner.hpp

Go to the documentation of this file.
00001 #ifndef SimplePruner_HPP
00002 #define SimplePruner_HPP
00003 
00004 #include "common.hpp"
00005 #include "common/Edge.hpp"
00006 #include "apriori/bodon/inhomogeneous_trie/trie_manipulators/ManipulatorBase.hpp"
00007 #include <vector>
00008 //#include <cstdio>
00009 //#include <iterator>   //for test
00010 
00011 
00012 
00013 
00014 namespace Bodon
00015 {
00016 namespace sequence
00017 {
00018 namespace inhomogeneous_trie
00019 {
00020    template <class DF_D, class TRIE, class LEAF, class LEAF_ALLOCATOR>
00021    class SimplePruner : public 
00022    Bodon::inhomogeneous_trie::ManipulatorBase<DF_D, TRIE, LEAF_ALLOCATOR>
00023    {
00024       private:
00025          typedef Bodon::inhomogeneous_trie::ManipulatorBase<DF_D, TRIE, LEAF_ALLOCATOR> PARENT;
00026       protected:
00027          std::vector<Edge> extenders;
00028          std::vector<Edge> replace_list;
00029 
00030       public:
00031          SimplePruner( TRIE& main_trie, DF_D& df_decoder,
00032                        LEAF_ALLOCATOR& s_alloc ) :
00033             Bodon::inhomogeneous_trie::ManipulatorBase<DF_D, TRIE, LEAF_ALLOCATOR>(
00034                main_trie, df_decoder, s_alloc){}
00035 
00036 
00037       protected:
00039          int isAllSubsetFrequent( std::vector<item_t>& maybe_candidate, 
00040                                   const item_t new_item ) const;
00041 
00042 
00043          void generateCandidateAtParent( 
00044             TRIE* trie, std::vector<item_t>& maybe_candidate );
00045    };
00046 
00047 
00048    template <class DF_D, class TRIE, class LEAF, class LEAF_ALLOCATOR> inline int 
00049    SimplePruner<DF_D, TRIE, LEAF, LEAF_ALLOCATOR>::isAllSubsetFrequent( 
00050       std::vector<item_t>& generator, const item_t new_item ) const
00051    {
00052       assert(generator.size() > 1);
00053       std::vector<item_t>::iterator item_it = generator.end()-2;
00054       register item_t deleted_item = *item_it, temp_item;
00055       const TRIE* temp_trie;
00056 
00057       generator.erase( item_it );
00058       temp_trie = PARENT::main_trie.isIncluded( generator, generator.begin() );
00059       if( temp_trie)
00060       { 
00061          if( !temp_trie->edgelist.find(new_item) )
00062          {
00063             generator.insert( item_it, deleted_item );
00064             return 0;
00065          }
00066       }
00067       else
00068       {
00069          generator.insert( item_it, deleted_item );
00070          return 0;
00071       }
00072       while(item_it != generator.begin())
00073       {
00074          --item_it;
00075          temp_item = *item_it;
00076          *item_it = deleted_item;
00077          deleted_item = temp_item;
00078          temp_trie = PARENT::main_trie.isIncluded( generator, generator.begin() );      
00079          if( temp_trie)
00080          { 
00081             if( !temp_trie->edgelist.find(new_item) )
00082             {
00083                generator.insert( item_it, deleted_item );
00084                return 0;
00085             }
00086          }
00087          else
00088          {
00089             generator.insert( item_it, deleted_item );
00090             return 0;
00091          }
00092       }
00093       generator.insert( item_it, deleted_item );
00094       return 1;
00095    }
00096 
00097 
00098    template <class DF_D, class TRIE, class LEAF, class LEAF_ALLOCATOR> inline void 
00099    SimplePruner<DF_D, TRIE, LEAF, LEAF_ALLOCATOR>::
00100    generateCandidateAtParent(TRIE* trie, std::vector<item_t>& maybe_candidate)
00101    {
00102       typename TRIE::iterator itEdge2;
00103       LEAF* toExtendAsLeaf;
00104       TRIE* toExtend;
00105       replace_list.clear();
00106       for( typename TRIE::iterator itEdge( trie->edgelist.begin() ); 
00107            itEdge != trie->edgelist.end(); ++itEdge )
00108       {
00109          toExtendAsLeaf = static_cast<LEAF*>((*itEdge).second);
00110          PARENT::df_decoder.pushItemWithWrite( (*itEdge).first, toExtendAsLeaf->getCounter() );
00111          PARENT::df_decoder.popItem();
00112          maybe_candidate.push_back((*itEdge).first);
00113          extenders.clear();
00114          for( itEdge2 = trie->edgelist.begin(); 
00115               itEdge2 != trie->edgelist.end(); ++itEdge2 )
00116          {
00117             if( isAllSubsetFrequent( maybe_candidate, (*itEdge2).first ) == 1 )
00118             {
00119                extenders.push_back(Edge((*itEdge2).first, PARENT::s_alloc.allocate()));
00120                static_cast<LEAF*>(extenders.back().second)->setCounter(0);
00121             }
00122          }
00123          maybe_candidate.pop_back();
00124          if(extenders.empty())
00125          {
00126             toExtendAsLeaf->setCounter(0);
00127             replace_list.push_back(Edge((*itEdge).first, toExtendAsLeaf));
00128          }
00129          else
00130          {
00131             toExtend = new TRIE(toExtendAsLeaf->getCounter());
00132             PARENT::s_alloc.free(toExtendAsLeaf);
00133             replace_list.push_back(Edge((*itEdge).first, toExtend));
00134             toExtend->edgelist.insert(extenders);
00135          }
00136       }
00137       trie->edgelist.clear();
00138       trie->edgelist.insert(replace_list);
00139    }
00140 }
00141 }
00142 }
00143 #endif

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