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

more TDB

上级 98a1762a
......@@ -28,10 +28,13 @@ typedef struct {
// Btree page header definition
typedef struct __attribute__((__packed__)) {
uint8_t flags;
uint16_t ncells;
pgsz_t pldOffset; // payload offset
/* TODO */
uint8_t flag; // page flag
int32_t vlen; // value length of current page, TDB_VARIANT_LEN for variant length
uint16_t nPayloads; // number of total payloads
pgoff_t freeOff; // free payload offset
pgsz_t fragSize; // total fragment size
pgoff_t offPayload; // payload offset
pgno_t rChildPgno; // right most child page number
} SBtPgHdr;
typedef int (*BtreeCmprFn)(const void *, const void *);
......@@ -88,7 +91,7 @@ int btreeCursorMoveTo(SBtCursor *pBtCur, int kLen, const void *pKey) {
SPgFile * pPgFile;
pgno_t childPgno;
pgno_t rootPgno;
int nPayload;
int nPayloads;
void * pPayload;
BtreeCmprFn cmpFn;
......@@ -109,11 +112,11 @@ int btreeCursorMoveTo(SBtCursor *pBtCur, int kLen, const void *pKey) {
pPage = pBtCur->pPage;
pBtPgHdr = BTREE_PAGE_HDR(pPage);
nPayload = pBtPgHdr->ncells;
nPayloads = pBtPgHdr->nPayloads;
// Binary search the page
lidx = 0;
ridx = nPayload - 1;
ridx = nPayloads - 1;
midx = (lidx + ridx) >> 1;
for (;;) {
// get the payload ptr at midx
......
......@@ -70,6 +70,9 @@ typedef int32_t frame_id_t;
#define TDB_DEFAULT_PGSIZE 4096
#define TDB_IS_PGSIZE_VLD(s) (((s) >= TDB_MIN_PGSIZE) && ((s) <= TDB_MAX_PGSIZE))
// pgoff_t
typedef pgsz_t pgoff_t;
// cache
#define TDB_DEFAULT_CACHE_SIZE (256 * 1024) // 256K
......@@ -93,15 +96,17 @@ typedef TD_DLIST(SPgFile) SPgFileList;
} \
} while (0)
#define TDB_VARIANT_LEN -1
#define TDB_VARIANT_LEN (int32_t) - 1
// page payload format
// <keyLen> + <valLen> + [key] + [value]
#define TDB_DECODE_PAYLOAD(pPayload, keyLen, pKey, valLen, pVal) \
do { \
if ((keyLen) == TDB_VARIANT_LEN) { \
/* TODO */ \
/* TODO: decode the keyLen */ \
} \
if ((valLen) == TDB_VARIANT_LEN) { \
/* TODO */ \
/* TODO: decode the valLen */ \
} \
/* TODO */ \
} while (0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册