//////////////////////////////////////////////////////////////////////
// fk_node.h: definitons of the fk_node class.
//
//////////////////////////////////////////////////////////////////////

#ifndef FK_NODE_H
#define FK_NODE_H

//#include "fp_node.h"
#include "common.h"

class FK_tree;

class FPnode{
public:
	int itemname;  //item name, by compact name

public:
//	FPnode(FPnode* par, int itemname, int count);
//	~Fnode();
};

class Knode : public FPnode{
public:
	Knode* par; //parent
	Knode* leftchild;
	Knode* rightsibling;
	Knode* next;  //node link
	int count;   //count of the path

	bool blmark; //a marker for local tree construction

	int *tailSet;  //the itemset occur in some transactions containing the prefix,
	               //can allocate from the heap
	int tailSize;  //the size of tailSet
	int tailSupport; //support for the tail;
	void addTail(int * & tailSet, int tailSize, int support);
   
public:
	~Knode();

	//void init(Knode* parent, int itemname, int count, int posCount); //initialize a node
	void init(Knode* parent, int itemname, int count);
   
	Knode* append(FK_tree* fptree, Knode* sib, int itemno, int counts); //append a node as the child, return the new child

	void detach(FK_tree* fptree, Knode* sib); //detach a node and its children from the tree
	void removeNodeFromHeader(FK_tree* fptree, int decCount); //remove a node from header link list

};   

bool Intersection(int * &dst, int & len1, int * src, int len2, bool reverse);
//intersection of the two sets.

bool Copy(int *dst, int &dstLen, int *src, int len);
//copy one set to another, space should be allocated first.

bool Insert(int *dstSet, int & dstLen, int item);
//Insert an item into a set, space should be allocated first

#endif
