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

more code

上级 ffa58120
...@@ -30,7 +30,7 @@ typedef int32_t (*tRBTreeCmprFn)(const void *, const void *); ...@@ -30,7 +30,7 @@ typedef int32_t (*tRBTreeCmprFn)(const void *, const void *);
// SRBTree ============================================= // SRBTree =============================================
#define tRBTreeCreate(compare) \ #define tRBTreeCreate(compare) \
(SRBTree) { .cmprFn = (compare), .rootNode = NULL, .minNode = NULL, .maxNode = NULL } (SRBTree) { .cmprFn = (compare), .root = NULL, .min = NULL, .max = NULL }
SRBTreeNode *tRBTreePut(SRBTree *pTree, SRBTreeNode *pNew); SRBTreeNode *tRBTreePut(SRBTree *pTree, SRBTreeNode *pNew);
void tRBTreeDrop(SRBTree *pTree, SRBTreeNode *pNode); void tRBTreeDrop(SRBTree *pTree, SRBTreeNode *pNode);
...@@ -39,7 +39,7 @@ SRBTreeNode *tRBTreeGet(SRBTree *pTree, void *pKey); ...@@ -39,7 +39,7 @@ SRBTreeNode *tRBTreeGet(SRBTree *pTree, void *pKey);
// SRBTreeIter ============================================= // SRBTreeIter =============================================
#define tRBTreeIterCreate(tree, ascend) \ #define tRBTreeIterCreate(tree, ascend) \
(SRBTreeIter) { .asc = (ascend), .pTree = (tree), .pNode = (ascend) ? (tree)->minNode : (tree)->maxNode } (SRBTreeIter) { .asc = (ascend), .pTree = (tree), .pNode = (ascend) ? (tree)->min : (tree)->max }
SRBTreeNode *tRBTreeIterNext(SRBTreeIter *pIter); SRBTreeNode *tRBTreeIterNext(SRBTreeIter *pIter);
...@@ -55,9 +55,9 @@ struct SRBTreeNode { ...@@ -55,9 +55,9 @@ struct SRBTreeNode {
struct SRBTree { struct SRBTree {
tRBTreeCmprFn cmprFn; tRBTreeCmprFn cmprFn;
SRBTreeNode *rootNode; SRBTreeNode *root;
SRBTreeNode *minNode; SRBTreeNode *min;
SRBTreeNode *maxNode; SRBTreeNode *max;
}; };
struct SRBTreeIter { struct SRBTreeIter {
......
...@@ -90,8 +90,8 @@ static int32_t tDataMergeNext(SDataMerger *pMerger, SRowInfo **ppInfo) { ...@@ -90,8 +90,8 @@ static int32_t tDataMergeNext(SDataMerger *pMerger, SRowInfo **ppInfo) {
} }
} }
if (pMerger->pNode && pMerger->rbt.minNode) { if (pMerger->pNode && pMerger->rbt.min) {
int32_t c = tRowInfoCmprFn(pMerger->pNode->payload, pMerger->rbt.minNode->payload); int32_t c = tRowInfoCmprFn(pMerger->pNode->payload, pMerger->rbt.min->payload);
if (c > 0) { if (c > 0) {
pMerger->pNode = tRBTreePut(&pMerger->rbt, pMerger->pNode); pMerger->pNode = tRBTreePut(&pMerger->rbt, pMerger->pNode);
ASSERT(pMerger->pNode); ASSERT(pMerger->pNode);
...@@ -103,7 +103,7 @@ static int32_t tDataMergeNext(SDataMerger *pMerger, SRowInfo **ppInfo) { ...@@ -103,7 +103,7 @@ static int32_t tDataMergeNext(SDataMerger *pMerger, SRowInfo **ppInfo) {
} }
if (pMerger->pNode == NULL) { if (pMerger->pNode == NULL) {
pMerger->pNode = pMerger->rbt.minNode; pMerger->pNode = pMerger->rbt.min;
if (pMerger->pNode) { if (pMerger->pNode) {
tRBTreeDrop(&pMerger->rbt, pMerger->pNode); tRBTreeDrop(&pMerger->rbt, pMerger->pNode);
} }
...@@ -128,6 +128,7 @@ typedef struct { ...@@ -128,6 +128,7 @@ typedef struct {
struct { struct {
SDataFReader *pReader; SDataFReader *pReader;
SArray *aBlockIdx; SArray *aBlockIdx;
SDataMerger merger;
SArray *aBlockL[TSDB_MAX_LAST_FILE]; SArray *aBlockL[TSDB_MAX_LAST_FILE];
} dReader; } dReader;
struct { struct {
...@@ -222,9 +223,16 @@ static int32_t tsdbMergeFileData(STsdbMerger *pMerger, SDFileSet *pSet) { ...@@ -222,9 +223,16 @@ static int32_t tsdbMergeFileData(STsdbMerger *pMerger, SDFileSet *pSet) {
if (code) goto _err; if (code) goto _err;
// impl // impl
SRowInfo rInfo = {.suid = INT64_MIN};
SRowInfo *pInfo;
while (true) { while (true) {
if (1) break; code = tDataMergeNext(&pMerger->dReader.merger, &pInfo);
// TODO if (code) goto _err;
if (pInfo == NULL) break;
ASSERT(tRowInfoCmprFn(pInfo, &rInfo) > 0);
rInfo = *pInfo;
} }
// end // end
......
...@@ -26,7 +26,7 @@ static void tRBTreeRotateLeft(SRBTree *pTree, SRBTreeNode *x) { ...@@ -26,7 +26,7 @@ static void tRBTreeRotateLeft(SRBTree *pTree, SRBTreeNode *x) {
} }
y->parent = x->parent; y->parent = x->parent;
if (x->parent == NULL) { if (x->parent == NULL) {
pTree->rootNode = y; pTree->root = y;
} else if (x == x->parent->left) { } else if (x == x->parent->left) {
x->parent->left = y; x->parent->left = y;
} else { } else {
...@@ -44,7 +44,7 @@ static void tRBTreeRotateRight(SRBTree *pTree, SRBTreeNode *x) { ...@@ -44,7 +44,7 @@ static void tRBTreeRotateRight(SRBTree *pTree, SRBTreeNode *x) {
} }
y->parent = x->parent; y->parent = x->parent;
if (x->parent == NULL) { if (x->parent == NULL) {
pTree->rootNode = y; pTree->root = y;
} else if (x == x->parent->left) { } else if (x == x->parent->left) {
x->parent->left = y; x->parent->left = y;
} else { } else {
...@@ -109,11 +109,11 @@ SRBTreeNode *tRBTreePut(SRBTree *pTree, SRBTreeNode *pNew) { ...@@ -109,11 +109,11 @@ SRBTreeNode *tRBTreePut(SRBTree *pTree, SRBTreeNode *pNew) {
pNew->color = RED; pNew->color = RED;
// insert // insert
if (pTree->rootNode == NULL) { if (pTree->root == NULL) {
pNew->parent = NULL; pNew->parent = NULL;
pTree->rootNode = pNew; pTree->root = pNew;
} else { } else {
SRBTreeNode *pNode = pTree->rootNode; SRBTreeNode *pNode = pTree->root;
while (true) { while (true) {
ASSERT(pNode); ASSERT(pNode);
...@@ -181,14 +181,14 @@ SRBTreeNode *tRBTreePut(SRBTree *pTree, SRBTreeNode *pNew) { ...@@ -181,14 +181,14 @@ SRBTreeNode *tRBTreePut(SRBTree *pTree, SRBTreeNode *pNew) {
} }
} }
} }
pTree->rootNode->color = BLACK; pTree->root->color = BLACK;
// update min/max node // update min/max node
if (pTree->minNode == NULL || pTree->cmprFn(pTree->minNode->payload, pNew->payload) > 0) { if (pTree->min == NULL || pTree->cmprFn(pTree->min->payload, pNew->payload) > 0) {
pTree->minNode = pNew; pTree->min = pNew;
} }
if (pTree->maxNode == NULL || pTree->cmprFn(pTree->maxNode->payload, pNew->payload) < 0) { if (pTree->max == NULL || pTree->cmprFn(pTree->max->payload, pNew->payload) < 0) {
pTree->maxNode = pNew; pTree->max = pNew;
} }
return pNew; return pNew;
...@@ -196,7 +196,7 @@ SRBTreeNode *tRBTreePut(SRBTree *pTree, SRBTreeNode *pNew) { ...@@ -196,7 +196,7 @@ SRBTreeNode *tRBTreePut(SRBTree *pTree, SRBTreeNode *pNew) {
static void tRBTreeTransplant(SRBTree *pTree, SRBTreeNode *u, SRBTreeNode *v) { static void tRBTreeTransplant(SRBTree *pTree, SRBTreeNode *u, SRBTreeNode *v) {
if (u->parent == NULL) { if (u->parent == NULL) {
pTree->rootNode = v; pTree->root = v;
} else if (u == u->parent->left) { } else if (u == u->parent->left) {
u->parent->left = v; u->parent->left = v;
} else { } else {
...@@ -208,7 +208,7 @@ static void tRBTreeTransplant(SRBTree *pTree, SRBTreeNode *u, SRBTreeNode *v) { ...@@ -208,7 +208,7 @@ static void tRBTreeTransplant(SRBTree *pTree, SRBTreeNode *u, SRBTreeNode *v) {
} }
static void tRBTreeDropFixup(SRBTree *t, SRBTreeNode *x) { static void tRBTreeDropFixup(SRBTree *t, SRBTreeNode *x) {
while (x != t->rootNode && x->color == BLACK) { while (x != t->root && x->color == BLACK) {
if (x == x->parent->left) { if (x == x->parent->left) {
SRBTreeNode *w = x->parent->right; SRBTreeNode *w = x->parent->right;
if (RBTREE_NODE_COLOR(w) == RED) { if (RBTREE_NODE_COLOR(w) == RED) {
...@@ -231,7 +231,7 @@ static void tRBTreeDropFixup(SRBTree *t, SRBTreeNode *x) { ...@@ -231,7 +231,7 @@ static void tRBTreeDropFixup(SRBTree *t, SRBTreeNode *x) {
x->parent->color = BLACK; x->parent->color = BLACK;
w->right->color = BLACK; w->right->color = BLACK;
tRBTreeRotateLeft(t, x->parent); tRBTreeRotateLeft(t, x->parent);
x = t->rootNode; x = t->root;
} }
} else { } else {
SRBTreeNode *w = x->parent->left; SRBTreeNode *w = x->parent->left;
...@@ -255,7 +255,7 @@ static void tRBTreeDropFixup(SRBTree *t, SRBTreeNode *x) { ...@@ -255,7 +255,7 @@ static void tRBTreeDropFixup(SRBTree *t, SRBTreeNode *x) {
x->parent->color = BLACK; x->parent->color = BLACK;
w->left->color = BLACK; w->left->color = BLACK;
tRBTreeRotateRight(t, x->parent); tRBTreeRotateRight(t, x->parent);
x = t->rootNode; x = t->root;
} }
} }
} }
...@@ -264,11 +264,11 @@ static void tRBTreeDropFixup(SRBTree *t, SRBTreeNode *x) { ...@@ -264,11 +264,11 @@ static void tRBTreeDropFixup(SRBTree *t, SRBTreeNode *x) {
void tRBTreeDrop(SRBTree *t, SRBTreeNode *z) { void tRBTreeDrop(SRBTree *t, SRBTreeNode *z) {
// update min/max node // update min/max node
if (t->minNode == z) { if (t->min == z) {
t->minNode = tRBTreeSuccessor(t->minNode); t->min = tRBTreeSuccessor(t->min);
} }
if (t->maxNode == z) { if (t->max == z) {
t->maxNode = tRBTreePredecessor(t->maxNode); t->max = tRBTreePredecessor(t->max);
} }
// drop impl // drop impl
...@@ -316,7 +316,7 @@ SRBTreeNode *tRBTreeDropByKey(SRBTree *pTree, void *pKey) { ...@@ -316,7 +316,7 @@ SRBTreeNode *tRBTreeDropByKey(SRBTree *pTree, void *pKey) {
} }
SRBTreeNode *tRBTreeGet(SRBTree *pTree, void *pKey) { SRBTreeNode *tRBTreeGet(SRBTree *pTree, void *pKey) {
SRBTreeNode *pNode = pTree->rootNode; SRBTreeNode *pNode = pTree->root;
while (pNode) { while (pNode) {
int32_t c = pTree->cmprFn(pKey, pNode->payload); int32_t c = pTree->cmprFn(pKey, pNode->payload);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册