strtoumax: fix typo in previous commit.
[gnulib.git] / lib / gl_rbtree_oset.c
index 6247972..9393d12 100644 (file)
@@ -1,5 +1,5 @@
 /* Ordered set data type implemented by a binary tree.
-   Copyright (C) 2006-2007 Free Software Foundation, Inc.
+   Copyright (C) 2006-2007, 2009-2013 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2006.
 
    This program is free software: you can redistribute it and/or modify
@@ -22,8 +22,6 @@
 
 #include <stdlib.h>
 
-#include "xalloc.h"
-
 /* A red-black tree is a binary tree where every node is colored black or
    red such that
    1. The root is black.
@@ -34,7 +32,7 @@
    Let's call this the "black-height" bh of the tree.  It follows that every
    such path contains exactly bh black and between 0 and bh red nodes.  (The
    extreme cases are a path containing only black nodes, and a path colored
-   alternatingly black-red-black-red-...-black-red.)  The height of the tree
+   alternately black-red-black-red-...-black-red.)  The height of the tree
    therefore is >= bh, <= 2*bh.
  */
 
@@ -84,7 +82,7 @@ struct gl_oset_impl
 
    Change the tree structure, update the branch sizes.
    The caller must update the colors and register D as child of its parent.  */
-static inline gl_oset_node_t
+static gl_oset_node_t
 rotate_left (gl_oset_node_t b_node, gl_oset_node_t d_node)
 {
   gl_oset_node_t c_node = d_node->left;
@@ -110,7 +108,7 @@ rotate_left (gl_oset_node_t b_node, gl_oset_node_t d_node)
 
    Change the tree structure, update the branch sizes.
    The caller must update the colors and register B as child of its parent.  */
-static inline gl_oset_node_t
+static gl_oset_node_t
 rotate_right (gl_oset_node_t b_node, gl_oset_node_t d_node)
 {
   gl_oset_node_t c_node = b_node->right;
@@ -538,10 +536,14 @@ rebalance_after_remove (gl_oset_t set, gl_oset_node_t child, gl_oset_node_t pare
 }
 
 static gl_oset_node_t
-gl_tree_add_first (gl_oset_t set, const void *elt)
+gl_tree_nx_add_first (gl_oset_t set, const void *elt)
 {
   /* Create new node.  */
-  gl_oset_node_t new_node = XMALLOC (struct gl_oset_node_impl);
+  gl_oset_node_t new_node =
+    (struct gl_oset_node_impl *) malloc (sizeof (struct gl_oset_node_impl));
+
+  if (new_node == NULL)
+    return NULL;
 
   new_node->left = NULL;
   new_node->right = NULL;
@@ -573,10 +575,14 @@ gl_tree_add_first (gl_oset_t set, const void *elt)
 }
 
 static gl_oset_node_t
-gl_tree_add_before (gl_oset_t set, gl_oset_node_t node, const void *elt)
+gl_tree_nx_add_before (gl_oset_t set, gl_oset_node_t node, const void *elt)
 {
   /* Create new node.  */
-  gl_oset_node_t new_node = XMALLOC (struct gl_oset_node_impl);
+  gl_oset_node_t new_node =
+    (struct gl_oset_node_impl *) malloc (sizeof (struct gl_oset_node_impl));
+
+  if (new_node == NULL)
+    return NULL;
 
   new_node->left = NULL;
   new_node->right = NULL;
@@ -601,10 +607,14 @@ gl_tree_add_before (gl_oset_t set, gl_oset_node_t node, const void *elt)
 }
 
 static gl_oset_node_t
-gl_tree_add_after (gl_oset_t set, gl_oset_node_t node, const void *elt)
+gl_tree_nx_add_after (gl_oset_t set, gl_oset_node_t node, const void *elt)
 {
   /* Create new node.  */
-  gl_oset_node_t new_node = XMALLOC (struct gl_oset_node_impl);
+  gl_oset_node_t new_node =
+    (struct gl_oset_node_impl *) malloc (sizeof (struct gl_oset_node_impl));
+
+  if (new_node == NULL)
+    return NULL;
 
   new_node->left = NULL;
   new_node->right = NULL;
@@ -791,11 +801,11 @@ gl_rbtree_oset_check_invariants (gl_oset_t set)
 
 const struct gl_oset_implementation gl_rbtree_oset_implementation =
   {
-    gl_tree_create_empty,
+    gl_tree_nx_create_empty,
     gl_tree_size,
     gl_tree_search,
     gl_tree_search_atleast,
-    gl_tree_add,
+    gl_tree_nx_add,
     gl_tree_remove,
     gl_tree_oset_free,
     gl_tree_iterator,