annotate libgomp/splay-tree.h @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* A splay-tree datatype.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 1998-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 Contributed by Mark Mitchell (mark@markmitchell.com).
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of the GNU Offloading and Multi Processing Library
kono
parents:
diff changeset
6 (libgomp).
kono
parents:
diff changeset
7
kono
parents:
diff changeset
8 Libgomp is free software; you can redistribute it and/or modify it
kono
parents:
diff changeset
9 under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
10 the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
11 any later version.
kono
parents:
diff changeset
12
kono
parents:
diff changeset
13 Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
kono
parents:
diff changeset
15 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
kono
parents:
diff changeset
16 more details.
kono
parents:
diff changeset
17
kono
parents:
diff changeset
18 Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
19 permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
20 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
21
kono
parents:
diff changeset
22 You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
23 a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
25 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27 /* The splay tree code copied from include/splay-tree.h and adjusted,
kono
parents:
diff changeset
28 so that all the data lives directly in splay_tree_node_s structure
kono
parents:
diff changeset
29 and no extra allocations are needed.
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 Files including this header should before including it add:
kono
parents:
diff changeset
32 typedef struct splay_tree_node_s *splay_tree_node;
kono
parents:
diff changeset
33 typedef struct splay_tree_s *splay_tree;
kono
parents:
diff changeset
34 typedef struct splay_tree_key_s *splay_tree_key;
kono
parents:
diff changeset
35 define splay_tree_key_s structure, and define
kono
parents:
diff changeset
36 splay_compare inline function.
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 Alternatively, they can define splay_tree_prefix macro before
kono
parents:
diff changeset
39 including this header and then all the above types, the
kono
parents:
diff changeset
40 splay_compare function and the splay_tree_{lookup,insert_remove}
kono
parents:
diff changeset
41 function will be prefixed by that prefix. If splay_tree_prefix
kono
parents:
diff changeset
42 macro is defined, this header must be included twice: once where
kono
parents:
diff changeset
43 you need the header file definitions, and once where you need the
kono
parents:
diff changeset
44 .c implementation routines. In the latter case, you must also
kono
parents:
diff changeset
45 define the macro splay_tree_c. See the include of splay-tree.h in
kono
parents:
diff changeset
46 priority_queue.[hc] for an example. */
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 /* For an easily readable description of splay-trees, see:
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 Lewis, Harry R. and Denenberg, Larry. Data Structures and Their
kono
parents:
diff changeset
51 Algorithms. Harper-Collins, Inc. 1991.
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 The major feature of splay trees is that all basic tree operations
kono
parents:
diff changeset
54 are amortized O(log n) time for a tree with n nodes. */
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 #ifdef splay_tree_prefix
kono
parents:
diff changeset
57 # define splay_tree_name_1(prefix, name) prefix ## _ ## name
kono
parents:
diff changeset
58 # define splay_tree_name(prefix, name) splay_tree_name_1 (prefix, name)
kono
parents:
diff changeset
59 # define splay_tree_node_s \
kono
parents:
diff changeset
60 splay_tree_name (splay_tree_prefix, splay_tree_node_s)
kono
parents:
diff changeset
61 # define splay_tree_s \
kono
parents:
diff changeset
62 splay_tree_name (splay_tree_prefix, splay_tree_s)
kono
parents:
diff changeset
63 # define splay_tree_key_s \
kono
parents:
diff changeset
64 splay_tree_name (splay_tree_prefix, splay_tree_key_s)
kono
parents:
diff changeset
65 # define splay_tree_node \
kono
parents:
diff changeset
66 splay_tree_name (splay_tree_prefix, splay_tree_node)
kono
parents:
diff changeset
67 # define splay_tree \
kono
parents:
diff changeset
68 splay_tree_name (splay_tree_prefix, splay_tree)
kono
parents:
diff changeset
69 # define splay_tree_key \
kono
parents:
diff changeset
70 splay_tree_name (splay_tree_prefix, splay_tree_key)
kono
parents:
diff changeset
71 # define splay_compare \
kono
parents:
diff changeset
72 splay_tree_name (splay_tree_prefix, splay_compare)
kono
parents:
diff changeset
73 # define splay_tree_lookup \
kono
parents:
diff changeset
74 splay_tree_name (splay_tree_prefix, splay_tree_lookup)
kono
parents:
diff changeset
75 # define splay_tree_insert \
kono
parents:
diff changeset
76 splay_tree_name (splay_tree_prefix, splay_tree_insert)
kono
parents:
diff changeset
77 # define splay_tree_remove \
kono
parents:
diff changeset
78 splay_tree_name (splay_tree_prefix, splay_tree_remove)
kono
parents:
diff changeset
79 # define splay_tree_foreach \
kono
parents:
diff changeset
80 splay_tree_name (splay_tree_prefix, splay_tree_foreach)
kono
parents:
diff changeset
81 # define splay_tree_callback \
kono
parents:
diff changeset
82 splay_tree_name (splay_tree_prefix, splay_tree_callback)
kono
parents:
diff changeset
83 #endif
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 #ifndef splay_tree_c
kono
parents:
diff changeset
86 /* Header file definitions and prototypes. */
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 /* The nodes in the splay tree. */
kono
parents:
diff changeset
89 struct splay_tree_node_s {
kono
parents:
diff changeset
90 struct splay_tree_key_s key;
kono
parents:
diff changeset
91 /* The left and right children, respectively. */
kono
parents:
diff changeset
92 splay_tree_node left;
kono
parents:
diff changeset
93 splay_tree_node right;
kono
parents:
diff changeset
94 };
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 /* The splay tree. */
kono
parents:
diff changeset
97 struct splay_tree_s {
kono
parents:
diff changeset
98 splay_tree_node root;
kono
parents:
diff changeset
99 };
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 typedef void (*splay_tree_callback) (splay_tree_key, void *);
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 extern splay_tree_key splay_tree_lookup (splay_tree, splay_tree_key);
kono
parents:
diff changeset
104 extern void splay_tree_insert (splay_tree, splay_tree_node);
kono
parents:
diff changeset
105 extern void splay_tree_remove (splay_tree, splay_tree_key);
kono
parents:
diff changeset
106 extern void splay_tree_foreach (splay_tree, splay_tree_callback, void *);
kono
parents:
diff changeset
107 #else /* splay_tree_c */
kono
parents:
diff changeset
108 # ifdef splay_tree_prefix
kono
parents:
diff changeset
109 # include "splay-tree.c"
kono
parents:
diff changeset
110 # undef splay_tree_name_1
kono
parents:
diff changeset
111 # undef splay_tree_name
kono
parents:
diff changeset
112 # undef splay_tree_node_s
kono
parents:
diff changeset
113 # undef splay_tree_s
kono
parents:
diff changeset
114 # undef splay_tree_key_s
kono
parents:
diff changeset
115 # undef splay_tree_node
kono
parents:
diff changeset
116 # undef splay_tree
kono
parents:
diff changeset
117 # undef splay_tree_key
kono
parents:
diff changeset
118 # undef splay_compare
kono
parents:
diff changeset
119 # undef splay_tree_lookup
kono
parents:
diff changeset
120 # undef splay_tree_insert
kono
parents:
diff changeset
121 # undef splay_tree_remove
kono
parents:
diff changeset
122 # undef splay_tree_foreach
kono
parents:
diff changeset
123 # undef splay_tree_callback
kono
parents:
diff changeset
124 # undef splay_tree_c
kono
parents:
diff changeset
125 # endif
kono
parents:
diff changeset
126 #endif /* #ifndef splay_tree_c */
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 #ifdef splay_tree_prefix
kono
parents:
diff changeset
129 # undef splay_tree_prefix
kono
parents:
diff changeset
130 #endif