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

SupportCounterIterArray.hpp

Go to the documentation of this file.
00001 #ifndef SupportCounterIterArray_HPP
00002 #define SupportCounterIterArray_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 namespace sequence
00016 {
00017    template <class TRIE>
00018    class SupportCounterIterArray
00019    {
00020       public:
00021          SupportCounterIterArray( ){}
00022 
00023       public:
00026          void findCandidates( TRIE* subtrie,
00027             std::vector<item_t>::const_iterator it_basket_upper_bound,
00028             std::vector<item_t>::const_iterator it_basket, 
00029             item_t step_to_candidate,
00030             const counter_t counter_incr );
00031       private:
00032          typedef std::vector<std::vector<item_t>::const_iterator> iter_vector_t;
00033          typedef std::vector< iter_vector_t > iter_array_t;
00034          
00035          void findCandidatesAssist( 
00036             TRIE* subtrie, 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, const counter_t counter_incr,
00039             std::vector< iter_vector_t::const_iterator >& first_occurences, 
00040             const std::vector< iter_vector_t::const_iterator >& iter_ends );
00041 
00042    };
00043 
00044    template <class TRIE> void 
00045    SupportCounterIterArray<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       iter_array_t iter_array;
00051       for( std::vector<item_t>::const_iterator it_basket2 = it_basket; 
00052            it_basket2 != it_basket_upper_bound + step_to_candidate -1; 
00053            ++it_basket2)
00054       {
00055          if(*it_basket2 >= iter_array.size())
00056             iter_array.resize(*it_basket2 + 1);
00057          iter_array[*it_basket2].push_back(it_basket2);        
00058       }
00059       std::vector< iter_vector_t::const_iterator > first_occurences, iter_ends;
00060       first_occurences.reserve(iter_array.size());
00061       iter_ends.reserve(iter_array.size());
00062       for(iter_array_t::const_iterator it_first_occ = iter_array.begin(); 
00063          it_first_occ != iter_array.end(); ++it_first_occ)
00064       {
00065          first_occurences.push_back((*it_first_occ).begin());
00066          iter_ends.push_back((*it_first_occ).end());
00067       }
00068       findCandidatesAssist( subtrie, it_basket_upper_bound, it_basket, 
00069                             step_to_candidate, counter_incr, 
00070                             first_occurences, iter_ends );
00071    }
00072 
00073    template <class TRIE> void 
00074    SupportCounterIterArray<TRIE>::findCandidatesAssist( 
00075       TRIE* subtrie, std::vector<item_t>::const_iterator it_basket_upper_bound,
00076       const std::vector<item_t>::const_iterator it_basket, 
00077       item_t step_to_candidate, const counter_t counter_incr,
00078       std::vector< iter_vector_t::const_iterator >& first_occurences, 
00079       const std::vector< iter_vector_t::const_iterator >& iter_ends )
00080    {
00081       --step_to_candidate;
00082       iter_vector_t::const_iterator first_occurenc_origin;
00083       std::vector<item_t>::const_iterator it_basket_next;
00084       for( typename TRIE::iterator it_edge(subtrie->edgelist.begin()); 
00085            it_edge != subtrie->edgelist.end(); ++it_edge)
00086       {
00087          if( (*it_edge).first < first_occurences.size() && 
00088              first_occurences[(*it_edge).first] != iter_ends[(*it_edge).first])
00089          {
00090             first_occurenc_origin = first_occurences[(*it_edge).first];
00091             while(*(first_occurences[(*it_edge).first]) < it_basket)
00092             {
00093                ++first_occurences[(*it_edge).first];
00094                if( first_occurences[(*it_edge).first] == iter_ends[(*it_edge).first] )
00095                   break;
00096             }
00097 
00098             if(first_occurences[(*it_edge).first] != iter_ends[(*it_edge).first] &&
00099                *(first_occurences[(*it_edge).first]) < it_basket_upper_bound)
00100             {
00101                it_basket_next = *(first_occurences[(*it_edge).first]) + 1;
00102                ++first_occurences[(*it_edge).first];
00103                if( step_to_candidate ) 
00104                   findCandidatesAssist( 
00105                      static_cast<TRIE*>((*it_edge).second), it_basket_upper_bound + 1, 
00106                      it_basket_next, step_to_candidate, counter_incr, 
00107                      first_occurences, iter_ends );
00108                else
00109                   static_cast<Leaf*>((*it_edge).second)->increaseCounter(counter_incr);
00110             }
00111             first_occurences[(*it_edge).first] = first_occurenc_origin;
00112          }
00113       }
00114    }
00115 }
00116 }
00117 #endif

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