提交 4383b3b5 编写于 作者: H Hongze Cheng

more TDB

上级 2aa6d7e3
...@@ -203,6 +203,34 @@ int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *p ...@@ -203,6 +203,34 @@ int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *p
return 0; return 0;
} }
int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen) {
SBtCursor btc;
SCell *pCell;
int cret;
SCellDecoder cd;
tdbBtreeCursor(&btc, pBt);
tdbBtCursorMoveTo(&btc, pKey, kLen, &cret);
if (cret) {
return cret;
}
pCell = tdbPageGetCell(btc.pPage, btc.idx);
tdbBtreeDecodeCell(btc.pPage, pCell, &cd);
*vLen = cd.vLen;
// TODO: here may have memory leak
*ppVal = realloc(*ppVal, *vLen);
if (*ppVal == NULL) {
return -1;
}
memcpy(*ppVal, cd.pVal, cd.vLen);
return 0;
}
static int tdbBtCursorMoveToChild(SBtCursor *pCur, SPgno pgno) { static int tdbBtCursorMoveToChild(SBtCursor *pCur, SPgno pgno) {
int ret; int ret;
......
...@@ -88,7 +88,6 @@ int tdbDbInsert(STDb *pDb, const void *pKey, int keyLen, const void *pVal, int v ...@@ -88,7 +88,6 @@ int tdbDbInsert(STDb *pDb, const void *pKey, int keyLen, const void *pVal, int v
return 0; return 0;
} }
int tdbDbGet(STDb *pDb, const void *pKey, int kLen, void *pVal, int *vLen) { int tdbDbGet(STDb *pDb, const void *pKey, int kLen, void **ppVal, int *vLen) {
// TODO return tdbBtreeGet(pDb->pBt, pKey, kLen, ppVal, vLen);
return 0;
} }
\ No newline at end of file
...@@ -37,6 +37,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pFile, FKeyComparator kcmpr, SB ...@@ -37,6 +37,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pFile, FKeyComparator kcmpr, SB
int tdbBtreeClose(SBTree *pBt); int tdbBtreeClose(SBTree *pBt);
int tdbBtreeCursor(SBtCursor *pCur, 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);
int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -26,7 +26,7 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF ...@@ -26,7 +26,7 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF
int tdbDbClose(STDb *pDb); int tdbDbClose(STDb *pDb);
int tdbDbDrop(STDb *pDb); 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);
int tdbDbGet(STDb *pDb, const void *pKey, int kLen, void *pVal, int *vLen); int tdbDbGet(STDb *pDb, const void *pKey, int kLen, void **ppVal, int *vLen);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -37,7 +37,7 @@ TEST(tdb_test, simple_test) { ...@@ -37,7 +37,7 @@ TEST(tdb_test, simple_test) {
sprintf(key, "key%d", i); sprintf(key, "key%d", i);
sprintf(val, "value%d", i); sprintf(val, "value%d", i);
ret = tdbDbGet(pDb, key, strlen(key), pVal, &vLen); ret = tdbDbGet(pDb, key, strlen(key), &pVal, &vLen);
GTEST_ASSERT_EQ(ret, 0); GTEST_ASSERT_EQ(ret, 0);
GTEST_ASSERT_EQ(vLen, strlen(val)); GTEST_ASSERT_EQ(vLen, strlen(val));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册