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

trie/trie_manipulators/sequence/FrequentPairInserterNoprune.hpp

Go to the documentation of this file.
00001 #ifndef FrequentPairInserterNoprune_HPP
00002 #define FrequentPairInserterNoprune_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 namespace Bodon
00012 {
00013 namespace sequence
00014 {
00015 template <class DF_D, class TRIE, class LEAF, class LEAF_ALLOCATOR>
00016 class FrequentPairInserterNoprune : public 
00017 inhomogeneous_trie::ManipulatorBase<DF_D, TRIE, LEAF_ALLOCATOR>
00018 {
00019    private:
00020       typedef inhomogeneous_trie::ManipulatorBase<DF_D, TRIE, LEAF_ALLOCATOR> PARENT;
00021    protected:
00022       std::vector<Edge> extenders;
00023 
00024    public:
00025       FrequentPairInserterNoprune( TRIE& trie, DF_D& df_decoder,
00026                                    LEAF_ALLOCATOR& s_alloc) : 
00027          inhomogeneous_trie::ManipulatorBase<DF_D, TRIE, LEAF_ALLOCATOR>(
00028             trie, df_decoder, s_alloc){}
00029 
00030 
00032       void insertFrequentPairs(
00033          const std::vector< std::pair< counter_t, 
00034          std::pair<item_t, item_t> > >& freq_pairs_with_counters );
00035 
00036 };
00037 
00038    
00039 template <class DF_D, class TRIE, class LEAF, class LEAF_ALLOCATOR> void 
00040 FrequentPairInserterNoprune<DF_D, TRIE, LEAF, LEAF_ALLOCATOR>::insertFrequentPairs(
00041    const std::vector< std::pair< counter_t, std::pair<item_t, item_t> > >& 
00042    freq_pairs_with_counters )
00043 {
00044    if( freq_pairs_with_counters.empty() )
00045       PARENT::main_trie.edgelist.clear();
00046    else
00047    {
00048       std::vector< std::pair< counter_t, std::pair<item_t, item_t> > >::
00049          const_iterator it = freq_pairs_with_counters.begin();
00050       typename TRIE::iterator mt_iter = PARENT::main_trie.edgelist.begin(); 
00051       while( mt_iter != PARENT::main_trie.edgelist.end())
00052       {
00053          while (it != freq_pairs_with_counters.end() && 
00054                 (*it).second.first < (*mt_iter).first)
00055             ++it;
00056          extenders.clear();
00057          while( it != freq_pairs_with_counters.end() &&  
00058                 (*it).second.first == (*mt_iter).first)
00059          {
00060             extenders.push_back(Edge((*it).second.second, PARENT::s_alloc.allocate()));
00061             static_cast<LEAF*>(extenders.back().second)->setCounter((*it).first);
00062             ++it;
00063          }
00064          if(extenders.size() > 0)
00065          {
00066             static_cast<TRIE*>((*mt_iter).second)->edgelist.insert(extenders);
00067             ++mt_iter;
00068          }
00069          else
00070          {
00071             delete static_cast<TRIE*>((*mt_iter).second);
00072             mt_iter = PARENT::main_trie.edgelist.erase(mt_iter);
00073          }
00074       }
00075       while( mt_iter != PARENT::main_trie.edgelist.end() )
00076       {
00077          delete static_cast<TRIE*>((*mt_iter).second);
00078          mt_iter = PARENT::main_trie.edgelist.erase(mt_iter);
00079       }
00080    }
00081 }
00082 
00083 }
00084 }
00085 
00086 #endif

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