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

RBTreeDBCache.hpp

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

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