This commit is contained in:
Hongze Cheng 2022-02-25 07:38:41 +00:00
parent b8e346a3f5
commit 7c7c0fb5f6
1 changed files with 54 additions and 6 deletions

View File

@ -17,12 +17,14 @@
#define BTREE_MAX_DEPTH 20 #define BTREE_MAX_DEPTH 20
typedef int (*FKeyComparator)(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
struct SBTree { struct SBTree {
SPgno root; SPgno root;
int keyLen; int keyLen;
int valLen; int valLen;
SPFile * pFile; SPFile * pFile;
int (*FKeyComparator)(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2); FKeyComparator kcmpr;
}; };
typedef struct SPgHdr { typedef struct SPgHdr {
@ -48,6 +50,8 @@ struct SBtCursor {
static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen); static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen);
static int tdbEncodeLength(u8 *pBuf, uint len); static int tdbEncodeLength(u8 *pBuf, uint len);
static int tdbBtCursorMoveToRoot(SBtCursor *pCur);
static int tdbInitBtPage(SPage *pPage, SBtPage **ppBtPage);
int tdbBtreeOpen(SPgno root, SBTree **ppBt) { int tdbBtreeOpen(SPgno root, SBTree **ppBt) {
*ppBt = NULL; *ppBt = NULL;
@ -88,6 +92,9 @@ int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *p
} }
static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen) { static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen) {
int ret;
ret = tdbBtCursorMoveToRoot(pCur);
// TODO // TODO
return 0; return 0;
} }
@ -120,7 +127,16 @@ static int tdbEncodeKeyValue(const void *pKey, int kLen, int kLenG, const void *
} }
static int tdbDecodeKeyValue(const void *pBuf, void *pKey, int *kLen, void *pVal, int *vLen) { static int tdbDecodeKeyValue(const void *pBuf, void *pKey, int *kLen, void *pVal, int *vLen) {
// TODO if (*kLen == TDB_VARIANT_LEN) {
// Decode the key length
}
if (*vLen == TDB_VARIANT_LEN) {
// Decode the value length
}
// TODO: decode the key and value
return 0; return 0;
} }
@ -136,3 +152,35 @@ static int tdbEncodeLength(u8 *pBuf, uint len) {
return iCount; return iCount;
} }
static int tdbBtCursorMoveToRoot(SBtCursor *pCur) {
SBTree * pBt;
SPFile * pFile;
SPage * pPage;
SBtPage *pBtPage;
int ret;
pBt = pCur->pBt;
pFile = pBt->pFile;
pPage = tdbPFileGet(pFile, pBt->root);
if (pPage == NULL) {
// TODO: handle error
}
ret = tdbInitBtPage(pPage, &pBtPage);
if (ret < 0) {
// TODO
return 0;
}
pCur->pPage = pBtPage;
pCur->iPage = 0;
return 0;
}
static int tdbInitBtPage(SPage *pPage, SBtPage **ppBtPage) {
// TODO
return 0;
}