refact
This commit is contained in:
parent
3902294f01
commit
8bd4beec94
|
@ -117,23 +117,27 @@ static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
int lidx, ridx, midx, c;
|
||||
if (pCur->pPage->pHdr->nCells == 0) {
|
||||
// Tree is empty
|
||||
} else {
|
||||
for (;;) {
|
||||
int lidx, ridx, midx, c;
|
||||
|
||||
pBtPage = pCur->pPage;
|
||||
lidx = 0;
|
||||
ridx = pBtPage->pHdr->nCells - 1;
|
||||
while (lidx <= ridx) {
|
||||
midx = (lidx + ridx) >> 1;
|
||||
pCell = (void *)(pBtPage->aData + pBtPage->aCellIdx[midx]);
|
||||
pBtPage = pCur->pPage;
|
||||
lidx = 0;
|
||||
ridx = pBtPage->pHdr->nCells - 1;
|
||||
while (lidx <= ridx) {
|
||||
midx = (lidx + ridx) >> 1;
|
||||
pCell = (void *)(pBtPage->aData + pBtPage->aCellIdx[midx]);
|
||||
|
||||
c = tdbCompareKeyAndCell(pKey, kLen, pCell);
|
||||
if (c == 0) {
|
||||
break;
|
||||
} else if (c < 0) {
|
||||
lidx = lidx + 1;
|
||||
} else {
|
||||
ridx = ridx - 1;
|
||||
c = tdbCompareKeyAndCell(pKey, kLen, pCell);
|
||||
if (c == 0) {
|
||||
break;
|
||||
} else if (c < 0) {
|
||||
lidx = lidx + 1;
|
||||
} else {
|
||||
ridx = ridx - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF
|
|||
// pDb->pEnv
|
||||
pDb->pEnv = pEnv;
|
||||
|
||||
pFile = tdbEnvGetPFile(pEnv, fname);
|
||||
pFile = tdbEnvGetPager(pEnv, fname);
|
||||
if (pFile == NULL) {
|
||||
snprintf(fFullName, TDB_FILENAME_LEN, "%s/%s", pEnv->rootDir, fname);
|
||||
ret = tdbPagerOpen(pEnv->pCache, fFullName, &pFile);
|
||||
|
|
|
@ -64,7 +64,7 @@ int tdbEnvClose(STEnv *pEnv) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
SPager *tdbEnvGetPFile(STEnv *pEnv, const char *fname) {
|
||||
SPager *tdbEnvGetPager(STEnv *pEnv, const char *fname) {
|
||||
// TODO
|
||||
return NULL;
|
||||
}
|
|
@ -30,7 +30,7 @@ typedef struct STEnv {
|
|||
int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv);
|
||||
int tdbEnvClose(STEnv *pEnv);
|
||||
|
||||
SPager *tdbEnvGetPFile(STEnv *pEnv, const char *fname);
|
||||
SPager *tdbEnvGetPager(STEnv *pEnv, const char *fname);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue