TDengine/source/util/test/trbtreeTest.cpp

40 lines
900 B
C++
Raw Normal View History

2022-08-24 14:34:11 +00:00
#include <gtest/gtest.h>
#include <stdio.h>
#include <stdlib.h>
#include "trbtree.h"
static int32_t tCmprInteger(const void *p1, const void *p2) {
if (*(int *)p1 < *(int *)p2) {
return -1;
} else if (*(int *)p1 > *(int *)p2) {
return 1;
}
return 0;
}
TEST(trbtreeTest, rbtree_test1) {
2022-09-02 08:37:40 +00:00
#if 0
2022-08-25 15:07:59 +00:00
SRBTree rt;
tRBTreeCreate(&rt, tCmprInteger);
int a[] = {1, 3, 4, 2, 7, 5, 8};
2022-08-24 14:34:11 +00:00
for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++) {
SRBTreeNode *pNode = (SRBTreeNode *)taosMemoryMalloc(sizeof(*pNode) + sizeof(int));
*(int *)pNode->payload = a[i];
tRBTreePut(&rt, pNode);
}
2022-08-25 02:43:13 +00:00
SRBTreeIter rti = tRBTreeIterCreate(&rt, 1);
2022-08-24 14:34:11 +00:00
SRBTreeNode *pNode = tRBTreeIterNext(&rti);
int la = 0;
while (pNode) {
GTEST_ASSERT_GT(*(int *)pNode->payload, la);
la = *(int *)pNode->payload;
2022-08-25 02:43:13 +00:00
// printf("%d\n", la);
2022-08-24 14:34:11 +00:00
pNode = tRBTreeIterNext(&rti);
}
2022-09-02 08:37:40 +00:00
#endif
2022-08-24 14:34:11 +00:00
}