提交 a95d6690 编写于 作者: H Hongze Cheng

refact

上级 41bce71c
......@@ -19,7 +19,7 @@ struct SBTree {
SPgno root;
int keyLen;
int valLen;
SPager * pFile;
SPager * pPager;
FKeyComparator kcmpr;
};
......@@ -52,7 +52,7 @@ 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, SPager *pFile, FKeyComparator kcmpr, SBTree **ppBt) {
int tdbBtreeOpen(SPgno rtPgno, int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, SBTree **ppBt) {
SBTree *pBt;
*ppBt = NULL;
......@@ -68,8 +68,8 @@ int tdbBtreeOpen(SPgno rtPgno, int keyLen, int valLen, SPager *pFile, FKeyCompar
pBt->keyLen = keyLen;
// pBt->valLen
pBt->valLen = valLen;
// pBt->pFile
pBt->pFile = pFile;
// pBt->pPager
pBt->pPager = pPager;
// pBt->kcmpr
pBt->kcmpr = kcmpr ? kcmpr : tdbDefaultKeyCmprFn;
......@@ -93,7 +93,7 @@ int tdbBtreeCursor(SBtCursor *pCur, SBTree *pBt) {
int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *pVal, int vLen) {
int ret;
SPager * pFile;
SPager * pPager;
SBtPage *pPage;
ret = tdbBtCursorMoveTo(pCur, pKey, kLen);
......@@ -203,15 +203,15 @@ static int tdbEncodeLength(u8 *pBuf, uint len) {
static int tdbBtCursorMoveToRoot(SBtCursor *pCur) {
SBTree * pBt;
SPager * pFile;
SPager * pPager;
SPage * pPage;
SBtPage *pBtPage;
int ret;
pBt = pCur->pBt;
pFile = pBt->pFile;
pPager = pBt->pPager;
pPage = tdbPagerGet(pFile, pBt->root);
pPage = tdbPagerGet(pPager, pBt->root);
if (pPage == NULL) {
// TODO: handle error
}
......
......@@ -22,7 +22,7 @@ struct STDb {
int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDb **ppDb) {
STDb * pDb;
SPager *pFile;
SPager *pPager;
int ret;
char fFullName[TDB_FILENAME_LEN];
SPage * pPage;
......@@ -38,24 +38,24 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF
// pDb->pEnv
pDb->pEnv = pEnv;
pFile = tdbEnvGetPager(pEnv, fname);
if (pFile == NULL) {
pPager = tdbEnvGetPager(pEnv, fname);
if (pPager == NULL) {
snprintf(fFullName, TDB_FILENAME_LEN, "%s/%s", pEnv->rootDir, fname);
ret = tdbPagerOpen(pEnv->pCache, fFullName, &pFile);
ret = tdbPagerOpen(pEnv->pCache, fFullName, &pPager);
if (ret < 0) {
return -1;
}
}
ASSERT(pFile != NULL);
ASSERT(pPager != NULL);
ret = tdbPagerOpenDB(pFile, &pgno, true);
ret = tdbPagerOpenDB(pPager, &pgno, true);
if (ret < 0) {
return -1;
}
// pDb->pBt
ret = tdbBtreeOpen(pgno, keyLen, valLen, pFile, keyCmprFn, &(pDb->pBt));
ret = tdbBtreeOpen(pgno, keyLen, valLen, pPager, keyCmprFn, &(pDb->pBt));
if (ret < 0) {
return -1;
}
......@@ -75,9 +75,9 @@ int tdbDbDrop(STDb *pDb) {
}
int tdbDbInsert(STDb *pDb, const void *pKey, int keyLen, const void *pVal, int valLen) {
SBtCursor btc;
SBtCursor btc;
SBtCursor *pCur;
int ret;
int ret;
pCur = &btc;
ret = tdbBtreeCursor(pCur, pDb->pBt);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册