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

support_counter/SupportCounterMerge.hpp

Go to the documentation of this file.
00001 #ifndef SupportCounterMerge_HPP
00002 #define SupportCounterMerge_HPP
00003 
00004 #include "common.hpp"
00005 #include <vector>
00006 #include "apriori/bodon/Leaf.hpp"
00007 //#include <cstdio>
00008 //#include <iterator>   //for test
00009 
00010 
00011 
00012 
00013 namespace Bodon
00014 {
00015    template <class TRIE>
00016    class SupportCounterMerge
00017    {
00018       protected:
00019          typedef Leaf LEAF;
00020       public:
00021          SupportCounterMerge( ){}
00022 
00023          void updateCounters(
00024             TRIE& main_trie, const std::vector<item_t>& transaction,
00025             item_t candidate_size, const counter_t counter_incr)
00026          {
00027             if( candidate_size <= transaction.size() )
00028                findCandidates( 
00029                   &main_trie, transaction.end()-candidate_size+1, 
00030                   transaction.begin(), candidate_size,
00031                   counter_incr );
00032          }
00033 
00034       protected:
00037          void findCandidates( TRIE* subtrie,
00038             std::vector<item_t>::const_iterator it_basket_upper_bound,
00039             std::vector<item_t>::const_iterator it_basket, 
00040             item_t step_to_candidate,
00041             const counter_t counter_incr );
00042    };
00043 
00044    template <class TRIE> void 
00045    SupportCounterMerge<TRIE>::findCandidates( 
00046       TRIE* subtrie, std::vector<item_t>::const_iterator it_basket_upper_bound,
00047       std::vector<item_t>::const_iterator it_basket, 
00048       item_t step_to_candidate, const counter_t counter_incr )
00049    {
00050       --step_to_candidate;
00051       typename TRIE::iterator it_edge(subtrie->edgelist.begin());
00052       if( step_to_candidate ) 
00053       {
00054          while( it_edge != subtrie->edgelist.end() && 
00055                 it_basket != it_basket_upper_bound )
00056          {
00057             if( (*it_edge).first < *it_basket) ++it_edge;
00058             else if( (*it_edge).first > *it_basket) ++it_basket;
00059             else
00060             {
00061                ++it_basket;
00062                findCandidates( static_cast<TRIE*>((*it_edge).second),
00063                                it_basket_upper_bound + 1, it_basket, 
00064                                step_to_candidate, counter_incr);
00065                ++it_edge;
00066             }
00067          }
00068       }
00069       else
00070       {
00071          while( it_edge != subtrie->edgelist.end() && 
00072                 it_basket != it_basket_upper_bound )
00073          {
00074             if( (*it_edge).first < *it_basket) ++it_edge;
00075             else if( (*it_edge).first > *it_basket) ++it_basket;
00076             else
00077             {
00078                ++it_basket;
00079                static_cast<LEAF*>((*it_edge).second)
00080                      ->increaseCounter( counter_incr);
00081                ++it_edge;
00082             }
00083          }
00084       }
00085    }
00086 }
00087 #endif

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