00001 #ifndef FrequentItemInserterDyn_HPP 00002 #define FrequentItemInserterDyn_HPP 00003 00004 #include "common.hpp" 00005 #include "common/Edge.hpp" 00006 #include "apriori/bodon/trie/trie_manipulators/ManipulatorBase.hpp" 00007 #include "apriori/bodon/Leaf.hpp" 00008 #include <vector> 00009 //#include <cstdio> 00010 //#include <iterator> //for test 00011 00012 00013 namespace Bodon 00014 { 00015 namespace dynamic_trie 00016 { 00017 template <class DF_D, class TRIE_OEL, NEELevel NEE> 00018 class FrequentItemInserter : public Bodon::ManipulatorBase<DF_D, TRIE_OEL> 00019 { 00020 private: 00021 typedef Bodon::ManipulatorBase<DF_D, TRIE_OEL> PARENT; 00022 public: 00023 FrequentItemInserter( TRIE_OEL& trie, DF_D& df_decoder ) : 00024 PARENT(trie, df_decoder){} 00025 00027 void setEmptysetSupport(const counter_t emptyset_support) 00028 { 00029 PARENT::main_trie.setCounter(emptyset_support | TWO_POW31); 00030 } 00031 00033 void insertFrequentItems(const std::vector<counter_t>& freq_counters ) 00034 { 00035 std::vector<Edge> extenders; 00036 if(NEE > NEE_Off) 00037 { 00038 unsigned int nr_of_prefix_equiitem=0; 00039 for(item_t index = 0; index < freq_counters.size(); ++index) 00040 { 00041 00042 if( freq_counters[index] == 00043 PARENT::main_trie.getCounter() ) 00044 { 00045 #if DEBUG_LEVEL >= LEVEL_PERF 00046 ++nr_of_prefix_equiitem; 00047 #endif 00048 PARENT::main_trie.neelist.push_back(index); 00049 } 00050 else 00051 extenders.push_back(Edge(index, new Bodon::Leaf(freq_counters[index]))); 00052 } 00053 PARENT::main_trie.edgelist.insert(extenders); 00054 // log_perf(0,"Number of prefix equisupport items: %d", nr_of_prefix_equiitem); 00055 } 00056 else 00057 { 00058 PARENT::df_decoder.write(PARENT::main_trie.getCounter() 00059 & TWO_POW31_1); 00060 00061 for(item_t index = 0; index < freq_counters.size(); ++index) 00062 { 00063 PARENT::df_decoder.pushItemWithWrite( index, freq_counters[index] ); 00064 extenders.push_back( Edge(index, new Bodon::Leaf(freq_counters[index])) ); 00065 PARENT::df_decoder.popItem(); 00066 } 00067 PARENT::main_trie.edgelist.insert(extenders); 00068 } 00069 } 00070 }; 00071 } 00072 } 00073 00074 #endif