1 /* A splay-tree datatype.
2 Copyright 1998, 1999, 2000, 2002, 2004 Free Software Foundation, Inc.
3 Contributed by Mark Mitchell (mark@markmitchell.com).
4 Adapted for libmudflap from libiberty by Frank Ch. Eigler <fche@redhat.com>.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GCC is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* For an easily readable description of splay-trees, see:
25 Lewis, Harry R. and Denenberg, Larry. Data Structures and Their
26 Algorithms. Harper-Collins, Inc. 1991.
28 The major feature of splay trees is that all basic tree operations
29 are amortized O(log n) time for a tree with n nodes.
31 This version has been further modified to periodically rebalance
32 the entire tree, should degenerate access patterns result in a very
39 /* Use typedefs for the key and data types to facilitate changing
40 these types, if necessary. These types should be sufficiently wide
41 that any pointer or scalar can be cast to these types, and then
42 cast back, without loss of precision. */
43 typedef uintptr_t splay_tree_key
;
44 typedef void *splay_tree_value
;
46 /* Forward declaration for a node in the tree. */
47 typedef struct splay_tree_node_s
*splay_tree_node
;
49 /* The type of a function used to iterate over the tree. */
50 typedef int (*splay_tree_foreach_fn
) (splay_tree_node
, void *);
52 /* The nodes in the splay tree. */
53 struct splay_tree_node_s
57 splay_tree_value value
;
60 splay_tree_node right
;
63 /* The splay tree itself. */
66 /* The root of the tree. */
69 /* The last key value for which the tree has been splayed, but not
71 splay_tree_key last_splayed_key
;
72 int last_splayed_key_p
;
77 /* Traversal recursion control flags. */
82 typedef struct splay_tree_s
*splay_tree
;
84 extern splay_tree
splay_tree_new (void);
85 extern splay_tree_node
splay_tree_insert (splay_tree
, splay_tree_key
, splay_tree_value
);
86 extern void splay_tree_remove (splay_tree
, splay_tree_key
);
87 extern splay_tree_node
splay_tree_lookup (splay_tree
, splay_tree_key
);
88 extern splay_tree_node
splay_tree_predecessor (splay_tree
, splay_tree_key
);
89 extern splay_tree_node
splay_tree_successor (splay_tree
, splay_tree_key
);
90 extern splay_tree_node
splay_tree_max (splay_tree
);
91 extern splay_tree_node
splay_tree_min (splay_tree
);
92 extern int splay_tree_foreach (splay_tree
, splay_tree_foreach_fn
, void *);
93 extern void splay_tree_rebalance (splay_tree sp
);
96 #endif /* _SPLAY_TREE_H */