ports/devel/py-rbtree/files/patch-src__rbtree_impl.c
Marcus Alves Grando 03ad0df1b9 - New port devel/py-rbtree
An RBTree is a fast, balanced efficient data structure with the
following properties:

get          O(log n)
set          O(log n)
delete       O(log n)
min          O(log n)
max          O(log n)
contains     O(log n)

Because the worst case timing is minimal across the range of standard
dict and ordered data operations it makes sense to use this when you
have volatile/dynamic sorted data.

In common usage its nearly as fast as the Python dict impl but has a
slightly more expensive usage of the compare function as the keys are
ordered and not hashed.

WWW:	http://www.python.org/pypi/RBTree/
2006-05-08 14:25:19 +00:00

37 lines
1,003 B
C

--- ./src/rbtree_impl.c.orig Mon May 8 11:00:16 2006
+++ ./src/rbtree_impl.c Mon May 8 11:01:48 2006
@@ -43,10 +43,11 @@
int
rbtree_node_compare(PyObject *x, PyObject *y)
{
+ int gt, lt;
/* a three way compare that should work with whatever objects support */
- int gt = PyObject_RichCompareBool(x,y, Py_GT);
+ gt = PyObject_RichCompareBool(x,y, Py_GT);
if (gt == 1) return 1;
- int lt = PyObject_RichCompareBool(x,y, Py_LT);
+ lt = PyObject_RichCompareBool(x,y, Py_LT);
if (lt == 1) return -1;
return 0;
}
@@ -626,16 +627,18 @@
rbtree_node_t *
tree_min(rbtree_t *T, rbtree_node_t *x) {
+ rbtree_node_t *n;
if (x == NULL) x = T->root;
- rbtree_node_t *n = __tree_min(T, x);
+ n = __tree_min(T, x);
if (n == T->nil) n = NULL;
return n;
}
rbtree_node_t *
tree_max(rbtree_t *T, rbtree_node_t *x) {
+ rbtree_node_t *n;
if (x == NULL) x = T->root;
- rbtree_node_t *n = __tree_max(T, x);
+ n = __tree_max(T, x);
if (n == T->nil) n = NULL;
return n;
}