Skip to content

Commit

Permalink
Issue #48: Renames for PostgreSQL 10 and 11 in rbtree structures and …
Browse files Browse the repository at this point in the history
…functions
  • Loading branch information
za-arthur committed Nov 9, 2018
1 parent 4ed27db commit 7f025c9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
6 changes: 5 additions & 1 deletion src/rum.h
Original file line number Diff line number Diff line change
Expand Up @@ -773,9 +773,13 @@ extern IndexBulkDeleteResult *rumvacuumcleanup(IndexVacuumInfo *info,
extern bool rumvalidate(Oid opclassoid);

/* rumbulk.c */
#if PG_VERSION_NUM < 100000
#define RBTNode RBNode
#endif

typedef struct RumEntryAccumulator
{
RBNode rbnode;
RBTNode rbnode;
Datum key;
RumNullCategory category;
OffsetNumber attnum;
Expand Down
40 changes: 24 additions & 16 deletions src/rumbulk.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@
#define DEF_NENTRY 2048 /* RumEntryAccumulator allocation quantum */
#define DEF_NPTR 5 /* ItemPointer initial allocation quantum */

/* PostgreSQL pre 10 has different names for this functions */
#if PG_VERSION_NUM < 100000
#define rbt_create(node_size, comparator, combiner, allocfunc, freefunc, arg) \
(rb_create(node_size, comparator, combiner, allocfunc, freefunc, arg))
#define rbt_insert(rbt, data, isNew) \
(rb_insert(rbt, data, isNew))
#endif


/* Combiner function for rbtree.c */
static void
rumCombineData(RBNode *existing, const RBNode *newdata, void *arg)
rumCombineData(RBTNode *existing, const RBTNode *newdata, void *arg)
{
RumEntryAccumulator *eo = (RumEntryAccumulator *) existing;
const RumEntryAccumulator *en = (const RumEntryAccumulator *) newdata;
Expand Down Expand Up @@ -65,7 +73,7 @@ rumCombineData(RBNode *existing, const RBNode *newdata, void *arg)

/* Comparator function for rbtree.c */
static int
cmpEntryAccumulator(const RBNode *a, const RBNode *b, void *arg)
cmpEntryAccumulator(const RBTNode *a, const RBTNode *b, void *arg)
{
const RumEntryAccumulator *ea = (const RumEntryAccumulator *) a;
const RumEntryAccumulator *eb = (const RumEntryAccumulator *) b;
Expand All @@ -77,15 +85,15 @@ cmpEntryAccumulator(const RBNode *a, const RBNode *b, void *arg)
}

/* Allocator function for rbtree.c */
static RBNode *
static RBTNode *
rumAllocEntryAccumulator(void *arg)
{
BuildAccumulator *accum = (BuildAccumulator *) arg;
RumEntryAccumulator *ea;

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

/* Allocate new RBNode from current chunk */
/* Allocate new RBTNode from current chunk */
ea = accum->entryallocator + accum->eas_used;
accum->eas_used++;

return (RBNode *) ea;
return (RBTNode *) ea;
}

void
Expand All @@ -108,12 +116,12 @@ rumInitBA(BuildAccumulator *accum)
accum->allocatedMemory = 0;
accum->entryallocator = NULL;
accum->eas_used = 0;
accum->tree = rb_create(sizeof(RumEntryAccumulator),
cmpEntryAccumulator,
rumCombineData,
rumAllocEntryAccumulator,
NULL, /* no freefunc needed */
(void *) accum);
accum->tree = rbt_create(sizeof(RumEntryAccumulator),
cmpEntryAccumulator,
rumCombineData,
rumAllocEntryAccumulator,
NULL, /* no freefunc needed */
(void *) accum);
}

/*
Expand Down Expand Up @@ -163,8 +171,8 @@ rumInsertBAEntry(BuildAccumulator *accum,
item.addInfo = addInfo;
item.addInfoIsNull = addInfoIsNull;

ea = (RumEntryAccumulator *) rb_insert(accum->tree, (RBNode *) &eatmp,
&isNew);
ea = (RumEntryAccumulator *) rbt_insert(accum->tree, (RBTNode *) &eatmp,
&isNew);

if (isNew)
{
Expand Down Expand Up @@ -273,7 +281,7 @@ void
rumBeginBAScan(BuildAccumulator *accum)
{
#if PG_VERSION_NUM >= 100000
rb_begin_iterate(accum->tree, LeftRightWalk, &accum->tree_walk);
rbt_begin_iterate(accum->tree, LeftRightWalk, &accum->tree_walk);
#else
rb_begin_iterate(accum->tree, LeftRightWalk);
#endif
Expand All @@ -293,7 +301,7 @@ rumGetBAEntry(BuildAccumulator *accum,
RumItem *list;

#if PG_VERSION_NUM >= 100000
entry = (RumEntryAccumulator *) rb_iterate(&accum->tree_walk);
entry = (RumEntryAccumulator *) rbt_iterate(&accum->tree_walk);
#else
entry = (RumEntryAccumulator *) rb_iterate(accum->tree);
#endif
Expand Down

0 comments on commit 7f025c9

Please sign in to comment.