abt: New function abt_is_empty().
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 6 Nov 2011 21:03:24 +0000 (13:03 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 21 Apr 2012 04:39:52 +0000 (21:39 -0700)
src/libpspp/abt.h
tests/libpspp/abt-test.c

index 0e5b25281e0ec5b94ad43a581f97d7a37f25f88a..f97d957e5251c70aeb55190f4b313b6eefea0799 100644 (file)
    code and links to other resources, such as the original AA
    tree paper.  */
 
+#include <stdbool.h>
 #include <stddef.h>
 #include "libpspp/cast.h"
 
@@ -186,6 +187,8 @@ struct abt
 void abt_init (struct abt *, abt_compare_func *, abt_reaugment_func *,
                const void *aux);
 
+static inline bool abt_is_empty (const struct abt *);
+
 struct abt_node *abt_insert (struct abt *, struct abt_node *);
 void abt_insert_after (struct abt *,
                        const struct abt_node *, struct abt_node *);
@@ -203,4 +206,12 @@ void abt_reaugmented (const struct abt *, struct abt_node *);
 struct abt_node *abt_changed (struct abt *, struct abt_node *);
 void abt_moved (struct abt *, struct abt_node *);
 
+/* Returns true if ABT contains no nodes, false if ABT contains at least one
+   node. */
+static inline bool
+abt_is_empty (const struct abt *abt)
+{
+  return abt->root == NULL;
+}
+
 #endif /* libpspp/abt.h */
index eae7d46787ba5549a4264aa951496d543c566b1c..3e68637a5bee3b38eec64011d5f7df87d43bccf2 100644 (file)
@@ -371,6 +371,7 @@ check_abt (struct abt *abt, const int data[], size_t cnt)
         check (abt_node_to_element (p)->data == order[cnt - i - 1]);
       check (p == NULL);
     }
+  check (abt_is_empty (abt) == (cnt == 0));
 
   free (order);
 }