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