more TDB
This commit is contained in:
parent
0c9eb0fbc6
commit
be09ef45f2
|
@ -736,19 +736,14 @@ static int tdbBtreeBalance(SBtCursor *pCur) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef TDB_BTREE_CELL
|
#ifndef TDB_BTREE_CELL // =========================================================
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* Data */
|
int kLen;
|
||||||
} SCellEncoder;
|
u8 *pKey;
|
||||||
|
int vLen;
|
||||||
typedef struct {
|
u8 *pVal;
|
||||||
int kLen;
|
SPgno pgno;
|
||||||
u8 *pKey;
|
u8 *pTmpSpace;
|
||||||
int vLen;
|
|
||||||
u8 *pVal;
|
|
||||||
u8 kOverflow;
|
|
||||||
u8 vOverflow;
|
|
||||||
u8 *pTmpSpace;
|
|
||||||
} SCellDecoder;
|
} SCellDecoder;
|
||||||
|
|
||||||
static int tdbBtreeEncodePayload(SPage *pPage, u8 *pPayload, void *pKey, int kLen, void *pVal, int vLen,
|
static int tdbBtreeEncodePayload(SPage *pPage, u8 *pPayload, void *pKey, int kLen, void *pVal, int vLen,
|
||||||
|
@ -830,43 +825,70 @@ 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;
|
||||||
|
|
||||||
// Decode kLen
|
ASSERT(pDecoder->pKey == NULL);
|
||||||
if (pPage->kLen != -1) {
|
|
||||||
pDecoder->vLen = pPage->kLen;
|
if (pDecoder->pVal) {
|
||||||
|
nPayload = pDecoder->kLen + pDecoder->vLen;
|
||||||
} 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);
|
||||||
}
|
|
||||||
|
|
||||||
flags = TDB_PAGE_FLAGS(pPage);
|
|
||||||
if (TDB_BTREE_PAGE_IS_LEAF(flags)) {
|
|
||||||
// For leaf page
|
|
||||||
// TODO
|
|
||||||
} else {
|
|
||||||
// For interior page
|
|
||||||
ASSERT(pDecoder->vLen == sizeof(SPgno));
|
|
||||||
|
|
||||||
pDecoder->pVal = pCell;
|
|
||||||
pDecoder->kOverflow = 0;
|
|
||||||
pCell = pCell + pPage->vLen;
|
|
||||||
|
|
||||||
pDecoder->pKey = pCell;
|
|
||||||
if (0) {
|
|
||||||
pDecoder->vOverflow = 1;
|
|
||||||
} else {
|
|
||||||
pDecoder->vOverflow = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// 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);
|
||||||
|
leaf = TDB_BTREE_PAGE_IS_LEAF(flags);
|
||||||
|
|
||||||
|
// 1. Decode header part
|
||||||
|
if (pPage->kLen == TDB_VARIANT_LEN) {
|
||||||
|
nHeader += tdbGetVarInt(pCell + nHeader, &(pDecoder->kLen));
|
||||||
|
} else {
|
||||||
|
pDecoder->kLen = pPage->kLen;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pPage->vLen == TDB_VARIANT_LEN) {
|
||||||
|
nHeader += tdbGetVarInt(pCell + nHeader, &(pDecoder->vLen));
|
||||||
|
} else {
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue