//////////////////////////////////////////////////////////////////////
// ec_storage.h: definitons of the ec_storage class.
//
//////////////////////////////////////////////////////////////////////
#include "hash_table.h"
//#include "key_map.h"
#include "tree.h"
//#include "negborder.h"

#ifndef EC_STORAGE_H
#define EC_STORAGE_H

struct KeyHashNode; //note
struct CloseHashNode; //note
class FK_tree;
//class Knode;
class GK_node;

class ec_storage
{
private:
	closeHashTable* closeHash;
	keyHashTable* keyHash;
	GloK_tree *gKeyTree;

	//for updating
	int updateKeyWithTransaction(int* t, int length); //update invovled keys with one incremental transaction

	int updateKeyTree(int* t, int length, int pos, int support); //for a particular segment of the transaction

	int updateKeyNode(KeyHashNode* node, int count=1); //update the ec of the particular key

	int splitEC(KeyHashNode* keyNode, CloseHashNode* closeNode); //split up ecs

	bool compSetNBranch(CloseHashNode* closeNode); //store results in closeNode->diffSet n shareSet

	bool isSubset(int* iset, int ilen); //check whether the key is subset of the branch

	int updateNBGnode(GK_node* knode, KeyHashNode* hnode, int count=1); //update nbg node

	int enumNewKey(GK_node* knode, KeyHashNode* hnode, int*& closet, int& clen); //mine closed pattern of newly emerged nbg n extend e border

	int DecUpdateKeyWithTransaction(int* t, int length); //update invovled keys with one incremental transaction

	int DecUpdateKeyTree(int* t, int length, int pos, int support=1); //for a particular segment of the transaction

	int DecUpdateKeyNode(KeyHashNode* node, int count=1); //update the ec of a particular key or nbg

	
public:
	FK_tree* fkTree;

	ec_storage();
	~ec_storage();

	int init();

	int insertEC(int *&iCloseSet, int clen, int support, int *iKeySet, int iLen);
	int insertEC(int *&iCloseSet, int clen, int support, K_tree* ktree, int index);
	
	int insertKey(int *&iKeySet, int klen, int support, int cindex=-1);
	
	int insertNBG(int *&iKeySet, int klen, int support);
	//int insertNBG(GK_node*& previous, int*&iKeySet, int klen, int support, int cindex=-1);

	int outputEC(FSout *fout, double &closeNum, double &keyNum);
	int outputKey(FSout *fout, FSout* foutNGB, double &keyNum);
	int outputNGB(FSout *fout); //for debug

	int findEC(int* closeset, int len, int &support);
	int findEC(int* keyset, int klen);

	CloseHashNode* findECpt(int* closeset, int len, int &support);
	CloseHashNode* findECpt(int* keyset, int klen);

	int findKey(int* iset, int len, int &support);
	KeyHashNode* findKey(int* iset, int len);
	KeyHashNode* findKey(int index);

	int readOldEC(Data* fdat);

	int updateEC(Data* fdat); //incrmental update
	void expandNGB(); //support threshold adjustment update
	int DecUpdateEC(Data* fdat); //decremtnal update

};

#endif
