00001 #ifndef SupportCounterLookupTransOffsetBitVec_HPP
00002 #define SupportCounterLookupTransOffsetBitVec_HPP
00003
00004 #include "common.hpp"
00005 #include <vector>
00006 #include "apriori/bodon/Leaf.hpp"
00007
00008
00009
00010
00011
00012 namespace Bodon
00013 {
00014 template <class TRIE>
00015 class SupportCounterLookupTransOffsetBitVec
00016 {
00017 public:
00018 SupportCounterLookupTransOffsetBitVec( ){}
00019
00020 void updateCounters(
00021 TRIE& main_trie, const std::vector<item_t>& transaction,
00022 item_t candidate_size, const counter_t counter_incr)
00023 {
00024 if( candidate_size <= transaction.size() )
00025 {
00026 const item_t offset = transaction.front();
00027 std::vector<bool> trans_vector(transaction.back() - offset + 1, false);
00028
00029 for(std::vector<item_t>::const_iterator it_basket = transaction.begin();
00030 it_basket != transaction.end(); ++it_basket)
00031 trans_vector[*it_basket - offset] = true;
00032
00033
00034
00035
00036 std::vector<item_t>::const_iterator
00037 it_basket_upper_bound = transaction.end()-candidate_size+1;
00038 --candidate_size;
00039 typename TRIE::iterator it_edge(main_trie.edgelist.begin());
00040 while( it_edge != main_trie.edgelist.end() && (*it_edge).first < offset )
00041 ++it_edge;
00042 while( it_edge != main_trie.edgelist.end() &&
00043 (*it_edge).first < *it_basket_upper_bound )
00044 {
00045 if( trans_vector[(*it_edge).first - offset] )
00046 if( candidate_size )
00047 findCandidatesAssist( static_cast<TRIE*>((*it_edge).second),
00048 offset, trans_vector,
00049 candidate_size, counter_incr);
00050 else
00051 static_cast<Leaf*>((*it_edge).second)
00052 ->increaseCounter( counter_incr);
00053 ++it_edge;
00054 }
00055 }
00056 }
00057
00058 protected:
00059 void findCandidatesAssist(
00060 TRIE* subtrie, const item_t offset,
00061 const std::vector<bool>& trans_vector, item_t step_to_candidate,
00062 const counter_t counter_incr );
00063
00064 };
00065
00066 template <class TRIE> void
00067 SupportCounterLookupTransOffsetBitVec<TRIE>::findCandidatesAssist(
00068 TRIE* subtrie, const item_t offset,
00069 const std::vector<bool>& trans_vector,item_t step_to_candidate,
00070 const counter_t counter_incr )
00071 {
00072 --step_to_candidate;
00073 typename TRIE::iterator it_edge(subtrie->edgelist.begin());
00074 if( step_to_candidate )
00075 {
00076 while( it_edge != subtrie->edgelist.end() &&
00077 (*it_edge).first < trans_vector.size() + offset)
00078 {
00079 if( trans_vector[(*it_edge).first - offset] )
00080 findCandidatesAssist( static_cast<TRIE*>((*it_edge).second),
00081 offset, trans_vector,
00082 step_to_candidate, counter_incr);
00083 ++it_edge;
00084 }
00085 }
00086 else
00087 {
00088 while( it_edge != subtrie->edgelist.end() &&
00089 (*it_edge).first < trans_vector.size() + offset)
00090 {
00091 if( trans_vector[(*it_edge).first - offset] )
00092 static_cast<Leaf*>((*it_edge).second)
00093 ->increaseCounter( counter_incr);
00094 ++it_edge;
00095 }
00096 }
00097 }
00098 }
00099 #endif