From 1e8e6e32e4b26ca3fdbf2427e24ea239fac77861 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 30 Mar 2022 07:14:55 +0000 Subject: [PATCH] refact --- source/libs/tdb/src/db/tdbBtree.c | 27 +++++++++++++++++++++------ source/libs/tdb/src/inc/tdbBtree.h | 1 - 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 9b63849705..6c7f7e2471 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -1277,11 +1277,6 @@ static int tdbBtcMoveToNext(SBTC *pBtc) { return 0; } -int tdbBtcClose(SBTC *pBtc) { - // TODO - return 0; -} - static int tdbBtcMoveDownward(SBTC *pBtc, SPgno pgno) { int ret; @@ -1310,8 +1305,27 @@ static int tdbBtcMoveUpward(SBTC *pBtc) { return 0; } + +int tdbBtcClose(SBTC *pBtc) { + if (pBtc->iPage < 0) return 0; + + for (;;) { + ASSERT(pBtc->pPage); + + tdbPagerReturnPage(pBtc->pBt->pPager, pBtc->pPage); + + pBtc->iPage--; + if (pBtc->iPage < 0) break; + + pBtc->pPage = pBtc->pgStack[pBtc->iPage]; + pBtc->idx = pBtc->idxStack[pBtc->iPage]; + } + + return 0; +} // TDB_BTREE_CURSOR +// TDB_BTREE_DEBUG ===================== #ifndef NODEBUG typedef struct { SPgno pgno; @@ -1342,4 +1356,5 @@ void tdbBtPageInfo(SPage *pPage, int idx) { pBtPageInfo->nCells = TDB_PAGE_TOTAL_CELLS(pPage) - pPage->nOverflow; pBtPageInfo->nOvfl = pPage->nOverflow; } -#endif \ No newline at end of file +#endif +// TDB_BTREE_DEBUG \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbBtree.h b/source/libs/tdb/src/inc/tdbBtree.h index 0e8ca0c803..a320401a48 100644 --- a/source/libs/tdb/src/inc/tdbBtree.h +++ b/source/libs/tdb/src/inc/tdbBtree.h @@ -35,7 +35,6 @@ struct SBTC { int idx; int idxStack[BTREE_MAX_DEPTH + 1]; SPage *pgStack[BTREE_MAX_DEPTH + 1]; - void *pBuf; }; // SBTree -- GitLab