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

sequence/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 <algorithm>
00008 
00009 //#include <cstdio>
00010 //#include <iterator>   //for test
00011 
00012 
00013 
00014 
00015 namespace Bodon
00016 {
00017 namespace sequence
00018 {
00019    template <class TRIE>
00020    class SupportCounterMerge
00021    {
00022       private:
00023          class SeqFirstOcc : public std::pair<item_t, std::vector<item_t>::const_iterator>
00024          {
00025             public:
00026                SeqFirstOcc(item_t item, std::vector<item_t>::const_iterator it) :
00027                   std::pair<item_t, std::vector<item_t>::const_iterator>(item, it){}
00028  
00029 /*             bool operator<(const SeqFirstOcc& x) const
00030                {
00031                   return first < x.first;
00032                   }*/
00033                bool operator==(const SeqFirstOcc& x) const
00034                {
00035                   return first == x.first;
00036                }
00037          };
00038 
00039       public:
00040          SupportCounterMerge( ){}
00041 
00044          void findCandidates( TRIE* subtrie,
00045             std::vector<item_t>::const_iterator it_transaction_upper_bound,
00046             std::vector<item_t>::const_iterator it_transaction, 
00047             item_t step_to_candidate,
00048             const counter_t counter_incr );
00049 
00050 
00051    };
00052 
00053    template <class TRIE> void 
00054    SupportCounterMerge<TRIE>::findCandidates( 
00055       TRIE* subtrie, std::vector<item_t>::const_iterator it_transaction_upper_bound,
00056       std::vector<item_t>::const_iterator it_transaction, 
00057       item_t step_to_candidate, const counter_t counter_incr )
00058    {
00059       --step_to_candidate;
00060       vector<bool>::size_type largestEdgelabel = 
00061          subtrie->edgelist.largestEdgelabel();
00062       vector<bool>::size_type smallestEdgelabel = 
00063          subtrie->edgelist.smallestEdgelabel();
00064 
00065       typename std::vector<SupportCounterMerge<TRIE>::SeqFirstOcc> 
00066          first_occ;
00067       first_occ.reserve(it_transaction_upper_bound - it_transaction);
00068       while(it_transaction != it_transaction_upper_bound)
00069          if(*it_transaction <= largestEdgelabel &&
00070             *it_transaction >= smallestEdgelabel )
00071             first_occ.push_back(SupportCounterMerge<TRIE>::SeqFirstOcc(
00072                                    *it_transaction, ++it_transaction));
00073          else
00074             ++it_transaction;
00075 //       std::stable_sort(first_occ.begin(), first_occ.end() );
00076       std::sort(first_occ.begin(), first_occ.end() );
00077       first_occ.erase( std::unique(first_occ.begin(), first_occ.end() ), 
00078                        first_occ.end() );
00079          
00080       typename TRIE::iterator it_edge(subtrie->edgelist.begin());
00081       typename std::vector<SupportCounterMerge<TRIE>::SeqFirstOcc>::const_iterator 
00082          it_transaction2(first_occ.begin());
00083       while( it_edge != subtrie->edgelist.end() && 
00084              it_transaction2 != first_occ.end() )
00085       {
00086          if( (*it_edge).first < (*it_transaction2).first ) ++it_edge;
00087          else if( (*it_edge).first > (*it_transaction2).first ) 
00088             ++it_transaction2;
00089          else
00090          {
00091             if( step_to_candidate ) 
00092                findCandidates( static_cast<TRIE*>((*it_edge).second),
00093                                it_transaction_upper_bound + 1, 
00094                                (*it_transaction2).second, 
00095                                step_to_candidate, counter_incr);
00096             else
00097                static_cast<Leaf*>((*it_edge).second)
00098                   ->increaseCounter( counter_incr);
00099             ++it_transaction2;
00100             ++it_edge;
00101          }
00102       }
00103    }
00104 }
00105 }
00106 #endif

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