00001
00006 #ifndef __SPARSEBITMATRIX_CREATE_HPP_
00007 #define __SPARSEBITMATRIX_CREATE_HPP_ t
00008
00009
00010
00011 #include "common/debug.hpp"
00012
00013
00014
00015
00016 #include <vector>
00017
00018 typedef std::vector<std::pair<counter_t, item_t> > CounterItemPairs;
00019
00026 template <class TRANSACTION_READER>
00027 SparseBitmatrix* createSparseItemTransactionIncidenceMatrix(TRANSACTION_READER& tdb, CounterItemPairs& freqItems) {
00028 SparseBitmatrix* iti = NULL;
00029
00030
00031 int numItems = freqItems.size();
00032 int* itemFrequencies = new int[numItems];
00033 CounterItemPairs::iterator it_freqItems;
00034 int i = 0;
00035 for( it_freqItems = freqItems.begin(); it_freqItems != freqItems.end(); ++it_freqItems )
00036 itemFrequencies[i++] = it_freqItems->first;
00037
00038
00039
00040
00041 iti = new SparseBitmatrix(numItems, itemFrequencies);
00042
00043
00044
00045
00046
00047
00048
00049
00050 tdb.rewind();
00051 std::vector<item_t> transaction;
00052 std::vector<item_t>::iterator it_transaction;
00053 i = 0;
00054 while(tdb.nextTransactionBIS(transaction))
00055 {
00056 for(it_transaction = transaction.begin(); it_transaction != transaction.end(); ++it_transaction) {
00057 int item = *it_transaction;
00058 iti->push_back(item, i);
00059 }
00060 i++;
00061 }
00062
00063 delete[] itemFrequencies;
00064
00065 return iti;
00066 }
00067
00068
00069 #endif