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.
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. */
36 #endif /* __cplusplus */
40 #define ATTRIBUTE_UNUSED __attribute__((__unused__))
46 /* Use typedefs for the key and data types to facilitate changing
47 these types, if necessary. These types should be sufficiently wide
48 that any pointer or scalar can be cast to these types, and then
49 cast back, without loss of precision. */
50 typedef uintptr_t splay_tree_key;
51 typedef void *splay_tree_value;
53 /* Forward declaration for a node in the tree. */
54 typedef struct splay_tree_node_s *splay_tree_node;
56 /* The type of a function used to iterate over the tree. */
57 typedef int (*splay_tree_foreach_fn) PARAMS((splay_tree_node, void*));
59 /* The type of a function used to allocate memory for tree root and
60 node structures. The first argument is the number of bytes needed;
61 the second is a data pointer the splay tree functions pass through
62 to the allocator. This function must never return zero. */
63 typedef PTR (*splay_tree_allocate_fn) PARAMS((int, void *));
65 /* The type of a function used to free memory allocated using the
66 corresponding splay_tree_allocate_fn. The first argument is the
67 memory to be freed; the latter is a data pointer the splay tree
68 functions pass through to the freer. */
69 typedef void (*splay_tree_deallocate_fn) PARAMS((void *, void *));
71 /* The nodes in the splay tree. */
72 struct splay_tree_node_s GTY(())
75 splay_tree_key GTY ((use_param1)) key;
78 splay_tree_value GTY ((use_param2)) value;
80 /* The left and right children, respectively. */
81 splay_tree_node GTY ((use_params)) left;
82 splay_tree_node GTY ((use_params)) right;
85 /* The splay tree itself. */
86 struct splay_tree_s GTY(())
88 /* The root of the tree. */
89 splay_tree_node GTY ((use_params)) root;
91 /* Allocate/free functions, and a data pointer to pass to them. */
92 splay_tree_allocate_fn allocate;
93 splay_tree_deallocate_fn deallocate;
94 PTR GTY((skip)) allocate_data;
96 /* The last key value for which the tree has been splayed, but not
98 splay_tree_key GTY ((use_param1)) last_splayed_key;
99 int last_splayed_key_p;
101 typedef struct splay_tree_s *splay_tree;
103 extern splay_tree splay_tree_new PARAMS((void));
104 extern void splay_tree_delete PARAMS((splay_tree));
105 extern splay_tree_node splay_tree_insert
109 extern void splay_tree_remove PARAMS((splay_tree,
111 extern splay_tree_node splay_tree_lookup
114 extern splay_tree_node splay_tree_predecessor
117 extern splay_tree_node splay_tree_successor
120 extern splay_tree_node splay_tree_max
121 PARAMS((splay_tree));
122 extern splay_tree_node splay_tree_min
123 PARAMS((splay_tree));
124 extern int splay_tree_foreach PARAMS((splay_tree,
125 splay_tree_foreach_fn,
127 extern int splay_tree_compare_ints PARAMS((splay_tree_key,
129 extern int splay_tree_compare_pointers PARAMS((splay_tree_key,
134 #endif /* __cplusplus */
136 #endif /* _SPLAY_TREE_H */