00001 #ifndef SupportCounter_HPP
00002 #define SupportCounter_HPP
00003
00004
00005 #include "common.hpp"
00006 #include <vector>
00007 #include "apriori/bodon/Leaf.hpp"
00008
00009
00010
00011
00012
00013
00014 namespace Bodon
00015 {
00016 namespace dynamic_trie
00017 {
00018 template <class TRIE_OEL, class TRIE_OI>
00019 class SupportCounter
00020 {
00021 private:
00022 typedef Bodon::Leaf LEAF;
00023 public:
00024 SupportCounter( ){}
00025
00026 void updateCounters(
00027 TRIE_OEL& main_trie, const std::vector<item_t>& transaction,
00028 item_t candidate_size, const counter_t counter_incr)
00029 {
00030 if( candidate_size <= transaction.size() )
00031 findCandidates(
00032 &main_trie, transaction.end()-candidate_size+1,
00033 transaction.begin(), candidate_size,
00034 counter_incr );
00035 }
00036 protected:
00039 void findCandidates( TRIE_OEL* subtrie,
00040 std::vector<item_t>::const_iterator it_basket_upper_bound,
00041 std::vector<item_t>::const_iterator it_basket,
00042 item_t step_to_candidate,
00043 const counter_t counter_incr );
00044 void findCandidates( TRIE_OI* subtrie,
00045 std::vector<item_t>::const_iterator it_basket_upper_bound,
00046 std::vector<item_t>::const_iterator it_basket,
00047 item_t step_to_candidate,
00048 const counter_t counter_incr );
00049 };
00050
00051 template <class TRIE_OEL, class TRIE_OI> void
00052 SupportCounter<TRIE_OEL, TRIE_OI>::findCandidates(
00053 TRIE_OEL* subtrie, std::vector<item_t>::const_iterator it_basket_upper_bound,
00054 std::vector<item_t>::const_iterator it_basket,
00055 item_t step_to_candidate, const counter_t counter_incr )
00056 {
00057 --step_to_candidate;
00058 typename TRIE_OEL::iterator it_edge(subtrie->edgelist.begin());
00059 if( step_to_candidate )
00060 {
00061 while( it_edge != subtrie->edgelist.end() &&
00062 it_basket != it_basket_upper_bound )
00063 {
00064 if( (*it_edge).first < *it_basket) ++it_edge;
00065 else if( (*it_edge).first > *it_basket) ++it_basket;
00066 else
00067 {
00068 ++it_basket;
00069 if(static_cast<LEAF*>((*it_edge).second)->getCounter() & TWO_POW31)
00070 findCandidates( static_cast<TRIE_OEL*>((*it_edge).second),
00071 it_basket_upper_bound + 1, it_basket,
00072 step_to_candidate, counter_incr);
00073 else
00074 findCandidates( static_cast<TRIE_OI*>((*it_edge).second),
00075 it_basket_upper_bound + 1, it_basket,
00076 step_to_candidate, counter_incr);
00077 ++it_edge;
00078 }
00079 }
00080 }
00081 else
00082 {
00083 while( it_edge != subtrie->edgelist.end() &&
00084 it_basket != it_basket_upper_bound )
00085 {
00086 if( (*it_edge).first < *it_basket) ++it_edge;
00087 else if( (*it_edge).first > *it_basket) ++it_basket;
00088 else
00089 {
00090 ++it_basket;
00091 static_cast<LEAF*>((*it_edge).second)
00092 ->increaseCounter( counter_incr);
00093 ++it_edge;
00094 }
00095 }
00096 }
00097
00098 }
00099
00100 template <class TRIE_OEL, class TRIE_OI> void
00101 SupportCounter<TRIE_OEL, TRIE_OI>::findCandidates(
00102 TRIE_OI* subtrie, std::vector<item_t>::const_iterator it_basket_upper_bound,
00103 std::vector<item_t>::const_iterator it_basket,
00104 item_t step_to_candidate, const counter_t counter_incr )
00105 {
00106 --step_to_candidate;
00107 void* subsubtrie;
00108 item_t largest_label = subtrie->edgelist.largestEdgelabel();
00109 if( step_to_candidate )
00110 {
00111 while( it_basket != it_basket_upper_bound && *it_basket <= largest_label)
00112 {
00113 subtrie->edgelist.lookupNoUppercheck(*it_basket, subsubtrie);
00114 ++it_basket;
00115 if(subsubtrie)
00116 if(static_cast<LEAF*>(subsubtrie)->getCounter() & TWO_POW31)
00117 findCandidates( static_cast<TRIE_OEL*>(subsubtrie),
00118 it_basket_upper_bound + 1, it_basket,
00119 step_to_candidate, counter_incr );
00120 else
00121 findCandidates( static_cast<TRIE_OI*>(subsubtrie),
00122 it_basket_upper_bound + 1, it_basket,
00123 step_to_candidate, counter_incr );
00124 }
00125 }
00126 else
00127 {
00128 while( it_basket != it_basket_upper_bound && *it_basket <= largest_label)
00129 {
00130 subtrie->edgelist.lookupNoUppercheck(*it_basket, subsubtrie);
00131 ++it_basket;
00132 if(subsubtrie)
00133 static_cast<LEAF*>(subsubtrie)
00134 ->increaseCounter( counter_incr);
00135 }
00136 }
00137 }
00138
00139 }
00140 }
00141 #endif