⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 allocate.h

📁 使用C++编写的数据库管理系统; 拥有自定义数据文件格式
💻 H
字号:
Block * super;
Block * systemTableBlock;
Block  * bitMapNode;

unsigned long findEmpty()
{
	bitMapNode=super;
	unsigned long nextBlock;	
	unsigned long last=0;  
	unsigned char l=0;	
	for(int i=256;i<2044;i++)     //seek in superblock
	{
		unsigned char l=(unsigned char)(bitMapNode->read(1,i));
		if(l!=0xff)			
			return i;		
	}
	

	while(true){
		nextBlock=bitMapNode->read(4,2044);
		bitMapNode->load(nextBlock);
		last=last+2044;
		for(int i=0;i<2044;i++)
		{
			l=(unsigned char)(super->read(1,i));
			if(l!=0xff)   
				return i+last;
		}
	}
}

unsigned long allocateBlock()
{
	unsigned long result=0;
	unsigned long fileLength=super->read(4,0);
	
	unsigned char a=128;
	unsigned char bitMap;
	unsigned long bitLocation=findEmpty();
	if((bitLocation-256)*8>fileLength*0.9)
	{
		//increace file
		Block::writeEmpty(fileLength,(int)(fileLength*0.2));	
		super->write((int)(fileLength*1.2),4,0);
		
	}	
	bitMap=(unsigned char)bitMapNode->read(1,bitLocation%2044);  //set bit map
	int j=0;
	while(bitMap&a)
	{
		a=a>>1;
		j++;
	}
	bitMap=bitMap|a;
	bitMapNode->write(bitMap,1,bitLocation%2044);
	return (bitLocation-256)*8+j;
			
}


/*void revokeBlock(unsigned long n)
{
	unsigned long a,b;
	a=n/8+256;
	b=n%8;
	bitMap=(unsigned char)bitMapNode->read(1,bitLocation%2044);

}*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -