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