提交 c908f178 编写于 作者: H Hongze Cheng

more TDB

上级 90789973
......@@ -20,6 +20,9 @@
#define TDB_BTREE_PAGE_IS_ROOT(flags) TDB_FLAG_HAS(flags, TDB_BTREE_ROOT)
#define TDB_BTREE_PAGE_IS_LEAF(flags) TDB_FLAG_HAS(flags, TDB_BTREE_LEAF)
#define TDB_BTREE_ASSERT_FLAG(flags) \
ASSERT(TDB_FLAG_IS(flags, TDB_BTREE_ROOT) || TDB_FLAG_IS(flags, TDB_BTREE_LEAF) || \
TDB_FLAG_IS(flags, TDB_BTREE_ROOT | TDB_BTREE_LEAF) || TDB_FLAG_IS(flags, 0))
struct SBTree {
SPgno root;
......@@ -315,11 +318,23 @@ static int tdbBtreeZeroPage(SPage *pPage, void *arg) {
// Init the page header
pPage->pPageHdr->flags = flags;
pPage->pPageHdr->nCells = 0;
pPage->pPageHdr->cellCont = 0;
pPage->pPageHdr->cellCont = pBt->pageSize;
pPage->pPageHdr->freeCell = 0;
pPage->pPageHdr->nFree = 0;
tdbBtreeInitPage(pPage, (void *)pBt);
TDB_BTREE_ASSERT_FLAG(flags);
if (TDB_BTREE_PAGE_IS_LEAF(pPage->pPageHdr->flags)) {
pPage->kLen = pBt->keyLen;
pPage->vLen = pBt->valLen;
pPage->maxLocal = pBt->maxLeaf;
pPage->minLocal = pBt->minLeaf;
} else {
pPage->kLen = pBt->keyLen;
pPage->vLen = sizeof(SPgno);
pPage->maxLocal = pBt->maxLocal;
pPage->minLocal = pBt->minLocal;
}
return 0;
}
......@@ -332,6 +347,8 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg) {
pPage->pPageHdr = (SPageHdr *)pPage->pData;
pPage->aCellIdx = (u16 *)(&(pPage->pPageHdr[1]));
TDB_BTREE_ASSERT_FLAG(pPage->pPageHdr->flags);
// Init other fields
if (TDB_BTREE_PAGE_IS_LEAF(pPage->pPageHdr->flags)) {
pPage->kLen = pBt->keyLen;
......
......@@ -128,6 +128,7 @@ typedef int (*FKeyComparator)(const void *pKey1, int kLen1, const void *pKey2, i
#define BTREE_MAX_DEPTH 20
#define TDB_FLAG_IS(flags, flag) ((flags) == (flag))
#define TDB_FLAG_HAS(flags, flag) (((flags) & (flag)) != 0)
#define TDB_FLAG_NO(flags, flag) ((flags) & (flag) == 0)
#define TDB_FLAG_ADD(flags, flag) ((flags) |= (flag))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册