X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fabt.h;h=f97d957e5251c70aeb55190f4b313b6eefea0799;hb=ea17c5b225557fc0760810861451a84dc241d462;hp=fa9d0dc87d6b7112a856cbe6666046a6013a9077;hpb=fe8dc2171009e90d2335f159d05f7e6660e24780;p=pspp diff --git a/src/libpspp/abt.h b/src/libpspp/abt.h index fa9d0dc87d..f97d957e52 100644 --- a/src/libpspp/abt.h +++ b/src/libpspp/abt.h @@ -34,10 +34,9 @@ The ABT data structure partially abstracts augmentation. The client passes in a "reaugmentation" function that accepts a - node and its left and right children. This function must - recalculate the node's augmentation data based on its own - contents and the contents of its children, and store the new - augmentation data in the node. + node. This function must recalculate the node's augmentation + data based on its own contents and the contents of its + children, and store the new augmentation data in the node. The ABT automatically calls the reaugmentation function whenever it can tell that a node's augmentation data might @@ -104,19 +103,16 @@ } // Recalculates the count for NODE's subtree by adding up the - // counts for its LEFT and RIGHT child subtrees. + // counts for its left and right child subtrees. static void - reaugment_elements (struct abt_node *node_, - const struct abt_node *left, - const struct abt_node *right, - const void *aux) + reaugment_elements (struct abt_node *node_, const void *aux) { struct element *node = node_to_element (node_); node->count = 1; - if (left != NULL) - node->count += node_to_element (left)->count; - if (right != NULL) - node->count += node_to_element (right)->count; + if (node->node.down[0] != NULL) + node->count += node_to_element (node->node.down[0])->count; + if (node->node.down[1] != NULL) + node->count += node_to_element (node->node.down[1])->count; } // Finds and returns the element in ABT that is in the given @@ -149,6 +145,7 @@ code and links to other resources, such as the original AA tree paper. */ +#include #include #include "libpspp/cast.h" @@ -173,12 +170,10 @@ typedef int abt_compare_func (const struct abt_node *a, const struct abt_node *b, const void *aux); -/* Recalculates NODE's augmentation based on NODE's data and that - of its LEFT and RIGHT children, with the tree's AUX. */ -typedef void abt_reaugment_func (struct abt_node *node, - const struct abt_node *left, - const struct abt_node *right, - const void *aux); +/* Recalculates NODE's augmentation based on NODE's data and that of its left + and right children NODE->down[0] and NODE[1], respectively, with the tree's + AUX. */ +typedef void abt_reaugment_func (struct abt_node *node, const void *aux); /* An augmented binary tree. */ struct abt @@ -192,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 *); @@ -209,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 */