pagemgr.cc

来自「为数据库创建索引的B+树的算法实现。功能包括创建删除节点、条目等。最终将树递归打」· CC 代码 · 共 44 行

CC
44
字号
#include "pagemgr.h"//------------------// Page Pool Manager//------------------int blocklength;		// size of a page blockint cachesize;	 		// max. number of page blockschar **cache;			// cache contvector<bool> isUsed;	// bitmap for used pagesint AvailBlockNum;		// # of avail blocksint getNumBlockAvail() {	return AvailBlockNum;}void InitPagePool(int csize,int blksize) {	//assert(csize>0);	assert(blksize>0);	cachesize=csize;	blocklength=blksize;	AvailBlockNum=csize;	cache = new char*[cachesize];	for (int i=0;i<cachesize;i++) cache[i] = new char[blocklength];	isUsed.assign(cachesize,false);}void DestroyPagePool() {	for (int i=0;i<cachesize;i++) delete[] cache[i];	delete[] cache;}char* GetNewBlock(int& BlockId) {	BlockId=-1;		for (int i=0;i<cachesize;i++)		if (!isUsed[i]) {			BlockId=i;			isUsed[BlockId]=true;	AvailBlockNum--;			return cache[BlockId];		}	return NULL;}void FreeBlock(int BlockId) {	if  (isUsed[BlockId]) { isUsed[BlockId]=false;	AvailBlockNum++; }		}

⌨️ 快捷键说明

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