Skip to content

Commit 7f025c9

Browse files
committed
Issue #48: Renames for PostgreSQL 10 and 11 in rbtree structures and functions
1 parent 4ed27db commit 7f025c9

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

Diff for: src/rum.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -773,9 +773,13 @@ extern IndexBulkDeleteResult *rumvacuumcleanup(IndexVacuumInfo *info,
773773
extern bool rumvalidate(Oid opclassoid);
774774

775775
/* rumbulk.c */
776+
#if PG_VERSION_NUM < 100000
777+
#define RBTNode RBNode
778+
#endif
779+
776780
typedef struct RumEntryAccumulator
777781
{
778-
RBNode rbnode;
782+
RBTNode rbnode;
779783
Datum key;
780784
RumNullCategory category;
781785
OffsetNumber attnum;

Diff for: src/rumbulk.c

+24-16
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,18 @@
2121
#define DEF_NENTRY 2048 /* RumEntryAccumulator allocation quantum */
2222
#define DEF_NPTR 5 /* ItemPointer initial allocation quantum */
2323

24+
/* PostgreSQL pre 10 has different names for this functions */
25+
#if PG_VERSION_NUM < 100000
26+
#define rbt_create(node_size, comparator, combiner, allocfunc, freefunc, arg) \
27+
(rb_create(node_size, comparator, combiner, allocfunc, freefunc, arg))
28+
#define rbt_insert(rbt, data, isNew) \
29+
(rb_insert(rbt, data, isNew))
30+
#endif
31+
2432

2533
/* Combiner function for rbtree.c */
2634
static void
27-
rumCombineData(RBNode *existing, const RBNode *newdata, void *arg)
35+
rumCombineData(RBTNode *existing, const RBTNode *newdata, void *arg)
2836
{
2937
RumEntryAccumulator *eo = (RumEntryAccumulator *) existing;
3038
const RumEntryAccumulator *en = (const RumEntryAccumulator *) newdata;
@@ -65,7 +73,7 @@ rumCombineData(RBNode *existing, const RBNode *newdata, void *arg)
6573

6674
/* Comparator function for rbtree.c */
6775
static int
68-
cmpEntryAccumulator(const RBNode *a, const RBNode *b, void *arg)
76+
cmpEntryAccumulator(const RBTNode *a, const RBTNode *b, void *arg)
6977
{
7078
const RumEntryAccumulator *ea = (const RumEntryAccumulator *) a;
7179
const RumEntryAccumulator *eb = (const RumEntryAccumulator *) b;
@@ -77,15 +85,15 @@ cmpEntryAccumulator(const RBNode *a, const RBNode *b, void *arg)
7785
}
7886

7987
/* Allocator function for rbtree.c */
80-
static RBNode *
88+
static RBTNode *
8189
rumAllocEntryAccumulator(void *arg)
8290
{
8391
BuildAccumulator *accum = (BuildAccumulator *) arg;
8492
RumEntryAccumulator *ea;
8593

8694
/*
8795
* Allocate memory by rather big chunks to decrease overhead. We have no
88-
* need to reclaim RBNodes individually, so this costs nothing.
96+
* need to reclaim RBTNodes individually, so this costs nothing.
8997
*/
9098
if (accum->entryallocator == NULL || accum->eas_used >= DEF_NENTRY)
9199
{
@@ -94,11 +102,11 @@ rumAllocEntryAccumulator(void *arg)
94102
accum->eas_used = 0;
95103
}
96104

97-
/* Allocate new RBNode from current chunk */
105+
/* Allocate new RBTNode from current chunk */
98106
ea = accum->entryallocator + accum->eas_used;
99107
accum->eas_used++;
100108

101-
return (RBNode *) ea;
109+
return (RBTNode *) ea;
102110
}
103111

104112
void
@@ -108,12 +116,12 @@ rumInitBA(BuildAccumulator *accum)
108116
accum->allocatedMemory = 0;
109117
accum->entryallocator = NULL;
110118
accum->eas_used = 0;
111-
accum->tree = rb_create(sizeof(RumEntryAccumulator),
112-
cmpEntryAccumulator,
113-
rumCombineData,
114-
rumAllocEntryAccumulator,
115-
NULL, /* no freefunc needed */
116-
(void *) accum);
119+
accum->tree = rbt_create(sizeof(RumEntryAccumulator),
120+
cmpEntryAccumulator,
121+
rumCombineData,
122+
rumAllocEntryAccumulator,
123+
NULL, /* no freefunc needed */
124+
(void *) accum);
117125
}
118126

119127
/*
@@ -163,8 +171,8 @@ rumInsertBAEntry(BuildAccumulator *accum,
163171
item.addInfo = addInfo;
164172
item.addInfoIsNull = addInfoIsNull;
165173

166-
ea = (RumEntryAccumulator *) rb_insert(accum->tree, (RBNode *) &eatmp,
167-
&isNew);
174+
ea = (RumEntryAccumulator *) rbt_insert(accum->tree, (RBTNode *) &eatmp,
175+
&isNew);
168176

169177
if (isNew)
170178
{
@@ -273,7 +281,7 @@ void
273281
rumBeginBAScan(BuildAccumulator *accum)
274282
{
275283
#if PG_VERSION_NUM >= 100000
276-
rb_begin_iterate(accum->tree, LeftRightWalk, &accum->tree_walk);
284+
rbt_begin_iterate(accum->tree, LeftRightWalk, &accum->tree_walk);
277285
#else
278286
rb_begin_iterate(accum->tree, LeftRightWalk);
279287
#endif
@@ -293,7 +301,7 @@ rumGetBAEntry(BuildAccumulator *accum,
293301
RumItem *list;
294302

295303
#if PG_VERSION_NUM >= 100000
296-
entry = (RumEntryAccumulator *) rb_iterate(&accum->tree_walk);
304+
entry = (RumEntryAccumulator *) rbt_iterate(&accum->tree_walk);
297305
#else
298306
entry = (RumEntryAccumulator *) rb_iterate(accum->tree);
299307
#endif

0 commit comments

Comments
 (0)