00001
00008 #ifndef RBTreeDBCacheInsertThenDestroyPro_HPP
00009 #define RBTreeDBCacheInsertThenDestroyPro_HPP
00010
00011 #include <vector>
00012 #include <map>
00013 #include "io/db_cache/transaction_shrinker/RBTreeDBCacheInsertThenDestroyBase.hpp"
00014
00015
00016 namespace Bodon
00017 {
00025 template< class T_R, class BIS = std::vector<item_t> >
00026 class RBTreeDBCacheInsertThenDestroyPro :
00027 public RBTreeDBCacheInsertThenDestroyBase<T_R, BIS>
00028 {
00029 public:
00030 typedef typename RBTreeDBCacheInsertThenDestroyBase<T_R, BIS>
00031 ::params_t params_t;
00032
00033 RBTreeDBCacheInsertThenDestroyPro( const params_t* par )
00034 : RBTreeDBCacheInsertThenDestroyBase<T_R, BIS>(par){}
00035
00036
00037 void rewind()
00038 {
00039 typename std::map<BIS, counter_t>::const_iterator it_temp =
00040 RBTreeDBCacheInsertThenDestroyBase<T_R, BIS>::temp_rb_tree.begin();
00041
00042 typename std::map<BIS, counter_t>::iterator it_large =
00043 RBTreeDBCacheInsertThenDestroyBase<T_R, BIS>::rb_tree.begin();
00044 typename std::map<BIS, counter_t>::iterator it_temp_large;
00045
00046 while( it_temp != RBTreeDBCacheInsertThenDestroyBase<T_R, BIS>::temp_rb_tree.end() &&
00047 it_large != RBTreeDBCacheInsertThenDestroyBase<T_R, BIS>::rb_tree.end() )
00048 {
00049 if(it_temp->first < it_large->first)
00050 {
00051 RBTreeDBCacheInsertThenDestroyBase<T_R, BIS>::
00052 rb_tree[it_temp->first] = it_temp->second;
00053
00054
00055
00056
00057
00058
00059 ++it_temp;
00060
00061 }
00062 else if(it_temp->first > it_large->first)
00063 ++it_large;
00064 else
00065 {
00066 it_large->second += it_temp->second;
00067 ++it_temp;
00068 ++it_large;
00069 }
00070 }
00071 while( it_temp != RBTreeDBCacheInsertThenDestroyBase<T_R, BIS>::
00072 temp_rb_tree.end() )
00073 {
00074 RBTreeDBCacheInsertThenDestroyBase<T_R, BIS>::
00075 rb_tree[it_temp->first] = it_temp->second;
00076 ++it_temp;
00077 }
00078 RBTreeDBCacheInsertThenDestroyBase<T_R, BIS>::rewind();
00079 }
00080 };
00081
00082 }
00083 #endif