more TDB
This commit is contained in:
parent
9ffdf09986
commit
cc176b1037
|
@ -131,7 +131,7 @@ int tdbBtreeClose(SBTree *pBt) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int tdbBtreeCursor(SBTC *pCur, SBTree *pBt) {
|
||||
int tdbBtcOpen(SBTC *pCur, SBTree *pBt) {
|
||||
pCur->pBt = pBt;
|
||||
pCur->iPage = -1;
|
||||
pCur->pPage = NULL;
|
||||
|
@ -210,7 +210,7 @@ int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen
|
|||
void *pVal;
|
||||
SCellDecoder cd;
|
||||
|
||||
tdbBtreeCursor(&btc, pBt);
|
||||
tdbBtcOpen(&btc, pBt);
|
||||
|
||||
tdbBtCursorMoveTo(&btc, pKey, kLen, &cret);
|
||||
|
||||
|
@ -1072,3 +1072,28 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell) {
|
|||
}
|
||||
|
||||
#endif
|
||||
|
||||
int tdbBtcMoveToFirst(SBTC *pBtc) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbBtcMoveToLast(SBTC *pBtc) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbBtcClose(SBTC *pBtc) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
|
@ -20,6 +20,10 @@ struct STDB {
|
|||
SBTree *pBt;
|
||||
};
|
||||
|
||||
struct STDBC {
|
||||
SBTC btc;
|
||||
};
|
||||
|
||||
int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDB **ppDb) {
|
||||
STDB *pDb;
|
||||
SPager *pPager;
|
||||
|
@ -75,7 +79,7 @@ int tdbDbInsert(STDB *pDb, const void *pKey, int keyLen, const void *pVal, int v
|
|||
int ret;
|
||||
|
||||
pCur = &btc;
|
||||
ret = tdbBtreeCursor(pCur, pDb->pBt);
|
||||
ret = tdbBtcOpen(pCur, pDb->pBt);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -92,17 +96,38 @@ int tdbDbGet(STDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen) {
|
|||
return tdbBtreeGet(pDb->pBt, pKey, kLen, ppVal, vLen);
|
||||
}
|
||||
|
||||
int tdbDbcOpen(STDB *pDb, STDBC **ppTDbc) {
|
||||
// TODO
|
||||
int tdbDbcOpen(STDB *pDb, STDBC **ppDbc) {
|
||||
int ret;
|
||||
STDBC *pDbc = NULL;
|
||||
|
||||
*ppDbc = NULL;
|
||||
pDbc = malloc(sizeof(*pDbc));
|
||||
if (pDbc == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
tdbBtcOpen(&pDbc->btc, pDb->pBt);
|
||||
|
||||
// TODO: move to first now, we can move to any key-value
|
||||
// and in any direction, design new APIs.
|
||||
ret = tdbBtcMoveToFirst(&pDbc->btc);
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*ppDbc = pDbc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbDbNext(STDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
|
||||
// TODO
|
||||
return 0;
|
||||
return tdbBtreeNext(&pDbc->btc, ppKey, kLen, ppVal, vLen);
|
||||
}
|
||||
|
||||
int tdbDbcClose(STDBC *pDbc) {
|
||||
// TODO
|
||||
if (pDbc) {
|
||||
free(pDbc);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -38,12 +38,20 @@ struct SBTC {
|
|||
void *pBuf;
|
||||
};
|
||||
|
||||
// SBTree
|
||||
int tdbBtreeOpen(int keyLen, int valLen, SPager *pFile, FKeyComparator kcmpr, SBTree **ppBt);
|
||||
int tdbBtreeClose(SBTree *pBt);
|
||||
int tdbBtreeCursor(SBTC *pCur, SBTree *pBt);
|
||||
int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal, int vLen);
|
||||
int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen);
|
||||
|
||||
// SBTC
|
||||
int tdbBtcOpen(SBTC *pCur, SBTree *pBt);
|
||||
int tdbBtcMoveToFirst(SBTC *pBtc);
|
||||
int tdbBtcMoveToLast(SBTC *pBtc);
|
||||
int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen);
|
||||
int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen);
|
||||
int tdbBtcClose(SBTC *pBtc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -31,7 +31,7 @@ int tdbDbInsert(STDB *pDb, const void *pKey, int keyLen, const void *pVal, int v
|
|||
int tdbDbGet(STDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen);
|
||||
|
||||
// STDBC
|
||||
int tdbDbcOpen(STDB *pDb, STDBC **ppTDbc);
|
||||
int tdbDbcOpen(STDB *pDb, STDBC **ppDbc);
|
||||
int tdbDbNext(STDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen);
|
||||
int tdbDbcClose(STDBC *pDbc);
|
||||
|
||||
|
|
Loading…
Reference in New Issue