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

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

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