postgresql/src/include/lib/rbtree.h

80 lines
2.5 KiB
C
Raw Normal View History

/*-------------------------------------------------------------------------
*
* rbtree.h
2010-02-26 03:01:40 +01:00
* interface for PostgreSQL generic Red-Black binary tree package
*
* Copyright (c) 2009-2018, PostgreSQL Global Development Group
*
* IDENTIFICATION
* src/include/lib/rbtree.h
*
*-------------------------------------------------------------------------
*/
#ifndef RBTREE_H
#define RBTREE_H
/*
* RBNode is intended to be used as the first field of a larger struct,
* whose additional fields carry whatever payload data the caller needs
* for a tree entry. (The total size of that larger struct is passed to
2011-04-10 17:42:00 +02:00
* rb_create.) RBNode is declared here to support this usage, but
* callers must treat it as an opaque struct.
*/
typedef struct RBNode
{
2011-04-10 17:42:00 +02:00
char color; /* node's current color, red or black */
struct RBNode *left; /* left child, or RBNIL if none */
struct RBNode *right; /* right child, or RBNIL if none */
struct RBNode *parent; /* parent, or NULL (not RBNIL!) if none */
} RBNode;
/* Opaque struct representing a whole tree */
typedef struct RBTree RBTree;
/* Available tree iteration orderings */
typedef enum RBOrderControl
{
LeftRightWalk, /* inorder: left child, node, right child */
RightLeftWalk /* reverse inorder: right, node, left */
} RBOrderControl;
/*
* RBTreeIterator holds state while traversing a tree. This is declared
* here so that callers can stack-allocate this, but must otherwise be
* treated as an opaque struct.
*/
typedef struct RBTreeIterator RBTreeIterator;
struct RBTreeIterator
{
RBTree *rb;
RBNode *(*iterate) (RBTreeIterator *iter);
RBNode *last_visited;
bool is_over;
};
/* Support functions to be provided by caller */
typedef int (*rb_comparator) (const RBNode *a, const RBNode *b, void *arg);
typedef void (*rb_combiner) (RBNode *existing, const RBNode *newdata, void *arg);
typedef RBNode *(*rb_allocfunc) (void *arg);
typedef void (*rb_freefunc) (RBNode *x, void *arg);
extern RBTree *rb_create(Size node_size,
rb_comparator comparator,
rb_combiner combiner,
rb_allocfunc allocfunc,
2010-02-26 03:01:40 +01:00
rb_freefunc freefunc,
void *arg);
extern RBNode *rb_find(RBTree *rb, const RBNode *data);
extern RBNode *rb_leftmost(RBTree *rb);
extern RBNode *rb_insert(RBTree *rb, const RBNode *data, bool *isNew);
extern void rb_delete(RBTree *rb, RBNode *node);
extern void rb_begin_iterate(RBTree *rb, RBOrderControl ctrl,
RBTreeIterator *iter);
extern RBNode *rb_iterate(RBTreeIterator *iter);
Phase 2 of pgindent updates. Change pg_bsd_indent to follow upstream rules for placement of comments to the right of code, and remove pgindent hack that caused comments following #endif to not obey the general rule. Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using the published version of pg_bsd_indent, but a hacked-up version that tried to minimize the amount of movement of comments to the right of code. The situation of interest is where such a comment has to be moved to the right of its default placement at column 33 because there's code there. BSD indent has always moved right in units of tab stops in such cases --- but in the previous incarnation, indent was working in 8-space tab stops, while now it knows we use 4-space tabs. So the net result is that in about half the cases, such comments are placed one tab stop left of before. This is better all around: it leaves more room on the line for comment text, and it means that in such cases the comment uniformly starts at the next 4-space tab stop after the code, rather than sometimes one and sometimes two tabs after. Also, ensure that comments following #endif are indented the same as comments following other preprocessor commands such as #else. That inconsistency turns out to have been self-inflicted damage from a poorly-thought-through post-indent "fixup" in pgindent. This patch is much less interesting than the first round of indent changes, but also bulkier, so I thought it best to separate the effects. Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:18:54 +02:00
#endif /* RBTREE_H */