OSDN Git Service

* demangle.h: Don't check IN_GCC anymore.
[pf3gnuchains/gcc-fork.git] / include / splay-tree.h
1 /* A splay-tree datatype.  
2    Copyright (C) 1998 Free Software Foundation, Inc.
3    Contributed by Mark Mitchell (mark@markmitchell.com).
4
5    This file is part of GNU CC.
6    
7    GNU CC is free software; you can redistribute it and/or modify it
8    under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2, or (at your option)
10    any later version.
11
12    GNU CC is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GNU CC; see the file COPYING.  If not, write to the Free
19    Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
20
21    For an easily readable description of splay-trees, see:
22
23      Lewis, Harry R. and Denenberg, Larry.  Data Structures and Their
24      Algorithms.  Harper-Collins, Inc.  1991.  
25
26    The major feature of splay trees is that all basic tree operations
27    are amortized O(log n) time for a tree with n nodes.  */
28
29 #ifndef _SPLAY_TREE_H
30 #define _SPLAY_TREE_H
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif /* __cplusplus */
35
36 #include <ansidecl.h>
37
38 /* Use typedefs for the key and data types to facilitate changing
39    these types, if necessary.  These types should be sufficiently wide
40    that any pointer or scalar can be cast to these types, and then
41    cast back, without loss of precision.  */
42 typedef unsigned long int splay_tree_key;
43 typedef unsigned long int splay_tree_value;
44
45 /* Forward declaration for a node in the tree.  */
46 typedef struct splay_tree_node *splay_tree_node;
47
48 /* The type of a function which compares two splay-tree keys.  The
49    function should return values as for qsort.  */
50 typedef int (*splay_tree_compare_fn) PARAMS((splay_tree_key, splay_tree_key));
51
52 /* The type of a function used to deallocate any resources associated
53    with the key.  */
54 typedef void (*splay_tree_delete_key_fn) PARAMS((splay_tree_key));
55
56 /* The type of a function used to deallocate any resources associated
57    with the value.  */
58 typedef void (*splay_tree_delete_value_fn) PARAMS((splay_tree_value));
59
60 /* The type of a function used to iterate over the tree.  */
61 typedef int (*splay_tree_foreach_fn) PARAMS((splay_tree_node, void*));
62
63 /* The nodes in the splay tree.  */
64 struct splay_tree_node
65 {
66   /* The key.  */
67   splay_tree_key key;
68
69   /* The value.  */
70   splay_tree_value value;
71
72   /* The left and right children, respectively.  */
73   splay_tree_node left;
74   splay_tree_node right;
75 };
76
77 /* The splay tree itself.  */
78 typedef struct splay_tree
79 {
80   /* The root of the tree.  */
81   splay_tree_node root;
82
83   /* The comparision function.  */
84   splay_tree_compare_fn comp;
85
86   /* The deallocate-key function.  NULL if no cleanup is necessary.  */
87   splay_tree_delete_key_fn delete_key;
88
89   /* The deallocate-value function.  NULL if no cleanup is necessary.  */
90   splay_tree_delete_value_fn delete_value;
91 } *splay_tree;
92
93 extern splay_tree splay_tree_new        PARAMS((splay_tree_compare_fn,
94                                                 splay_tree_delete_key_fn,
95                                                 splay_tree_delete_value_fn));
96 extern void splay_tree_delete           PARAMS((splay_tree));
97 extern void splay_tree_insert           PARAMS((splay_tree,
98                                                 splay_tree_key,
99                                                 splay_tree_value));
100 extern splay_tree_node splay_tree_lookup   
101                                         PARAMS((splay_tree,
102                                                 splay_tree_key));
103 extern int splay_tree_foreach           PARAMS((splay_tree,
104                                                 splay_tree_foreach_fn,
105                                                 void*));
106                                                
107 #ifdef __cplusplus
108 }
109 #endif /* __cplusplus */
110
111 #endif /* _SPLAY_TREE_H */