pspp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[patch 4/5] Allow traversing tower nodes in reverse order.


From: blp
Subject: [patch 4/5] Allow traversing tower nodes in reverse order.
Date: Sun, 03 Jun 2007 15:47:15 -0700
User-agent: quilt/0.45-1

Index: merge/src/libpspp/tower.h
===================================================================
--- merge.orig/src/libpspp/tower.h      2007-05-31 22:06:31.000000000 -0700
+++ merge/src/libpspp/tower.h   2007-05-31 22:36:10.000000000 -0700
@@ -95,7 +97,10 @@
                                  unsigned long int level,
                                  unsigned long int *node_start);
 struct tower_node *tower_first (const struct tower *);
+struct tower_node *tower_last (const struct tower *);
 struct tower_node *tower_next (const struct tower *,
                                const struct tower_node *);
+struct tower_node *tower_prev (const struct tower *,
+                               const struct tower_node *);
 
 #endif /* libpspp/tower.h */
Index: merge/src/libpspp/tower.c
===================================================================
--- merge.orig/src/libpspp/tower.c      2007-05-31 22:06:31.000000000 -0700
+++ merge/src/libpspp/tower.c   2007-05-31 22:36:10.000000000 -0700
@@ -25,8 +27,11 @@
 
 static struct tower_node *abt_to_tower_node (const struct abt_node *);
 static struct tower_node *first_node (const struct tower *);
+static struct tower_node *last_node (const struct tower *);
 static struct tower_node *next_node (const struct tower *,
                                      const struct tower_node *);
+static struct tower_node *prev_node (const struct tower *,
+                                     const struct tower_node *);
 static unsigned long int get_subtree_height (const struct abt_node *);
 static void reaugment_tower_node (struct abt_node *,
                                   const struct abt_node *,
@@ -168,6 +187,14 @@
   return first_node (t);
 }
 
+/* Returns the node at the top of tower T, or a null pointer if T
+   is empty. */
+struct tower_node *
+tower_last (const struct tower *t) 
+{
+  return last_node (t);
+}
+
 /* If NODE is nonnull, returns the node just above NODE in tower
    T, or a null pointer if NODE is the topmost node in T.
    If NODE is null, acts like tower_first. */
@@ -176,6 +203,15 @@
 {
   return node != NULL ? next_node (t, node) : first_node (t);
 }
+
+/* If NODE is nonnull, returns the node just below NODE in tower
+   T, or a null pointer if NODE is the bottommost node in T.
+   If NODE is null, acts like tower_last. */
+struct tower_node *
+tower_prev (const struct tower *t, const struct tower_node *node) 
+{
+  return node != NULL ? prev_node (t, node) : last_node (t);
+}
 
 /* Returns the tower node corresponding to the given ABT_NODE. */
 static struct tower_node *
@@ -184,20 +220,39 @@
   return abt_data (abt_node, struct tower_node, abt_node);
 }
 
+/* Returns the tower node corresponding to the given ABT_NODE. */
+static struct tower_node *
+abt_to_tower_node_null (const struct abt_node *abt_node) 
+{
+  return abt_node != NULL ? abt_to_tower_node (abt_node) : NULL;
+}
+
 /* Returns the first node in TOWER. */
 static struct tower_node *
 first_node (const struct tower *t) 
 {
-  struct abt_node *abt_node = abt_first (&t->abt);
-  return abt_node != NULL ? abt_to_tower_node (abt_node) : NULL;
+  return abt_to_tower_node_null (abt_first (&t->abt));
+}
+
+/* Returns the first node in TOWER. */
+static struct tower_node *
+last_node (const struct tower *t) 
+{
+  return abt_to_tower_node_null (abt_last (&t->abt));
 }
 
 /* Returns the next node in TOWER after NODE. */
 static struct tower_node *
 next_node (const struct tower *t, const struct tower_node *node) 
 {
-  struct abt_node *abt_node = abt_next (&t->abt, &node->abt_node);
-  return abt_node != NULL ? abt_to_tower_node (abt_node) : NULL;
+  return abt_to_tower_node_null (abt_next (&t->abt, &node->abt_node));
+}
+
+/* Returns the previous node in TOWER before NODE. */
+static struct tower_node *
+prev_node (const struct tower *t, const struct tower_node *node) 
+{
+  return abt_to_tower_node_null (abt_prev (&t->abt, &node->abt_node));
 }
 
 /* Returns the total height of the nodes in the subtree rooted at

--





reply via email to

[Prev in Thread] Current Thread [Next in Thread]