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

OrderedArrayDBCache.hpp

Go to the documentation of this file.
00001 #ifndef OrderedArrayDBCache_HPP
00002 #define OrderedArrayDBCache_HPP
00003 
00004 #include <vector>
00005 #include <set>
00006 #include <map>
00007 #include <functional>
00008 #include "io/db_cache/OrderedVectorDBCache.hpp" // to avoid retyping "less_itemset" predicate
00009 //#include <fstream>
00010 
00011 
00017 template <class T_R, class BIS>
00018 class OrderedArrayDBCache : public T_R
00019 {
00020    public:
00021       typedef typename T_R::params_t params_t;
00022 
00023       OrderedArrayDBCache( const params_t* par );
00024 
00025       counter_t nextTransactionBIS( 
00026          BIS& transaction );
00027 
00028       template <class UAC> counter_t nextTransactionUAC( 
00029          UAC& transaction );
00030 
00031       void rewind()
00032       {
00033          it_v = ordered_array.begin();
00034          while(it_v != ordered_array.end() && (*it_v).empty() )
00035             ++it_v;
00036          it = (*it_v).begin();
00037       }
00038    protected:
00039       std::vector<std::vector< std::pair<BIS, counter_t> > > ordered_array;
00040       typename std::vector<std::pair<BIS, counter_t> >::iterator it;
00041       typename std::vector<std::vector< std::pair<BIS, counter_t> > >
00042          ::iterator it_v;
00043 
00044 
00045 };
00046 
00047 template <class T_R, class BIS> inline OrderedArrayDBCache<T_R, BIS>::
00048 OrderedArrayDBCache(const params_t* par) : T_R(par)
00049 {
00050    BIS transaction;
00051    register counter_t multiplicity;
00052    unsigned int index;
00053    T_R::rewind();
00054    while( (multiplicity = T_R::nextTransactionBIS(
00055               transaction)) != 0 )
00056       if(transaction.size() > 1) 
00057       {
00058          index = transaction.size();
00059          if( index >= ordered_array.size() )
00060             ordered_array.resize(index + 1);
00061          it = std::lower_bound( ordered_array[index].begin(), 
00062                                 ordered_array[index].end(), 
00063                                 transaction, less_itemset<BIS> );
00064          if(it != ordered_array[index].end() && (*it).first == transaction)
00065             (*it).second += multiplicity;
00066          else
00067             ordered_array[index].insert( 
00068                it, std::pair<BIS, counter_t>(transaction, multiplicity) );
00069       }
00070    rewind();
00071 }
00072 
00073 template <class T_R, class BIS> inline counter_t OrderedArrayDBCache<T_R, BIS>::
00074 nextTransactionBIS( BIS& transaction )
00075 {
00076    if( it == (*it_v).end() )
00077    {
00078       do
00079       {
00080          ++it_v;
00081          if(it_v == ordered_array.end())
00082             return 0;       
00083       }
00084       while( (*it_v).empty() );
00085       it = (*it_v).begin();
00086    }
00087    transaction = (*it).first;
00088    return (*(it++)).second;
00089 
00090 }
00091 
00092 template <class T_R, class BIS> template <class UAC> inline counter_t 
00093 OrderedArrayDBCache<T_R, BIS>::nextTransactionUAC( UAC& transaction )
00094 {
00095    if( it == (*it_v).end() )
00096    {
00097       do
00098       {
00099          ++it_v;
00100          if(it_v == ordered_array.end())
00101             return 0;       
00102       }
00103       while( (*it_v).empty() );
00104       it = (*it_v).begin();
00105    }
00106    transaction.clear();
00107    transaction.insert((*it).first.begin(), (*it).first.end());
00108    return (*(it++)).second;
00109 }
00110 
00111 #endif

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