/*
*	go to the next header
*/
bool FileIO::GotoHeader(char* header)
{
	//check for errors
	if ((this->mFileHandle == NULL) || (!header))
		return false;

	bool found = false;
	long headerSize = strlen(header);
	char* currentHeader = new char[headerSize];

	for(;;)
	{
		//go to a byte
		if (Mode() == RECORD_MODE)
		{
			//goto next unit
			if (!GotoNext())
				break;	//if there is no further unit
		}

		//reset current header
		memset(currentHeader, 0, headerSize);

		//there is a byte, find the correct bytes (header)
		for(;;)
		{
			//continue search if in BYTE_MODE and there is something to read
			if ((Mode() == RECORD_MODE) ||
				(EndOfFile()))
				break;

			//append one byte to the back of the current header
			for (int c=0; c<headerSize - 1; c++)
				currentHeader[c] = currentHeader[c+1];
			currentHeader[headerSize - 1] = PopByte();

			//continue search if the current header is not full or
			//	it's full but doesn't match the right header
			if (!currentHeader[0] || memcmp(currentHeader, header, headerSize))
				continue;
			else
			{
				found = true;
				break;
			}
		}

		//called break above -> check if found or finished by EOF
		if (found || EndOfFile())
			break;
	}

	//clean up memory
	if (currentHeader)
		delete currentHeader;

	//found header?
	return found;
}
Exemple #2
0
//后继节点
PBTNODE GotoNext(PBTNODE pNode)
{
	PBTNODE resNode;
	if(pNode->right!=NULL)
		return GotoNext(pNode->right);
	resNode = pNode->farther ;
    while((resNode!=NULL)&&(pNode==resNode->right) ){
		pNode=resNode;
		resNode=resNode->farther;
	}
	return resNode;
}
Exemple #3
0
__int64 Extract(PBTNODE pNode)
{
	__int64 res = 0;
	CList<PBTNODE,PBTNODE&> pNL;
	GetLeafList(pNode, pNL);

	__int64 ir = pNL.GetCount();	//底数
	POSITION pos = pNL.GetHeadPosition();
	while(pos){
		PBTNODE c = pNL.GetNext(pos);
		PBTNODE n = GotoNext(c);
		DWORD lv = n==NULL?0:n->dwLevel;
		res += pow(ir,lv)*c->dwPre;
	}
	res += 62;
	return res;
}