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

📄 gistdb.cpp

📁 FastDb是高效的内存数据库系统
💻 CPP
字号:
// -*- Mode: C++ -*-////          GiSTdb.cpp#include "GiSTdb.h"#include "GiSTpath.h"REGISTER(GiSTtable);GiSTdb::GiSTdb(dbDatabase& aDB) : GiSTstore(), db(aDB) {    query = "name=",&tableName;    rootPageId = 0;}void GiSTdb::Create(const char *tableName){    if (IsOpen()) { 	return;    }    dbCursor<GiSTtable> cursor;    this->tableName = tableName;    SetOpen(1);    if (cursor.select(query) == 0) { 	GiSTtable table;	table.name = tableName;	rootPageId = Allocate();	table.rootPageId = rootPageId;	insert(table);    } else { 	rootPageId = cursor->rootPageId;    }}void GiSTdb::Open(const char *tableName){    dbCursor<GiSTtable> cursor;    this->tableName = tableName;    if (cursor.select(query) != 0) { 	rootPageId = cursor->rootPageId;	SetOpen(1);    }}void GiSTdb::Close(){    if (!IsOpen()) { 	return;    }    SetOpen(0);}void GiSTdb::Read(GiSTpage page, char *buf){    if (IsOpen()) {	if (page == GiSTRootPage) { 	    page = rootPageId;	}	memcpy(buf, db.get(page), dbPageSize);    }}void GiSTdb::Write(GiSTpage page, const char *buf){    if (IsOpen()) {	if (page == GiSTRootPage) { 	    page = rootPageId;	}	memcpy(db.put(page), buf, dbPageSize);    }}GiSTpage GiSTdb::Allocate(){    if (!IsOpen()) { 	return 0;    }    oid_t page = db.allocateObject(dbPageObjectMarker);    byte* pg = db.get(page);    memset(pg, 0, dbPageSize);    return page;}void GiSTdb::Deallocate(GiSTpage page){    db.freeObject(page);}

⌨️ 快捷键说明

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