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

trie/trie_manipulators/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 template <class DF_D, class TRIE, class LEAF, class LEAF_ALLOCATOR, bool NEE>
00014 class FrequentPairInserterNoprune : public 
00015 inhomogeneous_trie::ManipulatorBase<DF_D, TRIE, LEAF_ALLOCATOR>
00016 {
00017    private:
00018       typedef inhomogeneous_trie::ManipulatorBase<DF_D, TRIE, LEAF_ALLOCATOR> PARENT;
00019    protected:
00020       std::vector<Edge> extenders;
00021 
00022    public:
00023       FrequentPairInserterNoprune( TRIE& trie, DF_D& df_decoder,
00024                                    LEAF_ALLOCATOR& s_alloc) : 
00025          PARENT(trie, df_decoder, s_alloc){}
00026 
00027 
00029       void insertFrequentPairs(
00030          const std::vector< std::pair< counter_t, 
00031          std::pair<item_t, item_t> > >& freq_pairs_with_counters )
00032       {
00033          if(NEE > NEE_Off)
00034             insertFrequentPairsNEE(freq_pairs_with_counters);
00035          else
00036             insertFrequentPairsNONEE(freq_pairs_with_counters);
00037       }
00038 
00039    protected:
00040       void insertFrequentPairsNONEE(
00041          const std::vector< std::pair< counter_t, 
00042          std::pair<item_t, item_t> > >& freq_pairs_with_counters );
00043       void insertFrequentPairsNEE(
00044          const std::vector< std::pair< counter_t, 
00045          std::pair<item_t, item_t> > >& freq_pairs_with_counters );
00046 };
00047 
00048    
00049 template <class DF_D, class TRIE, class LEAF, class LEAF_ALLOCATOR, bool NEE> void 
00050 FrequentPairInserterNoprune<DF_D, TRIE, LEAF, LEAF_ALLOCATOR, NEE>::insertFrequentPairsNONEE(
00051    const std::vector< std::pair< counter_t, std::pair<item_t, item_t> > >& 
00052    freq_pairs_with_counters )
00053 {
00054    if( freq_pairs_with_counters.empty() )
00055       PARENT::main_trie.edgelist.clear();
00056    else
00057    {
00058       std::vector< std::pair< counter_t, std::pair<item_t, item_t> > >::
00059          const_iterator it = freq_pairs_with_counters.begin();
00060       typename TRIE::iterator mt_iter = PARENT::main_trie.edgelist.begin(); 
00061       while( mt_iter != PARENT::main_trie.edgelist.end())
00062       {
00063          while (it != freq_pairs_with_counters.end() && 
00064                 (*it).second.first < (*mt_iter).first)
00065             ++it;
00066          extenders.clear();
00067          while( it != freq_pairs_with_counters.end() &&  
00068                 (*it).second.first == (*mt_iter).first)
00069          {
00070             extenders.push_back(Edge((*it).second.second, PARENT::s_alloc.allocate()));
00071             static_cast<LEAF*>(extenders.back().second)->setCounter((*it).first);
00072             ++it;
00073          }
00074          if(extenders.size() > 1)
00075          {
00076             static_cast<TRIE*>((*mt_iter).second)->edgelist.insert(extenders);
00077             ++mt_iter;
00078          }
00079          else
00080          {
00081             if(extenders.size() == 1)
00082             {
00083                PARENT::df_decoder.pushItem((*mt_iter).first);
00084                PARENT::df_decoder.pushItemWithWrite(
00085                   extenders.front().first, static_cast<LEAF*>(extenders.front().second)->getCounter());
00086                PARENT::s_alloc.free(static_cast<LEAF*>(extenders.front().second));
00087                PARENT::df_decoder.popItem();
00088                PARENT::df_decoder.popItem();
00089             }
00090             delete static_cast<TRIE*>((*mt_iter).second);
00091             mt_iter = PARENT::main_trie.edgelist.erase(mt_iter);
00092          }
00093       }
00094       while( mt_iter != PARENT::main_trie.edgelist.end() )
00095       {
00096          delete static_cast<TRIE*>((*mt_iter).second);
00097          mt_iter = PARENT::main_trie.edgelist.erase(mt_iter);
00098       }
00099    }
00100 }
00101 
00102 template <class DF_D, class TRIE, class LEAF, class LEAF_ALLOCATOR, bool NEE> void 
00103 FrequentPairInserterNoprune<DF_D, TRIE, LEAF, LEAF_ALLOCATOR, NEE>::insertFrequentPairsNEE(
00104    const std::vector< std::pair< counter_t, std::pair<item_t, item_t> > >& 
00105    freq_pairs_with_counters )
00106 {
00107    PARENT::df_decoder.pushEquisupportItemSet(PARENT::main_trie.neelist);
00108    PARENT::df_decoder.write( PARENT::main_trie.getCounter() );
00109    if( freq_pairs_with_counters.empty() )
00110       PARENT::main_trie.edgelist.clear();
00111    else
00112    {
00113       unsigned int nr_of_prefix_equiitem=0;
00114       std::vector< std::pair< counter_t, std::pair<item_t, item_t> > >::
00115          const_iterator it = freq_pairs_with_counters.begin();
00116       vector<item_t> neelist;
00117       for( typename TRIE::iterator mt_iter = PARENT::main_trie.edgelist.begin(); 
00118            mt_iter != PARENT::main_trie.edgelist.end(); ++mt_iter )
00119       {
00120          while (it != freq_pairs_with_counters.end() && 
00121                 (*it).second.first < (*mt_iter).first)
00122             ++it;
00123          extenders.clear();
00124          neelist.clear();
00125          while( it != freq_pairs_with_counters.end() && 
00126                 (*it).second.first == (*mt_iter).first )
00127             if( !PARENT::main_trie.neeFind((*it).second.second) )
00128          {
00129             if( (*it).first == 
00130                 static_cast<LEAF*>((*mt_iter).second)->getCounter() )
00131             {
00132                neelist.push_back((*it).second.second);
00133 #if DEBUG_LEVEL >= LEVEL_PERF
00134                ++nr_of_prefix_equiitem;
00135 #endif
00136             }
00137             else
00138             {
00139                extenders.push_back(Edge((*it).second.second, 
00140                                         PARENT::s_alloc.allocate()));
00141                static_cast<LEAF*>(extenders.back().second)->setCounter((*it).first);
00142             }
00143             ++it;
00144          }
00145          if(extenders.size() > 1)
00146          {
00147             static_cast<TRIE*>((*mt_iter).second)->edgelist.insert(extenders);
00148             static_cast<TRIE*>((*mt_iter).second)->neePushBackSorted(neelist);
00149             ++mt_iter;
00150          }
00151          else
00152          {
00153             PARENT::df_decoder.pushItem((*mt_iter).first);
00154             PARENT::df_decoder.pushEquisupportItemSet(neelist);
00155             if(extenders.size() == 1)
00156             {
00157                PARENT::df_decoder.pushItem( extenders.front().first );
00158                PARENT::df_decoder.write(
00159                   static_cast<LEAF*>(extenders.front().second)->getCounter());
00160                PARENT::s_alloc.free(static_cast<LEAF*>(extenders.front().second));
00161                PARENT::df_decoder.popItem();
00162             }
00163             PARENT::df_decoder.write( 
00164                static_cast<LEAF*>((*mt_iter).second)->getCounter() );
00165             PARENT::df_decoder.popItem();
00166             delete static_cast<LEAF*>((*mt_iter).second);
00167             mt_iter = PARENT::main_trie.edgelist.erase(mt_iter);
00168          }
00169       }
00170 //      log_perf(0,"Number of prefix equisupport items: %d", nr_of_prefix_equiitem); 
00171    }
00172 }
00173 
00174 }
00175 
00176 #endif

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