//////////////////////////////////////////////////////////////////////
// data.h: definitons of the data class to read in data.
//
//////////////////////////////////////////////////////////////////////
#ifndef _DATA_CLASS
#define _DATA_CLASS

#include <stdio.h>
#include <stdlib.h>

#define TransLen 50

class K_tree;
class FK_tree;

class tranStore
{
public:
	int* t;
	int length;
	tranStore* next;

	tranStore(int l):length(l) {t = new int[l], next = NULL;}
};


class Transaction
{
public:
	
	Transaction():maxlength(TransLen), length(0){ t = new int[maxlength];}
	void DoubleTrans(int item);				// if current item is greater than current longest transaction, we change the length of t as 2*item
	~Transaction(){delete []t;}
  
	int maxlength;
	int length;
	int *t;
};

class EquiClass
{
public:
	int* closeSet;
	int clen;
	int* key;
	int klen;

	EquiClass(int itemno):clen(0), klen(0) {closeSet = new int[itemno]; key = new int[itemno];}

	~EquiClass(){delete []closeSet; delete []key;}
};

class Data
{
 public:

	 tranStore* ts;
	
	Data(char *filename);
	~Data();
	int isOpen();
	void close(){if(in)fclose(in);}

	void removeTS();

	Transaction *getNextTransaction(Transaction* Trans, bool bltranStore = false);
	//Transaction *getNextEC(Transaction* Trans, int &support, int &index, K_tree *& ktree);
	EquiClass *getNextEC(EquiClass* ec, int &support, int &index, K_tree *& ktree);
	
	int readStat();
	int getGCtree(FK_tree*& globalTree); //read full gc-tree
	int readNGB();
	//void readIncDB(double threshold, FK_tree* globalTree); //read in incremetal db


 private:
  
	FILE *in;
	int getTree(FK_tree* globalTree); //construct full gc_tree

	int initOrder(int net_itemno); //2008
};

#endif


