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

SupportCounterLookupTransOffsetIndex.hpp

Go to the documentation of this file.
00001 #ifndef SupportCounterLookupTransOffsetIndex_HPP
00002 #define SupportCounterLookupTransOffsetIndex_HPP
00003 
00004 #include "common.hpp"
00005 #include <vector>
00006 #include "apriori/bodon/Leaf.hpp"
00007 //#include <iterator>   //for test
00008 
00009 
00010 
00011 
00012 namespace Bodon
00013 {
00014    template <class TRIE>
00015    class SupportCounterLookupTransOffsetIndex
00016    {
00017       public:
00018          SupportCounterLookupTransOffsetIndex( ){}
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<size_t> trans_vector(transaction.back() - offset + 1, 0);
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] = it_basket - transaction.begin() +1;
00032 
00033 // We have to find the first label of the root that is greater than the offset.
00034 // As soon as such label is found, we know that all other labels that 
00035 // will be tested in the recursion are greater than the offset.
00036             std::vector<item_t>::const_iterator 
00037                it_basket_upper_bound = transaction.end()-candidate_size+1;
00038             size_t index_upper_bound = transaction.size()-candidate_size+3;
00039             --candidate_size;
00040             typename TRIE::iterator it_edge(main_trie.edgelist.begin());
00041             while( it_edge != main_trie.edgelist.end() && (*it_edge).first < offset )
00042                ++it_edge;
00043             while( it_edge != main_trie.edgelist.end() && 
00044                    (*it_edge).first < *it_basket_upper_bound )
00045             {
00046                if( trans_vector[(*it_edge).first - offset] )
00047                   if( candidate_size ) 
00048                      findCandidatesAssist( static_cast<TRIE*>((*it_edge).second),
00049                                            offset, trans_vector, index_upper_bound,
00050                                            candidate_size, counter_incr);
00051                   else
00052                      static_cast<Leaf*>((*it_edge).second)
00053                         ->increaseCounter( counter_incr);
00054                ++it_edge;
00055             }
00056             }
00057          }
00058 
00059       protected:
00060          void findCandidatesAssist( 
00061             TRIE* subtrie, const item_t offset,
00062             const std::vector<size_t>& trans_vector, size_t index_upper_bound,
00063             item_t step_to_candidate, const counter_t counter_incr );
00064          
00065    };
00066 
00067    template <class TRIE> void 
00068    SupportCounterLookupTransOffsetIndex<TRIE>::findCandidatesAssist( 
00069       TRIE* subtrie, const item_t offset, const std::vector<size_t>& trans_vector,
00070       const size_t index_upper_bound, item_t step_to_candidate, 
00071       const counter_t counter_incr )
00072    {
00073       --step_to_candidate;
00074       typename TRIE::iterator it_edge(subtrie->edgelist.begin());
00075       if( step_to_candidate ) 
00076       {
00077          while( it_edge != subtrie->edgelist.end() && 
00078                 (*it_edge).first < trans_vector.size() + offset)
00079          {
00080             if( trans_vector[(*it_edge).first - offset] )
00081                if( trans_vector[(*it_edge).first - offset] < index_upper_bound)
00082                   findCandidatesAssist( static_cast<TRIE*>((*it_edge).second),
00083                                         offset, trans_vector, index_upper_bound+1,
00084                                         step_to_candidate, counter_incr);
00085                else
00086                   break;
00087             ++it_edge;
00088          }
00089       }
00090       else
00091       {
00092          while( it_edge != subtrie->edgelist.end() && 
00093                 (*it_edge).first < trans_vector.size() + offset)
00094          {
00095             if( trans_vector[(*it_edge).first - offset] )
00096                if( trans_vector[(*it_edge).first - offset] < index_upper_bound)
00097                   static_cast<Leaf*>((*it_edge).second)
00098                      ->increaseCounter( counter_incr);
00099                else
00100                   break;
00101             ++it_edge;
00102          }
00103       }
00104    }
00105 }
00106 #endif

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