summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f2f52fa)
raw | patch | inline | side by side (parent: f2f52fa)
author | Sebastian Harl <sh@tokkee.org> | |
Fri, 17 Jun 2011 07:24:02 +0000 (09:24 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Fri, 17 Jun 2011 07:24:02 +0000 (09:24 +0200) |
src/utils_avltree.c | patch | blob | history | |
src/utils_avltree.h | patch | blob | history |
diff --git a/src/utils_avltree.c b/src/utils_avltree.c
index 3e258e95d8c6834271823cab5aa5cddfc3a4845a..0436d8fe077eceeaffdeff607bc8f9e44ebe5aca 100644 (file)
--- a/src/utils_avltree.c
+++ b/src/utils_avltree.c
{
c_avl_node_t *root;
int (*compare) (const void *, const void *);
+ int size;
};
struct c_avl_iterator_s
t->root = NULL;
t->compare = compare;
+ t->size = 0;
return (t);
}
} /* while (42) */
verify_tree (t->root);
+ ++t->size;
return (0);
} /* int c_avl_insert */
status = _remove (t, n);
verify_tree (t->root);
+ --t->size;
return (status);
} /* void *c_avl_remove */
{
free (iter);
}
+
+int c_avl_size (c_avl_tree_t *t)
+{
+ if (t == NULL)
+ return (0);
+ return (t->size);
+}
diff --git a/src/utils_avltree.h b/src/utils_avltree.h
index 355ced2493b971112f8fcb17f560f4cbeb1b6393..10fb5cbecf6ab46c9cc3a851f01732b5614d85b1 100644 (file)
--- a/src/utils_avltree.h
+++ b/src/utils_avltree.h
int c_avl_iterator_prev (c_avl_iterator_t *iter, void **key, void **value);
void c_avl_iterator_destroy (c_avl_iterator_t *iter);
+/*
+ * NAME
+ * c_avl_size
+ *
+ * DESCRIPTION
+ * Return the size (number of nodes) of the specified tree.
+ *
+ * PARAMETERS
+ * `t' AVL-tree to get the size of.
+ *
+ * RETURN VALUE
+ * Number of nodes in the tree, 0 if the tree is empty or NULL.
+ */
+int c_avl_size (c_avl_tree_t *t);
+
#endif /* UTILS_AVLTREE_H */