/* Balanced binary trees using treaps.
- Copyright (C) 2000, 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2002, 2003, 2007, 2008
+ Free Software Foundation, Inc.
Contributed by Andy Vaught
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
+Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
for more details.
You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING. If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA. */
+along with GCC; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>. */
/* The idea is to balance the tree using pseudorandom numbers. The
main constraint on this implementation is that we have several
/* Rotate the treap left. */
static gfc_bbt *
-rotate_left (gfc_bbt * t)
+rotate_left (gfc_bbt *t)
{
gfc_bbt *temp;
/* Rotate the treap right. */
static gfc_bbt *
-rotate_right (gfc_bbt * t)
+rotate_right (gfc_bbt *t)
{
gfc_bbt *temp;
aborts if we find a duplicate key. */
static gfc_bbt *
-insert (gfc_bbt * new, gfc_bbt * t, compare_fn compare)
+insert (gfc_bbt *new_bbt, gfc_bbt *t, compare_fn compare)
{
int c;
if (t == NULL)
- return new;
+ return new_bbt;
- c = (*compare) (new, t);
+ c = (*compare) (new_bbt, t);
if (c < 0)
{
- t->left = insert (new, t->left, compare);
+ t->left = insert (new_bbt, t->left, compare);
if (t->priority < t->left->priority)
t = rotate_right (t);
}
-
else if (c > 0)
{
- t->right = insert (new, t->right, compare);
+ t->right = insert (new_bbt, t->right, compare);
if (t->priority < t->right->priority)
t = rotate_left (t);
}
-
else /* if (c == 0) */
gfc_internal_error("insert_bbt(): Duplicate key found!");
already exists. */
void
-gfc_insert_bbt (void *root, void *new, compare_fn compare)
+gfc_insert_bbt (void *root, void *new_node, compare_fn compare)
{
gfc_bbt **r, *n;
r = (gfc_bbt **) root;
- n = (gfc_bbt *) new;
-
+ n = (gfc_bbt *) new_node;
n->priority = pseudo_random ();
*r = insert (n, *r, compare);
}
static gfc_bbt *
-delete_root (gfc_bbt * t)
+delete_root (gfc_bbt *t)
{
gfc_bbt *temp;
Returns the new root node of the tree. */
static gfc_bbt *
-delete_treap (gfc_bbt * old, gfc_bbt * t, compare_fn compare)
+delete_treap (gfc_bbt *old, gfc_bbt *t, compare_fn compare)
{
int c;
gfc_bbt **t;
t = (gfc_bbt **) root;
-
*t = delete_treap ((gfc_bbt *) old, *t, compare);
}