Commit d6f553ed authored by Yoni Fogel's avatar Yoni Fogel

Addresses #479

Modified tokuredblack to be more readable, support user malloc functions

git-svn-id: file:///svn/tokudb@2699 c7de825b-a66e-492c-adef-691d508d4ae1
parent 2950fda3
This diff is collapsed.
#include <rangetree.h>
// These are the redblack directives
/* rbgen generated code begins here */
/* rbgen: $Id: rbgen.in,v 1.3 2003/10/24 01:31:21 damo Exp $ */
#define toku_range toku_range
#define RB_INLINE
/* /*
* RCS $Id: redblack.h,v 1.9 2003/10/24 01:31:21 damo Exp $ * RCS $Id: redblack.h,v 1.9 2003/10/24 01:31:21 damo Exp $
*/ */
...@@ -28,196 +35,79 @@ ...@@ -28,196 +35,79 @@
/* Stop multiple includes */ /* Stop multiple includes */
#ifndef _REDBLACK_H #ifndef _REDBLACK_H
#ifndef RB_CUSTOMIZE
/*
* Without customization, the data member in the tree nodes is a void
* pointer, and you need to pass in a comparison function to be
* applied at runtime. With customization, you specify the data type
* as the macro RB_ENTRY(data_t) (has to be a macro because compilers
* gag on typdef void) and the name of the compare function as the
* value of the macro RB_COMPARE. Because the comparison function is
* compiled in, RB_COMPARE only needs to take two arguments. If your
* content type is not a pointer, define INLINE to get direct access.
*/
#define rbdata_t void
#define RB_COMPARE(s, t, e) (*rbinfo->rb_cmp)(s, t, e)
#undef RB_INLINE
#define RB_ENTRY(name) rb##name
#else
//Not Customized
#define RB_COMPARE(s, t) (*rbinfo->rb_cmp)(s, t)
#endif /* RB_CUSTOMIZE */
#ifndef RB_STATIC
#define RB_STATIC
#endif
/* Modes for rblookup */ /* Modes for rblookup */
#define RB_NONE -1 /* None of those below */ typedef enum {
#define RB_LUEQUAL 0 /* Only exact match */ RB_NONE = -1, /* None of those below */
#define RB_LUGTEQ 1 /* Exact match or greater */ RB_LUEQUAL = 0, /* Only exact match */
#define RB_LULTEQ 2 /* Exact match or less */ RB_LUGTEQ = 1, /* Exact match or greater */
#define RB_LULESS 3 /* Less than key (not equal to) */ RB_LULTEQ = 2, /* Exact match or less */
#define RB_LUGREAT 4 /* Greater than key (not equal to) */ RB_LULESS = 3, /* Less than key (not equal to) */
#define RB_LUNEXT 5 /* Next key after current */ RB_LUGREAT = 4, /* Greater than key (not equal to) */
#define RB_LUPREV 6 /* Prev key before current */ RB_LUNEXT = 5, /* Next key after current */
#define RB_LUFIRST 7 /* First key in index */ RB_LUPREV = 6, /* Prev key before current */
#define RB_LULAST 8 /* Last key in index */ RB_LUFIRST = 7, /* First key in index */
RB_LULAST = 8 /* Last key in index */
/* For rbwalk - pinched from search.h */ } toku_rbt_look_mode;
typedef enum
{ struct toku_rbt_lists {
preorder, const struct toku_rbt_node *rootp;
postorder, const struct toku_rbt_node *nextp;
endorder,
leaf
}
VISIT;
struct RB_ENTRY(lists) {
const struct RB_ENTRY(node) *rootp;
const struct RB_ENTRY(node) *nextp;
}; };
#define RBLIST struct RB_ENTRY(lists) struct toku_rbt_tree {
int (*rb_cmp)(const toku_range*, const toku_range*);
struct RB_ENTRY(tree) { struct toku_rbt_node *rb_root;
#ifndef RB_CUSTOMIZE void* (*rb_malloc) (size_t);
/* comparison routine */ void (*rb_free) (void*);
int (*rb_cmp)(const void *, const void *, const void *); void* (*rb_realloc)(void*, size_t);
/* config data to be passed to rb_cmp */
const void *rb_config;
/* root of tree */
#else
int (*rb_cmp)(const RB_ENTRY(data_t)*, const RB_ENTRY(data_t)*);
#endif /* RB_CUSTOMIZE */
struct RB_ENTRY(node) *rb_root;
}; };
RB_STATIC int RB_ENTRY(init) ( int toku_rbt_init (
#ifndef RB_CUSTOMIZE int (*cmp)(const toku_range*, const toku_range*),
int (*cmp)(const void *, const void *, const void *), const void *config, struct toku_rbt_tree** ptree
#else
int (*cmp)(const RB_ENTRY(data_t)*, const RB_ENTRY(data_t)*),
#endif /* RB_CUSTOMIZE */
struct RB_ENTRY(tree)** ptree
); );
#ifndef no_delete int toku_rbt_lookup(
RB_STATIC const RB_ENTRY(data_t) *RB_ENTRY(delete)(const RB_ENTRY(data_t) *, struct RB_ENTRY(tree) *);
#endif
#ifndef no_find
RB_STATIC const RB_ENTRY(data_t) *RB_ENTRY(find)(const RB_ENTRY(data_t) *, struct RB_ENTRY(tree) *);
#endif
#ifndef no_lookup
RB_STATIC int RB_ENTRY(lookup)(
int mode, int mode,
const RB_ENTRY(data_t)* key, const toku_range* key,
struct RB_ENTRY(tree)* rbinfo, struct toku_rbt_tree* rbinfo,
struct RB_ENTRY(node)** pinsert_finger, struct toku_rbt_node** pinsert_finger,
struct RB_ENTRY(node)** pelement_finger, struct toku_rbt_node** pelement_finger,
const RB_ENTRY(data_t)** pdata const toku_range** pdata
); );
#endif
#ifndef no_search
RB_STATIC const RB_ENTRY(data_t) *RB_ENTRY(search)(const RB_ENTRY(data_t) *, struct RB_ENTRY(tree) *);
#endif
#ifndef no_finger_insert const toku_range* toku_rbt_finger_insert(
RB_STATIC const RB_ENTRY(data_t)* RB_ENTRY(finger_insert)( const toku_range* key,
const RB_ENTRY(data_t)* key, struct toku_rbt_tree* rbinfo,
struct RB_ENTRY(tree)* rbinfo, struct toku_rbt_node* parent
struct RB_ENTRY(node)* parent
); );
#endif
#ifndef no_finger_delete
RB_STATIC int RB_ENTRY(finger_delete)(struct RB_ENTRY(node)* node, struct RB_ENTRY(tree) *rbinfo);
#endif
#ifndef no_pred int toku_rbt_finger_delete(struct toku_rbt_node* node, struct toku_rbt_tree *rbinfo);
RB_STATIC int RB_ENTRY(finger_predecessor)(const struct RB_ENTRY(node)** pfinger, const RB_ENTRY(data_t)** ppred_data);
#endif
#ifndef no_succ int toku_rbt_finger_predecessor(const struct toku_rbt_node** pfinger, const toku_range** ppred_data);
RB_STATIC int RB_ENTRY(finger_successor)(const struct RB_ENTRY(node)** pfinger, const RB_ENTRY(data_t)** psucc_data);
#endif
#ifndef no_destroy int toku_rbt_finger_successor(const struct toku_rbt_node** pfinger, const toku_range** psucc_data);
RB_STATIC void RB_ENTRY(destroy)(struct RB_ENTRY(tree) *);
#endif
#ifndef no_walk void toku_rbt_destroy(struct toku_rbt_tree *);
RB_STATIC void RB_ENTRY(walk)(const struct RB_ENTRY(tree) *,
void (*)(const RB_ENTRY(data_t) *, const VISIT, const int, void *),
void *);
#endif
#ifndef no_readlist enum nodecolour { BLACK, RED };
RB_STATIC RBLIST *RB_ENTRY(openlist)(const struct RB_ENTRY(tree) *);
RB_STATIC const RB_ENTRY(data_t) *RB_ENTRY(readlist)(RBLIST *);
RB_STATIC void RB_ENTRY(closelist)(RBLIST *);
#endif
/* Some useful macros */ struct toku_rbt_node
#define rbmin(rbinfo) RB_ENTRY(lookup)(RB_LUFIRST, NULL, (rbinfo)) {
#define rbmax(rbinfo) RB_ENTRY(lookup)(RB_LULAST, NULL, (rbinfo)) struct toku_rbt_node *left; /* Left down */
struct toku_rbt_node *right; /* Right down */
struct toku_rbt_node *up; /* Up */
enum nodecolour colour; /* Node colour */
#ifdef RB_INLINE
toku_range key; /* User's key (and data) */
#define RB_GET(x,y) &x->y
#define RB_SET(x,y,v) x->y = *(v)
#else
const toku_range *key; /* Pointer to user's key (and data) */
#define RB_GET(x,y) x->y
#define RB_SET(x,y,v) x->y = v
#endif /* RB_INLINE */
};
#define _REDBLACK_H #define _REDBLACK_H
#endif /* _REDBLACK_H */ #endif /* _REDBLACK_H */
/*
*
* $Log: redblack.h,v $
* Revision 1.9 2003/10/24 01:31:21 damo
* Patches from Eric Raymond: %prefix is implemented.  Various other small
* changes avoid stepping on global namespaces and improve the documentation.
*
* Revision 1.8 2003/10/23 04:18:47 damo
* Fixed up the rbgen stuff ready for the 1.3 release
*
* Revision 1.7 2002/08/26 03:11:40 damo
* Fixed up a bunch of compiler warnings when compiling example4
*
* Tidies up the Makefile.am & Specfile.
*
* Renamed redblack to rbgen
*
* Revision 1.6 2002/08/26 01:03:35 damo
* Patch from Eric Raymond to change the way the library is used:-
*
* Eric's idea is to convert libredblack into a piece of in-line code
* generated by another program. This should be faster, smaller and easier
* to use.
*
* This is the first check-in of his code before I start futzing with it!
*
* Revision 1.5 2002/01/30 07:54:53 damo
* Fixed up the libtool versioning stuff (finally)
* Fixed bug 500600 (not detecting a NULL return from malloc)
* Fixed bug 509485 (no longer needs search.h)
* Cleaned up debugging section
* Allow multiple inclusions of redblack.h
* Thanks to Matthias Andree for reporting (and fixing) these
*
* Revision 1.4 2000/06/06 14:43:43 damo
* Added all the rbwalk & rbopenlist stuff. Fixed up malloc instead of sbrk.
* Added two new examples
*
* Revision 1.3 2000/05/24 06:45:27 damo
* Converted everything over to using const
* Added a new example1.c file to demonstrate the worst case scenario
* Minor fixups of the spec file
*
* Revision 1.2 2000/05/24 06:17:10 damo
* Fixed up the License (now the LGPL)
*
* Revision 1.1 2000/05/24 04:15:53 damo
* Initial import of files. Versions are now all over the place. Oh well
*
*/
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment