more TDB
This commit is contained in:
parent
c4dd34b190
commit
bc36f14e1d
|
@ -62,10 +62,30 @@ static int tdbEncodeLength(u8 *pBuf, uint len);
|
|||
static int tdbBtCursorMoveToRoot(SBtCursor *pCur);
|
||||
static int tdbInitBtPage(SPage *pPage, SBtPage **ppBtPage);
|
||||
static int tdbCompareKeyAndCell(const void *pKey, int kLen, const void *pCell);
|
||||
static int tdbDefaultKeyCmprFn(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2);
|
||||
|
||||
int tdbBtreeOpen(SPgno rtPgno, int keyLen, int valLen, SPFile *pFile, FKeyComparator kcmpr, SBTree **ppBt) {
|
||||
SBTree *pBt;
|
||||
|
||||
int tdbBtreeOpen(SBTree **ppBt) {
|
||||
*ppBt = NULL;
|
||||
/* TODO */
|
||||
|
||||
pBt = (SBTree *)calloc(1, sizeof(*pBt));
|
||||
if (pBt == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// pBt->root
|
||||
pBt->root = rtPgno;
|
||||
// pBt->keyLen
|
||||
pBt->keyLen = keyLen;
|
||||
// pBt->valLen
|
||||
pBt->valLen = valLen;
|
||||
// pBt->pFile
|
||||
pBt->pFile = pFile;
|
||||
// pBt->kcmpr
|
||||
pBt->kcmpr = kcmpr ? kcmpr : tdbDefaultKeyCmprFn;
|
||||
|
||||
*ppBt = pBt;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -230,4 +250,24 @@ static int tdbInitBtPage(SPage *pPage, SBtPage **ppBtPage) {
|
|||
static int tdbCompareKeyAndCell(const void *pKey, int kLen, const void *pCell) {
|
||||
/* TODO */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tdbDefaultKeyCmprFn(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2) {
|
||||
int mlen;
|
||||
int cret;
|
||||
|
||||
ASSERT(keyLen1 > 0 && keyLen2 > 0 && pKey1 != NULL && pKey2 != NULL);
|
||||
|
||||
mlen = keyLen1 < keyLen2 ? keyLen1 : keyLen2;
|
||||
cret = memcmp(pKey1, pKey2, mlen);
|
||||
if (cret == 0) {
|
||||
if (keyLen1 < keyLen2) {
|
||||
cret = -1;
|
||||
} else if (keyLen1 > keyLen2) {
|
||||
cret = 1;
|
||||
} else {
|
||||
cret = 0;
|
||||
}
|
||||
}
|
||||
return cret;
|
||||
}
|
|
@ -60,10 +60,12 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF
|
|||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
// pDb->pBt
|
||||
ret = tdbBtreeOpen(&(pDb->pBt));
|
||||
ret = tdbBtreeOpen(pgno, keyLen, valLen, pFile, keyCmprFn, &(pDb->pBt));
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -252,23 +254,4 @@ int tdbInsert(TDB *pDb, const void *pKey, int nKey, const void *pData, int nData
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tdbDefaultKeyCmprFn(int keyLen1, const void *pKey1, int keyLen2, const void *pKey2) {
|
||||
int mlen;
|
||||
int cret;
|
||||
|
||||
ASSERT(keyLen1 > 0 && keyLen2 > 0 && pKey1 != NULL && pKey2 != NULL);
|
||||
|
||||
mlen = keyLen1 < keyLen2 ? keyLen1 : keyLen2;
|
||||
cret = memcmp(pKey1, pKey2, mlen);
|
||||
if (cret == 0) {
|
||||
if (keyLen1 < keyLen2) {
|
||||
cret = -1;
|
||||
} else if (keyLen1 > keyLen2) {
|
||||
cret = 1;
|
||||
} else {
|
||||
cret = 0;
|
||||
}
|
||||
}
|
||||
return cret;
|
||||
}
|
||||
#endif
|
|
@ -34,6 +34,7 @@ int tdbPFileOpen(SPCache *pCache, const char *fileName, SPFile **ppFile) {
|
|||
SPFile * pFile;
|
||||
int fsize;
|
||||
int zsize;
|
||||
int ret;
|
||||
|
||||
*ppFile = NULL;
|
||||
|
||||
|
@ -66,6 +67,11 @@ int tdbPFileOpen(SPCache *pCache, const char *fileName, SPFile **ppFile) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
ret = tdbGnrtFileID(pFile->dbFileName, pFile->fid, false);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
pFile->jfd = -1;
|
||||
|
||||
*ppFile = pFile;
|
||||
|
|
|
@ -23,7 +23,7 @@ extern "C" {
|
|||
typedef struct SBTree SBTree;
|
||||
typedef struct SBtCursor SBtCursor;
|
||||
|
||||
int tdbBtreeOpen(SBTree **ppBt);
|
||||
int tdbBtreeOpen(SPgno rtPgno, int keyLen, int valLen, SPFile *pFile, FKeyComparator kcmpr, SBTree **ppBt);
|
||||
int tdbBtreeClose(SBTree *pBt);
|
||||
int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *pVal, int vLen);
|
||||
|
||||
|
|
|
@ -131,12 +131,12 @@ typedef int (*FKeyComparator)(const void *pKey1, int kLen1, const void *pKey2, i
|
|||
|
||||
#include "tdbUtil.h"
|
||||
|
||||
#include "tdbBtree.h"
|
||||
|
||||
#include "tdbPCache.h"
|
||||
|
||||
#include "tdbPFile.h"
|
||||
|
||||
#include "tdbBtree.h"
|
||||
|
||||
#include "tdbEnv.h"
|
||||
|
||||
#include "tdbDb.h"
|
||||
|
|
Loading…
Reference in New Issue