summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Evans <jasone@canonware.com>2014-08-19 08:28:49 (GMT)
committerJason Evans <jasone@canonware.com>2014-08-20 04:05:54 (GMT)
commit1628e8615ed6c82ded14d6013ac775274eb426e6 (patch)
treee0b3db9952d2c2eb2f51f23961d06d5b4c22df27
parent3a81cbd2d4f2d8c052f11f4b0b73ee5c84a33d4f (diff)
downloadjemalloc-1628e8615ed6c82ded14d6013ac775274eb426e6.zip
jemalloc-1628e8615ed6c82ded14d6013ac775274eb426e6.tar.gz
jemalloc-1628e8615ed6c82ded14d6013ac775274eb426e6.tar.bz2
Add rb_empty().
-rw-r--r--include/jemalloc/internal/rb.h13
-rw-r--r--test/unit/rb.c3
2 files changed, 16 insertions, 0 deletions
diff --git a/include/jemalloc/internal/rb.h b/include/jemalloc/internal/rb.h
index 423802e..ffe3bb0 100644
--- a/include/jemalloc/internal/rb.h
+++ b/include/jemalloc/internal/rb.h
@@ -158,6 +158,8 @@ struct { \
#define rb_proto(a_attr, a_prefix, a_rbt_type, a_type) \
a_attr void \
a_prefix##new(a_rbt_type *rbtree); \
+a_attr bool \
+a_prefix##empty(a_rbt_type *rbtree); \
a_attr a_type * \
a_prefix##first(a_rbt_type *rbtree); \
a_attr a_type * \
@@ -224,6 +226,13 @@ a_prefix##reverse_iter(a_rbt_type *rbtree, a_type *start, \
* Args:
* tree: Pointer to an uninitialized red-black tree object.
*
+ * static bool
+ * ex_empty(ex_t *tree);
+ * Description: Determine whether tree is empty.
+ * Args:
+ * tree: Pointer to an initialized red-black tree object.
+ * Ret: True if tree is empty, false otherwise.
+ *
* static ex_node_t *
* ex_first(ex_t *tree);
* static ex_node_t *
@@ -309,6 +318,10 @@ a_attr void \
a_prefix##new(a_rbt_type *rbtree) { \
rb_new(a_type, a_field, rbtree); \
} \
+a_attr bool \
+a_prefix##empty(a_rbt_type *rbtree) { \
+ return (rbtree->rbt_root == &rbtree->rbt_nil); \
+} \
a_attr a_type * \
a_prefix##first(a_rbt_type *rbtree) { \
a_type *ret; \
diff --git a/test/unit/rb.c b/test/unit/rb.c
index b737485..e43907f 100644
--- a/test/unit/rb.c
+++ b/test/unit/rb.c
@@ -49,6 +49,7 @@ TEST_BEGIN(test_rb_empty)
tree_new(&tree);
+ assert_true(tree_empty(&tree), "Tree should be empty");
assert_ptr_null(tree_first(&tree), "Unexpected node");
assert_ptr_null(tree_last(&tree), "Unexpected node");
@@ -265,6 +266,8 @@ TEST_BEGIN(test_rb_random)
assert_u_eq(tree_iterate_reverse(&tree), k+1,
"Unexpected node iteration count");
+ assert_false(tree_empty(&tree),
+ "Tree should not be empty");
assert_ptr_not_null(tree_first(&tree),
"Tree should not be empty");
assert_ptr_not_null(tree_last(&tree),