mirror of git://gcc.gnu.org/git/gcc.git
splay-tree.c (splay_tree_delete_helper): Redesign the logic so that recursion (and thus large stack space) is not needed.
* splay-tree.c (splay_tree_delete_helper): Redesign the logic so that recursion (and thus large stack space) is not needed. From-SVN: r91815
This commit is contained in:
parent
354e49c1d9
commit
b180d5fb7b
|
@ -1,3 +1,8 @@
|
||||||
|
2004-12-07 DJ Delorie <dj@redhat.com>
|
||||||
|
|
||||||
|
* splay-tree.c (splay_tree_delete_helper): Redesign the logic so
|
||||||
|
that recursion (and thus large stack space) is not needed.
|
||||||
|
|
||||||
2004-11-29 Matt Kraai <kraai@alumni.cmu.edu>
|
2004-11-29 Matt Kraai <kraai@alumni.cmu.edu>
|
||||||
|
|
||||||
* pex-unix.c: Fix the spelling of longjmp.
|
* pex-unix.c: Fix the spelling of longjmp.
|
||||||
|
|
|
@ -59,18 +59,59 @@ splay_tree_delete_helper (sp, node)
|
||||||
splay_tree sp;
|
splay_tree sp;
|
||||||
splay_tree_node node;
|
splay_tree_node node;
|
||||||
{
|
{
|
||||||
|
splay_tree_node pending = 0;
|
||||||
|
splay_tree_node active = 0;
|
||||||
|
|
||||||
if (!node)
|
if (!node)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
splay_tree_delete_helper (sp, node->left);
|
#define KDEL(x) if (sp->delete_key) (*sp->delete_key)(x);
|
||||||
splay_tree_delete_helper (sp, node->right);
|
#define VDEL(x) if (sp->delete_value) (*sp->delete_value)(x);
|
||||||
|
|
||||||
if (sp->delete_key)
|
KDEL (node->key);
|
||||||
(*sp->delete_key)(node->key);
|
VDEL (node->value);
|
||||||
if (sp->delete_value)
|
|
||||||
(*sp->delete_value)(node->value);
|
|
||||||
|
|
||||||
(*sp->deallocate) ((char*) node, sp->allocate_data);
|
/* We use the "key" field to hold the "next" pointer. */
|
||||||
|
node->key = (splay_tree_key)pending;
|
||||||
|
pending = (splay_tree_node)node;
|
||||||
|
|
||||||
|
/* Now, keep processing the pending list until there aren't any
|
||||||
|
more. This is a little more complicated than just recursing, but
|
||||||
|
it doesn't toast the stack for large trees. */
|
||||||
|
|
||||||
|
while (pending)
|
||||||
|
{
|
||||||
|
active = pending;
|
||||||
|
pending = 0;
|
||||||
|
while (active)
|
||||||
|
{
|
||||||
|
splay_tree_node temp;
|
||||||
|
|
||||||
|
/* active points to a node which has its key and value
|
||||||
|
deallocated, we just need to process left and right. */
|
||||||
|
|
||||||
|
if (active->left)
|
||||||
|
{
|
||||||
|
KDEL (active->left->key);
|
||||||
|
VDEL (active->left->value);
|
||||||
|
active->left->key = (splay_tree_key)pending;
|
||||||
|
pending = (splay_tree_node)(active->left);
|
||||||
|
}
|
||||||
|
if (active->right)
|
||||||
|
{
|
||||||
|
KDEL (active->right->key);
|
||||||
|
VDEL (active->right->value);
|
||||||
|
active->right->key = (splay_tree_key)pending;
|
||||||
|
pending = (splay_tree_node)(active->right);
|
||||||
|
}
|
||||||
|
|
||||||
|
temp = active;
|
||||||
|
active = (splay_tree_node)(temp->key);
|
||||||
|
(*sp->deallocate) ((char*) temp, sp->allocate_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#undef KDEL
|
||||||
|
#undef VDEL
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Help splay SP around KEY. PARENT and GRANDPARENT are the parent
|
/* Help splay SP around KEY. PARENT and GRANDPARENT are the parent
|
||||||
|
|
Loading…
Reference in New Issue