提交 8bd4beec 编写于 作者: H Hongze Cheng

refact

上级 3902294f
...@@ -117,23 +117,27 @@ static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen) { ...@@ -117,23 +117,27 @@ static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen) {
return -1; return -1;
} }
for (;;) { if (pCur->pPage->pHdr->nCells == 0) {
int lidx, ridx, midx, c; // Tree is empty
} else {
pBtPage = pCur->pPage; for (;;) {
lidx = 0; int lidx, ridx, midx, c;
ridx = pBtPage->pHdr->nCells - 1;
while (lidx <= ridx) { pBtPage = pCur->pPage;
midx = (lidx + ridx) >> 1; lidx = 0;
pCell = (void *)(pBtPage->aData + pBtPage->aCellIdx[midx]); ridx = pBtPage->pHdr->nCells - 1;
while (lidx <= ridx) {
c = tdbCompareKeyAndCell(pKey, kLen, pCell); midx = (lidx + ridx) >> 1;
if (c == 0) { pCell = (void *)(pBtPage->aData + pBtPage->aCellIdx[midx]);
break;
} else if (c < 0) { c = tdbCompareKeyAndCell(pKey, kLen, pCell);
lidx = lidx + 1; if (c == 0) {
} else { break;
ridx = ridx - 1; } 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 ...@@ -38,7 +38,7 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF
// pDb->pEnv // pDb->pEnv
pDb->pEnv = pEnv; pDb->pEnv = pEnv;
pFile = tdbEnvGetPFile(pEnv, fname); pFile = tdbEnvGetPager(pEnv, fname);
if (pFile == NULL) { if (pFile == NULL) {
snprintf(fFullName, TDB_FILENAME_LEN, "%s/%s", pEnv->rootDir, fname); snprintf(fFullName, TDB_FILENAME_LEN, "%s/%s", pEnv->rootDir, fname);
ret = tdbPagerOpen(pEnv->pCache, fFullName, &pFile); ret = tdbPagerOpen(pEnv->pCache, fFullName, &pFile);
......
...@@ -64,7 +64,7 @@ int tdbEnvClose(STEnv *pEnv) { ...@@ -64,7 +64,7 @@ int tdbEnvClose(STEnv *pEnv) {
return 0; return 0;
} }
SPager *tdbEnvGetPFile(STEnv *pEnv, const char *fname) { SPager *tdbEnvGetPager(STEnv *pEnv, const char *fname) {
// TODO // TODO
return NULL; return NULL;
} }
\ No newline at end of file
...@@ -30,7 +30,7 @@ typedef struct STEnv { ...@@ -30,7 +30,7 @@ typedef struct STEnv {
int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv); int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv);
int tdbEnvClose(STEnv *pEnv); int tdbEnvClose(STEnv *pEnv);
SPager *tdbEnvGetPFile(STEnv *pEnv, const char *fname); SPager *tdbEnvGetPager(STEnv *pEnv, const char *fname);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册