more TDB
This commit is contained in:
parent
afe0f1b6e0
commit
628c989ee9
|
@ -15,8 +15,6 @@
|
|||
|
||||
#include "tdbInt.h"
|
||||
|
||||
#define BTREE_MAX_DEPTH 20
|
||||
|
||||
struct SBTree {
|
||||
SPgno root;
|
||||
int keyLen;
|
||||
|
@ -36,20 +34,10 @@ typedef struct SPgHdr {
|
|||
SPgno rightChild;
|
||||
} SPgHdr;
|
||||
|
||||
typedef struct SBtPage {
|
||||
struct SBtPage {
|
||||
SPgHdr *pHdr;
|
||||
u16 * aCellIdx;
|
||||
u8 * aData;
|
||||
} SBtPage;
|
||||
|
||||
struct SBtCursor {
|
||||
SBTree * pBt;
|
||||
i8 iPage;
|
||||
SBtPage *pPage;
|
||||
u16 idx;
|
||||
u16 idxStack[BTREE_MAX_DEPTH + 1];
|
||||
SBtPage *pgStack[BTREE_MAX_DEPTH + 1];
|
||||
void * pBuf;
|
||||
};
|
||||
|
||||
typedef struct SFreeCell {
|
||||
|
|
|
@ -75,6 +75,20 @@ int tdbDbDrop(STDb *pDb) {
|
|||
}
|
||||
|
||||
int tdbDbInsert(STDb *pDb, const void *pKey, int keyLen, const void *pVal, int valLen) {
|
||||
// TODO
|
||||
SBtCursor btc;
|
||||
SBtCursor *pCur;
|
||||
int ret;
|
||||
|
||||
pCur = &btc;
|
||||
ret = tdbBtreeCursor(pCur, pDb->pBt);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = tdbBtCursorInsert(pCur, pKey, keyLen, pVal, valLen);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -22,9 +22,21 @@ extern "C" {
|
|||
|
||||
typedef struct SBTree SBTree;
|
||||
typedef struct SBtCursor SBtCursor;
|
||||
typedef struct SBtPage SBtPage;
|
||||
|
||||
struct SBtCursor {
|
||||
SBTree * pBt;
|
||||
i8 iPage;
|
||||
SBtPage *pPage;
|
||||
u16 idx;
|
||||
u16 idxStack[BTREE_MAX_DEPTH + 1];
|
||||
SBtPage *pgStack[BTREE_MAX_DEPTH + 1];
|
||||
void * pBuf;
|
||||
};
|
||||
|
||||
int tdbBtreeOpen(SPgno rtPgno, int keyLen, int valLen, SPFile *pFile, FKeyComparator kcmpr, SBTree **ppBt);
|
||||
int tdbBtreeClose(SBTree *pBt);
|
||||
int tdbBtreeCursor(SBtCursor *pCur, SBTree *pBt);
|
||||
int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *pVal, int vLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -129,6 +129,8 @@ typedef int (*FKeyComparator)(const void *pKey1, int kLen1, const void *pKey2, i
|
|||
|
||||
#define TDB_DEFAULT_FANOUT 6
|
||||
|
||||
#define BTREE_MAX_DEPTH 20
|
||||
|
||||
#include "tdbUtil.h"
|
||||
|
||||
#include "tdbPCache.h"
|
||||
|
|
|
@ -16,13 +16,11 @@ TEST(tdb_test, simple_test) {
|
|||
GTEST_ASSERT_EQ(ret, 0);
|
||||
|
||||
// // Insert some data
|
||||
// ret = tdbDbInsert(pDb, "1", 1, "world", 5);
|
||||
// GTEST_ASSERT_EQ(ret, 0);
|
||||
ret = tdbDbInsert(pDb, "1", 1, "world", 5);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
|
||||
ret = tdbDbDrop(pDb);
|
||||
if (pDb == NULL) {
|
||||
return -1;
|
||||
}
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
|
||||
// Close a database
|
||||
tdbDbClose(pDb);
|
||||
|
|
Loading…
Reference in New Issue