[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 11/13] abt: New function abt_is_empty().
From: |
Ben Pfaff |
Subject: |
[PATCH 11/13] abt: New function abt_is_empty(). |
Date: |
Mon, 16 Apr 2012 20:52:17 -0700 |
---
src/libpspp/abt.h | 11 +++++++++++
tests/libpspp/abt-test.c | 1 +
2 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/src/libpspp/abt.h b/src/libpspp/abt.h
index 0e5b252..f97d957 100644
--- a/src/libpspp/abt.h
+++ b/src/libpspp/abt.h
@@ -145,6 +145,7 @@
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 */
diff --git a/tests/libpspp/abt-test.c b/tests/libpspp/abt-test.c
index eae7d46..3e68637 100644
--- a/tests/libpspp/abt-test.c
+++ b/tests/libpspp/abt-test.c
@@ -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);
}
--
1.7.2.5
- [PATCH 03/13] gui: Add undocumented --measure-startup option., (continued)
- [PATCH 03/13] gui: Add undocumented --measure-startup option., Ben Pfaff, 2012/04/16
- [PATCH 04/13] gui: Call g_thread_init() earlier., Ben Pfaff, 2012/04/16
- [PATCH 05/13] format: New functions fmt_change_width(), fmt_change_decimals()., Ben Pfaff, 2012/04/16
- [PATCH 07/13] format: Fix typo in comment., Ben Pfaff, 2012/04/16
- [PATCH 08/13] helper: New function value_to_text__()., Ben Pfaff, 2012/04/16
- [PATCH 09/13] value-labels: New function val_labs_find_value()., Ben Pfaff, 2012/04/16
- [PATCH 06/13] format: Introduce a new type "enum fmt_use"., Ben Pfaff, 2012/04/16
- [PATCH 10/13] abt: Drop child parameters from 'reaugment' function., Ben Pfaff, 2012/04/16
- [PATCH 11/13] abt: New function abt_is_empty().,
Ben Pfaff <=
- [PATCH 12/13] range-set: Rename "insert" function "set1", "delete" to "set0"., Ben Pfaff, 2012/04/16
- [PATCH 13/13] range-set: New macro RANGE_SET_FOR_EACH to make iteration easier., Ben Pfaff, 2012/04/16
- Re: [PATCH 00/13] second batch of psppsheet changes, John Darrington, 2012/04/18