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

RBTreeDBCacheInsertThenDestroyBase.hpp

Go to the documentation of this file.
00001 #ifndef RBTreeDBCacheInsertThenDestroyBase_HPP
00002 #define RBTreeDBCacheInsertThenDestroyBase_HPP
00003 
00004 #include <vector>
00005 #include <map>
00006 #include "io/db_cache/RBTreeDBCache.hpp"
00007 //#include <fstream>
00008 
00009 namespace Bodon
00010 {
00011    template< class T_R, class BIS = std::vector<item_t> >
00012    class RBTreeDBCacheInsertThenDestroyBase : public RBTreeDBCache<T_R, BIS>
00013    {
00014       public:
00015          typedef typename RBTreeDBCache<T_R, BIS>::params_t params_t;
00016 
00017          RBTreeDBCacheInsertThenDestroyBase( const params_t* par )
00018             : RBTreeDBCache<T_R, BIS>(par){}
00019 
00020          counter_t nextTransactionBIS_modifyPrevious( 
00021             BIS& transaction, std::vector<unsigned int>& filter);
00022 
00023          void rewind()
00024          {
00025             temp_rb_tree.clear();
00026             RBTreeDBCache<T_R, BIS>::rewind();
00027          }
00028          void setCandidateSize(const size_t candidate_size)
00029          {
00030             this->candidate_size = candidate_size;
00031          }
00032       protected:
00033          std::map<BIS, counter_t> temp_rb_tree;
00034          item_t candidate_size;
00035    };
00036 
00037    template <class T_R, class BIS> inline counter_t 
00038    RBTreeDBCacheInsertThenDestroyBase<T_R, BIS>::
00039    nextTransactionBIS_modifyPrevious( BIS& transaction, 
00040                                       std::vector<unsigned int>& filter)
00041    {
00042       typename BIS::iterator it_tr = transaction.begin();
00043       while( it_tr != transaction.end())
00044       {
00045          if(filter[*it_tr] < candidate_size)
00046          {
00047             filter[*it_tr] = 0;
00048             it_tr = transaction.erase(it_tr);
00049             while(it_tr != transaction.end())
00050             {
00051                if(filter[*it_tr] < candidate_size)
00052                {
00053                   filter[*it_tr] = 0;
00054                   it_tr = transaction.erase(it_tr);
00055                }
00056                else
00057                {
00058                   filter[*it_tr++] = 0;
00059                }
00060             }
00061             --RBTreeDBCache<T_R, BIS>::it;
00062             if(transaction.size() > candidate_size)
00063                temp_rb_tree[transaction] += RBTreeDBCache<T_R, BIS>::it->second;
00064             RBTreeDBCache<T_R, BIS>::rb_tree.erase(RBTreeDBCache<T_R, BIS>::it++);
00065             return RBTreeDBCache<T_R, BIS>::nextTransactionBIS(transaction);
00066          }
00067          filter[*it_tr++] = 0;
00068       }
00069       if(transaction.size() <= candidate_size)
00070       {
00071          --RBTreeDBCache<T_R, BIS>::it;
00072          RBTreeDBCache<T_R, BIS>::rb_tree.erase(RBTreeDBCache<T_R, BIS>::it++);
00073       }
00074       return RBTreeDBCache<T_R, BIS>::nextTransactionBIS(transaction);
00075    }
00076 }
00077 #endif

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