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

more TDB

上级 0c9eb0fb
...@@ -736,18 +736,13 @@ static int tdbBtreeBalance(SBtCursor *pCur) { ...@@ -736,18 +736,13 @@ static int tdbBtreeBalance(SBtCursor *pCur) {
} }
#endif #endif
#ifndef TDB_BTREE_CELL #ifndef TDB_BTREE_CELL // =========================================================
typedef struct {
/* Data */
} SCellEncoder;
typedef struct { typedef struct {
int kLen; int kLen;
u8 *pKey; u8 *pKey;
int vLen; int vLen;
u8 *pVal; u8 *pVal;
u8 kOverflow; SPgno pgno;
u8 vOverflow;
u8 *pTmpSpace; u8 *pTmpSpace;
} SCellDecoder; } SCellDecoder;
...@@ -830,41 +825,68 @@ static int tdbBtreeEncodeCell(SPage *pPage, void *pKey, int kLen, void *pVal, in ...@@ -830,41 +825,68 @@ static int tdbBtreeEncodeCell(SPage *pPage, void *pKey, int kLen, void *pVal, in
return 0; return 0;
} }
static int tdbBtreeDecodeCell(SPage *pPage, SCell *pCell, SCellDecoder *pDecoder) { static int tdbBtreeDecodePayload(SPage *pPage, const u8 *pPayload, SCellDecoder *pDecoder) {
u16 flags; int nPayload;
ASSERT(pDecoder->pKey == NULL);
// Decode kLen if (pDecoder->pVal) {
if (pPage->kLen != -1) { nPayload = pDecoder->kLen + pDecoder->vLen;
pDecoder->vLen = pPage->kLen;
} else { } else {
pCell += tdbGetVarInt(pCell, &pDecoder->kLen); nPayload = pDecoder->kLen;
} }
// Decode vLen if (nPayload <= pPage->maxLocal) {
if (pPage->vLen != -1) { // General case without overflow
pDecoder->vLen = pPage->vLen; pDecoder->pKey = (void *)pPayload;
} else { if (pDecoder->pVal) {
pCell += tdbGetVarInt(pCell, &(pDecoder->vLen)); pDecoder->pVal = (void *)(pPayload + pDecoder->vLen);
}
} }
{
// TODO: handle overflow case
ASSERT(0);
}
return 0;
}
static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder) {
u16 flags;
u8 leaf;
int nHeader;
int ret;
nHeader = 0;
flags = TDB_PAGE_FLAGS(pPage); flags = TDB_PAGE_FLAGS(pPage);
if (TDB_BTREE_PAGE_IS_LEAF(flags)) { leaf = TDB_BTREE_PAGE_IS_LEAF(flags);
// For leaf page
// TODO
} else {
// For interior page
ASSERT(pDecoder->vLen == sizeof(SPgno));
pDecoder->pVal = pCell; // 1. Decode header part
pDecoder->kOverflow = 0; if (pPage->kLen == TDB_VARIANT_LEN) {
pCell = pCell + pPage->vLen; nHeader += tdbGetVarInt(pCell + nHeader, &(pDecoder->kLen));
} else {
pDecoder->kLen = pPage->kLen;
}
pDecoder->pKey = pCell; if (pPage->vLen == TDB_VARIANT_LEN) {
if (0) { nHeader += tdbGetVarInt(pCell + nHeader, &(pDecoder->vLen));
pDecoder->vOverflow = 1;
} else { } else {
pDecoder->vOverflow = 0; pDecoder->vLen = pPage->vLen;
}
if (!leaf) {
ASSERT(pPage->vLen == sizeof(SPgno));
pDecoder->pgno = ((SPgno *)(pCell + nHeader))[0];
pDecoder->pVal = (u8 *)(&(pDecoder->pgno));
nHeader = nHeader + sizeof(SPgno);
} }
// 2. Decode payload part
ret = tdbBtreeDecodePayload(pPage, pCell + nHeader, pDecoder);
if (ret < 0) {
return -1;
} }
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册