2006-07-28 00:01:57 +00:00
|
|
|
|
/*
|
merge in changes from svn[r1572..r1601]
------------------------------------------------------------------------
r1601 | sears.russell@gmail.com | 2012-03-20 18:43:00 -0400 (Tue, 20
Mar 2012) | 1 line
commit bLSM bloom filter to stasis/util, which is where it really
belongs
------------------------------------------------------------------------
r1600 | sears.russell@gmail.com | 2012-03-04 01:58:38 -0500 (Sun, 04
Mar 2012) | 1 line
fix memory leak in skiplist unit test (now it is valgrind clean)
------------------------------------------------------------------------
r1599 | sears.russell@gmail.com | 2012-03-04 01:58:05 -0500 (Sun, 04
Mar 2012) | 1 line
fix typo in finalize type
------------------------------------------------------------------------
r1598 | sears.russell@gmail.com | 2012-03-04 00:59:59 -0500 (Sun, 04
Mar 2012) | 1 line
add comparator and finalizer parameters to skiplist constructor
------------------------------------------------------------------------
r1597 | sears.russell@gmail.com | 2012-03-03 18:23:16 -0500 (Sat, 03
Mar 2012) | 1 line
bugfixes for skiplist
------------------------------------------------------------------------
r1596 | sears.russell@gmail.com | 2012-03-02 15:05:07 -0500 (Fri, 02
Mar 2012) | 1 line
updated concurrentSkipList. Seeing strange crashes
------------------------------------------------------------------------
r1595 | sears.russell@gmail.com | 2012-03-01 16:51:59 -0500 (Thu, 01
Mar 2012) | 1 line
add progress reports
------------------------------------------------------------------------
r1594 | sears.russell@gmail.com | 2012-02-28 13:17:05 -0500 (Tue, 28
Feb 2012) | 1 line
experimental support for automatic logfile preallocation
------------------------------------------------------------------------
r1593 | sears.russell@gmail.com | 2012-02-28 12:10:01 -0500 (Tue, 28
Feb 2012) | 1 line
add histogram reporting to rawIOPS benchmark
------------------------------------------------------------------------
r1592 | sears.russell@gmail.com | 2012-02-24 16:31:36 -0500 (Fri, 24
Feb 2012) | 1 line
userspace raid 0 implementation
------------------------------------------------------------------------
r1591 | sears.russell@gmail.com | 2012-02-12 01:47:25 -0500 (Sun, 12
Feb 2012) | 1 line
add skiplist unit test, fix compile warnings
------------------------------------------------------------------------
r1590 | sears.russell@gmail.com | 2012-02-12 00:52:52 -0500 (Sun, 12
Feb 2012) | 1 line
fix compile error
------------------------------------------------------------------------
r1589 | sears.russell@gmail.com | 2012-02-12 00:50:21 -0500 (Sun, 12
Feb 2012) | 1 line
fix some bugs in hazard.h surrounding thread list management and
overruns of R under high contention
------------------------------------------------------------------------
r1588 | sears.russell@gmail.com | 2012-02-11 14:23:10 -0500 (Sat, 11
Feb 2012) | 1 line
add hazard pointer for get_lock. It was implicitly blowing away the
hazard pointer protecting y in the caller
------------------------------------------------------------------------
r1587 | sears.russell@gmail.com | 2012-02-10 18:51:25 -0500 (Fri, 10
Feb 2012) | 1 line
fix null pointer bug
------------------------------------------------------------------------
r1586 | sears.russell@gmail.com | 2012-02-10 18:03:39 -0500 (Fri, 10
Feb 2012) | 1 line
add simple refcounting scheme to concurrentSkipList. This solves the
problem where a deleted node points to another deleted node, and we
only have a hazard pointer for the first node.
------------------------------------------------------------------------
r1585 | sears.russell@gmail.com | 2012-02-10 14:19:14 -0500 (Fri, 10
Feb 2012) | 1 line
add hazard pointers for update using the smallest free slot first. The
old method left a race condition, since hazard_scan stops at the first
null pointer.
------------------------------------------------------------------------
r1584 | sears.russell@gmail.com | 2012-02-10 02:45:30 -0500 (Fri, 10
Feb 2012) | 1 line
add hazard pointers for update array
------------------------------------------------------------------------
r1583 | sears.russell@gmail.com | 2012-02-10 00:04:50 -0500 (Fri, 10
Feb 2012) | 1 line
skiplist update: concurrent, but broken
------------------------------------------------------------------------
r1582 | sears.russell@gmail.com | 2012-02-09 17:44:27 -0500 (Thu, 09
Feb 2012) | 1 line
skip list implementation. Not concurrent yet.
------------------------------------------------------------------------
r1581 | sears.russell@gmail.com | 2012-02-08 13:33:29 -0500 (Wed, 08
Feb 2012) | 1 line
Commit of a bunch of new, unused code: KISS random number generator,
Hazard Pointers, SUX latches (untested) and bit twiddling for
concurrent b-tree
------------------------------------------------------------------------
r1580 | sears.russell@gmail.com | 2012-01-17 19:17:37 -0500 (Tue, 17
Jan 2012) | 1 line
fix typo
------------------------------------------------------------------------
r1579 | sears.russell@gmail.com | 2012-01-11 18:33:31 -0500 (Wed, 11
Jan 2012) | 1 line
static build fixes for linux. hopefully these do not break macos...
------------------------------------------------------------------------
r1578 | sears.russell@gmail.com | 2012-01-09 19:13:34 -0500 (Mon, 09
Jan 2012) | 1 line
fix cmake under linux
------------------------------------------------------------------------
r1577 | sears.russell@gmail.com | 2012-01-09 18:37:15 -0500 (Mon, 09
Jan 2012) | 1 line
fix linux static binary compilation bugs
------------------------------------------------------------------------
r1576 | sears.russell | 2012-01-09 18:00:08 -0500 (Mon, 09 Jan 2012) |
1 line
port to macos x
------------------------------------------------------------------------
r1575 | sears.russell | 2012-01-09 17:39:43 -0500 (Mon, 09 Jan 2012) |
1 line
add missing _ from sync call name
------------------------------------------------------------------------
r1574 | sears.russell@gmail.com | 2012-01-09 14:26:31 -0500 (Mon, 09
Jan 2012) | 1 line
add -rt flag to static builds
------------------------------------------------------------------------
r1573 | sears.russell@gmail.com | 2011-12-20 23:38:29 -0500 (Tue, 20
Dec 2011) | 1 line
Simple makefile geared toward building libstasis.so and libstasis.a
(and nothing else)
------------------------------------------------------------------------
r1572 | sears.russell@gmail.com | 2011-12-20 22:37:54 -0500 (Tue, 20
Dec 2011) | 1 line
add some missing #include<config.h> lines
2012-04-21 16:52:31 +00:00
|
|
|
|
* RCS $Id: redblack.h 1525 2011-06-13 10:19:44Z sears.russell@gmail.com $
|
2006-07-28 00:01:57 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Redblack balanced tree algorithm
|
|
|
|
|
Copyright (C) Damian Ivereigh 2000
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
|
(at your option) any later version. See the file COPYING for details.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Header file for redblack.c, should be included by any code that
|
|
|
|
|
** uses redblack.c since it defines the functions
|
|
|
|
|
*/
|
2013-02-09 02:51:38 +00:00
|
|
|
|
#include <stasis/common.h>
|
2006-07-28 00:01:57 +00:00
|
|
|
|
|
|
|
|
|
/* Stop multiple includes */
|
2009-11-24 00:24:18 +00:00
|
|
|
|
#ifdef STLSEARCH
|
|
|
|
|
#include "stlredblack.h"
|
|
|
|
|
#else
|
2006-07-28 00:01:57 +00:00
|
|
|
|
#ifndef _REDBLACK_H
|
|
|
|
|
#ifndef RB_CUSTOMIZE
|
2013-02-09 02:51:38 +00:00
|
|
|
|
|
|
|
|
|
BEGIN_C_DECLS
|
2006-07-28 00:01:57 +00:00
|
|
|
|
/*
|
|
|
|
|
* 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_CMP. Because the comparison function is
|
|
|
|
|
* compiled in, RB_CMP 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_CMP(s, t, e) (*rbinfo->rb_cmp)(s, t, e)
|
|
|
|
|
#undef RB_INLINE
|
|
|
|
|
#define RB_ENTRY(name) rb##name
|
|
|
|
|
#endif /* RB_CUSTOMIZE */
|
|
|
|
|
|
|
|
|
|
#ifndef RB_STATIC
|
|
|
|
|
#define RB_STATIC
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Modes for rblookup */
|
|
|
|
|
#define RB_NONE -1 /* None of those below */
|
|
|
|
|
#define RB_LUEQUAL 0 /* Only exact match */
|
|
|
|
|
#define RB_LUGTEQ 1 /* Exact match or greater */
|
|
|
|
|
#define RB_LULTEQ 2 /* Exact match or less */
|
|
|
|
|
#define RB_LULESS 3 /* Less than key (not equal to) */
|
|
|
|
|
#define RB_LUGREAT 4 /* Greater than key (not equal to) */
|
|
|
|
|
#define RB_LUNEXT 5 /* Next key after current */
|
|
|
|
|
#define RB_LUPREV 6 /* Prev key before current */
|
|
|
|
|
#define RB_LUFIRST 7 /* First key in index */
|
|
|
|
|
#define RB_LULAST 8 /* Last key in index */
|
|
|
|
|
|
|
|
|
|
/* For rbwalk - pinched from search.h */
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
preorder,
|
|
|
|
|
postorder,
|
|
|
|
|
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 RB_ENTRY(tree) {
|
|
|
|
|
#ifndef RB_CUSTOMIZE
|
|
|
|
|
/* comparison routine */
|
|
|
|
|
int (*rb_cmp)(const void *, const void *, const void *);
|
|
|
|
|
/* config data to be passed to rb_cmp */
|
|
|
|
|
const void *rb_config;
|
|
|
|
|
/* root of tree */
|
|
|
|
|
#endif /* RB_CUSTOMIZE */
|
|
|
|
|
struct RB_ENTRY(node) *rb_root;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#ifndef RB_CUSTOMIZE
|
|
|
|
|
RB_STATIC struct RB_ENTRY(tree) *rbinit(int (*)(const void *, const void *, const void *),
|
|
|
|
|
const void *);
|
|
|
|
|
#else
|
|
|
|
|
RB_STATIC struct RB_ENTRY(tree) *RB_ENTRY(init)(void);
|
|
|
|
|
#endif /* RB_CUSTOMIZE */
|
|
|
|
|
|
|
|
|
|
#ifndef no_delete
|
|
|
|
|
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 const RB_ENTRY(data_t) *RB_ENTRY(lookup)(int, const RB_ENTRY(data_t) *, struct RB_ENTRY(tree) *);
|
|
|
|
|
#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_destroy
|
|
|
|
|
RB_STATIC void RB_ENTRY(destroy)(struct RB_ENTRY(tree) *);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef no_walk
|
|
|
|
|
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
|
|
|
|
|
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 *);
|
2013-02-09 02:51:38 +00:00
|
|
|
|
|
|
|
|
|
END_C_DECLS
|
|
|
|
|
|
2006-07-28 00:01:57 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Some useful macros */
|
|
|
|
|
#define rbmin(rbinfo) RB_ENTRY(lookup)(RB_LUFIRST, NULL, (rbinfo))
|
|
|
|
|
#define rbmax(rbinfo) RB_ENTRY(lookup)(RB_LULAST, NULL, (rbinfo))
|
|
|
|
|
|
|
|
|
|
#define _REDBLACK_H
|
2013-02-09 02:51:38 +00:00
|
|
|
|
|
2006-07-28 00:01:57 +00:00
|
|
|
|
#endif /* _REDBLACK_H */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* $Log$
|
|
|
|
|
* Revision 1.1 2006/07/28 00:01:57 sears
|
|
|
|
|
* Initial import of redblack implementation.
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
*
|
|
|
|
|
*/
|
2009-11-24 00:24:18 +00:00
|
|
|
|
#endif
|