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

SupportCounterHybridSimple.hpp

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

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