提交 4be337db 编写于 作者: H Hongze Cheng

more

上级 0c487338
......@@ -17,8 +17,6 @@
#define BTREE_MAX_DEPTH 20
typedef int (*FKeyComparator)(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
struct SBTree {
SPgno root;
int keyLen;
......
......@@ -16,15 +16,24 @@
#include "tdbInt.h"
struct STDb {
STEnv *pEnv;
/* TODO */
STEnv * pEnv;
SBTree *pBt;
};
int tdbDbOpen(STDb **ppDb) {
STDb *pDb;
int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDb **ppDb) {
STDb * pDb;
SPFile *pFile;
*ppDb = NULL;
/* TODO */
pDb = (STDb *)calloc(1, sizeof(*pDb));
if (pDb == NULL) {
return -1;
}
pDb->pEnv = pEnv;
*ppDb = pDb;
return 0;
}
......
......@@ -22,10 +22,11 @@ struct STEnv {
};
int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv) {
STEnv * pEnv;
int dsize;
int zsize;
uint8_t *pPtr;
STEnv *pEnv;
int dsize;
int zsize;
u8 * pPtr;
int ret;
*ppEnv = NULL;
......@@ -45,7 +46,12 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv)
pEnv->jfd = -1;
tdbPCacheOpen(pageSize, cacheSize, 0, &(pEnv->pCache));
ret = tdbPCacheOpen(pageSize, cacheSize, 0, &(pEnv->pCache));
if (ret < 0) {
return -1;
}
mkdir(rootDir, 0755);
*ppEnv = pEnv;
return 0;
......
......@@ -22,7 +22,7 @@ extern "C" {
typedef struct STDb STDb;
int tdbDbOpen(STDb **ppDb);
int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDb **ppDb);
int tdbDbClose(STDb *pDb);
int tdbDbInsert(STDb *pDb, const void *pKey, int keyLen, const void *pVal, int valLen);
......
......@@ -121,6 +121,8 @@ typedef TD_DLIST_NODE(SPgFile) SPgFileListNode;
/* TODO */ \
} while (0)
typedef int (*FKeyComparator)(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
#define TDB_JOURNAL_NAME "tdb.journal"
#include "tdbUtil.h"
......
......@@ -5,14 +5,14 @@
TEST(tdb_test, simple_test) {
int ret;
STEnv *pEnv;
STDb *pDb;
STDb * pDb;
// Open Env
ret = tdbEnvOpen("tdb", 1024, 20, &pEnv);
GTEST_ASSERT_EQ(ret, 0);
// Create a database
ret = tdbDbOpen(&pDb);
ret = tdbDbOpen("db.db", TDB_VARIANT_LEN, TDB_VARIANT_LEN, NULL, pEnv, &pDb);
GTEST_ASSERT_EQ(ret, 0);
// Insert some data
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册