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

more TDB

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