00001 #ifndef StatInput_HPP 00002 #define StatInput_HPP 00003 00008 #include "common.hpp" 00009 #include "common/log.h" 00010 #include "io/input/transaction_reader/brBufferedTransactionReader.hpp" 00011 00012 #include <vector> 00022 template <class TR = brBufferedTransactionReader< > > 00023 class StatInput : public TR 00024 { 00025 unsigned int nr_of_transaction, sum_of_tr_sizes; 00026 std::vector<bool> items; 00027 bool first_run; 00028 00029 counter_t temp_ret_value; 00030 public: 00031 typedef typename TR::params_t params_t; 00032 StatInput( const params_t* par ): 00033 TR(par), nr_of_transaction(0), 00034 sum_of_tr_sizes(0), first_run(true) { } 00035 template <class BIS> counter_t nextTransactionBIS( BIS& transaction ) 00036 { 00037 00038 if(first_run) 00039 { 00040 temp_ret_value = TR::nextTransactionBIS( transaction); 00041 if(temp_ret_value) 00042 { 00043 nr_of_transaction += temp_ret_value; 00044 sum_of_tr_sizes += transaction.size(); 00045 for(typename BIS::iterator it = transaction.begin(); 00046 it != transaction.end(); ++it) 00047 { 00048 if(*it >= items.size()) 00049 items.resize(*it + 1, false); 00050 items[*it] = true; 00051 } 00052 } 00053 else 00054 first_run = false; 00055 return temp_ret_value; 00056 } 00057 else 00058 return TR::nextTransactionBIS( transaction); 00059 } 00060 ~StatInput() 00061 { 00062 std::cout<<"Number of transactions: "<<nr_of_transaction<<std::endl; 00063 std::cout<<"Average size of the transactions: "<< 00064 static_cast<double>(sum_of_tr_sizes)/nr_of_transaction<<std::endl; 00065 std::cout<<"Number of items: "<< 00066 std::count(items.begin(), items.end(), true)<<std::endl; 00067 } 00068 }; 00069 00070 #endif //StatInput_HPP