annotate gcc/ada/libgnat/a-chtgop.ads @ 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 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT LIBRARY COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- ADA.CONTAINERS.HASH_TABLES.GENERIC_OPERATIONS --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 2004-2019, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 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 -- This unit was originally developed by Matthew J Heaney. --
kono
parents:
diff changeset
28 ------------------------------------------------------------------------------
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 -- Hash_Table_Type is used to implement hashed containers. This package
kono
parents:
diff changeset
31 -- declares hash-table operations that do not depend on keys.
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 with Ada.Streams;
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 generic
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 with package HT_Types is
kono
parents:
diff changeset
38 new Generic_Hash_Table_Types (<>);
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 use HT_Types, HT_Types.Implementation;
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 with function Hash_Node (Node : Node_Access) return Hash_Type;
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 with function Next (Node : Node_Access) return Node_Access;
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 with procedure Set_Next
kono
parents:
diff changeset
47 (Node : Node_Access;
kono
parents:
diff changeset
48 Next : Node_Access);
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 with function Copy_Node (Source : Node_Access) return Node_Access;
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 with procedure Free (X : in out Node_Access);
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 package Ada.Containers.Hash_Tables.Generic_Operations is
kono
parents:
diff changeset
55 pragma Preelaborate;
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 procedure Free_Hash_Table (Buckets : in out Buckets_Access);
kono
parents:
diff changeset
58 -- First frees the nodes in all non-null buckets of Buckets, and then frees
kono
parents:
diff changeset
59 -- the Buckets array itself.
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 function Index
kono
parents:
diff changeset
62 (Buckets : Buckets_Type;
kono
parents:
diff changeset
63 Node : Node_Access) return Hash_Type;
kono
parents:
diff changeset
64 pragma Inline (Index);
kono
parents:
diff changeset
65 -- Uses the hash value of Node to compute its Buckets array index
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 function Index
kono
parents:
diff changeset
68 (Hash_Table : Hash_Table_Type;
kono
parents:
diff changeset
69 Node : Node_Access) return Hash_Type;
kono
parents:
diff changeset
70 pragma Inline (Index);
kono
parents:
diff changeset
71 -- Uses the hash value of Node to compute its Hash_Table buckets array
kono
parents:
diff changeset
72 -- index.
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 function Checked_Index
kono
parents:
diff changeset
75 (Hash_Table : aliased in out Hash_Table_Type;
kono
parents:
diff changeset
76 Buckets : Buckets_Type;
kono
parents:
diff changeset
77 Node : Node_Access) return Hash_Type;
kono
parents:
diff changeset
78 -- Calls Index, but also locks and unlocks the container, per AI05-0022, in
kono
parents:
diff changeset
79 -- order to detect element tampering by the generic actual Hash function.
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 function Checked_Index
kono
parents:
diff changeset
82 (Hash_Table : aliased in out Hash_Table_Type;
kono
parents:
diff changeset
83 Node : Node_Access) return Hash_Type;
kono
parents:
diff changeset
84 -- Calls Checked_Index using Hash_Table's buckets array.
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 procedure Adjust (HT : in out Hash_Table_Type);
kono
parents:
diff changeset
87 -- Used to implement controlled Adjust. It is assumed that HT has the value
kono
parents:
diff changeset
88 -- of the bit-wise copy that immediately follows controlled Finalize.
kono
parents:
diff changeset
89 -- Adjust first allocates a new buckets array for HT (having the same
kono
parents:
diff changeset
90 -- length as the source), and then allocates a copy of each node of source.
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 procedure Finalize (HT : in out Hash_Table_Type);
kono
parents:
diff changeset
93 -- Used to implement controlled Finalize. It first calls Clear to
kono
parents:
diff changeset
94 -- deallocate any remaining nodes, and then deallocates the buckets array.
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 generic
kono
parents:
diff changeset
97 with function Find
kono
parents:
diff changeset
98 (HT : Hash_Table_Type;
kono
parents:
diff changeset
99 Key : Node_Access) return Boolean;
kono
parents:
diff changeset
100 function Generic_Equal
kono
parents:
diff changeset
101 (L, R : Hash_Table_Type) return Boolean;
kono
parents:
diff changeset
102 -- Used to implement hashed container equality. For each node in hash table
kono
parents:
diff changeset
103 -- L, it calls Find to search for an equivalent item in hash table R. If
kono
parents:
diff changeset
104 -- Find returns False for any node then Generic_Equal terminates
kono
parents:
diff changeset
105 -- immediately and returns False. Otherwise if Find returns True for every
kono
parents:
diff changeset
106 -- node then Generic_Equal returns True.
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 procedure Clear (HT : in out Hash_Table_Type);
kono
parents:
diff changeset
109 -- Deallocates each node in hash table HT. (Note that it only deallocates
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
110 -- the nodes, not the buckets array. Also note that for bounded containers,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
111 -- the buckets array is not dynamically allocated). Program_Error is raised
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
112 -- if the hash table is busy.
111
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 procedure Move (Target, Source : in out Hash_Table_Type);
kono
parents:
diff changeset
115 -- Moves (not copies) the buckets array and nodes from Source to
kono
parents:
diff changeset
116 -- Target. Program_Error is raised if Source is busy. The Target is first
kono
parents:
diff changeset
117 -- cleared to deallocate its nodes (implying that Program_Error is also
kono
parents:
diff changeset
118 -- raised if Target is busy). Source is empty following the move.
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 function Capacity (HT : Hash_Table_Type) return Count_Type;
kono
parents:
diff changeset
121 -- Returns the length of the buckets array
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 procedure Reserve_Capacity
kono
parents:
diff changeset
124 (HT : in out Hash_Table_Type;
kono
parents:
diff changeset
125 N : Count_Type);
kono
parents:
diff changeset
126 -- If N is greater than the current capacity, then it expands the buckets
kono
parents:
diff changeset
127 -- array to at least the value N. If N is less than the current capacity,
kono
parents:
diff changeset
128 -- then it contracts the buckets array. In either case existing nodes are
kono
parents:
diff changeset
129 -- rehashed onto the new buckets array, and the old buckets array is
kono
parents:
diff changeset
130 -- deallocated. Program_Error is raised if the hash table is busy.
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 procedure Delete_Node_At_Index
kono
parents:
diff changeset
133 (HT : in out Hash_Table_Type;
kono
parents:
diff changeset
134 Indx : Hash_Type;
kono
parents:
diff changeset
135 X : in out Node_Access);
kono
parents:
diff changeset
136 -- Delete a node whose bucket position is known. Used to remove a node
kono
parents:
diff changeset
137 -- whose element has been modified through a key_preserving reference.
kono
parents:
diff changeset
138 -- We cannot use the value of the element precisely because the current
kono
parents:
diff changeset
139 -- value does not correspond to the hash code that determines the bucket.
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 procedure Delete_Node_Sans_Free
kono
parents:
diff changeset
142 (HT : in out Hash_Table_Type;
kono
parents:
diff changeset
143 X : Node_Access);
kono
parents:
diff changeset
144 -- Removes node X from the hash table without deallocating the node
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 function First
kono
parents:
diff changeset
147 (HT : Hash_Table_Type) return Node_Access;
kono
parents:
diff changeset
148 function First
kono
parents:
diff changeset
149 (HT : Hash_Table_Type;
kono
parents:
diff changeset
150 Position : out Hash_Type) return Node_Access;
kono
parents:
diff changeset
151 -- Returns the head of the list in the first (lowest-index) non-empty
kono
parents:
diff changeset
152 -- bucket. Position will be the index of the bucket of the first node.
kono
parents:
diff changeset
153 -- It is provided so that clients can implement efficient iterators.
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 function Next
kono
parents:
diff changeset
156 (HT : aliased in out Hash_Table_Type;
kono
parents:
diff changeset
157 Node : Node_Access) return Node_Access;
kono
parents:
diff changeset
158 function Next
kono
parents:
diff changeset
159 (HT : aliased in out Hash_Table_Type;
kono
parents:
diff changeset
160 Node : Node_Access;
kono
parents:
diff changeset
161 Position : in out Hash_Type) return Node_Access;
kono
parents:
diff changeset
162 -- Returns the node that immediately follows Node. This corresponds to
kono
parents:
diff changeset
163 -- either the next node in the same bucket, or (if Node is the last node in
kono
parents:
diff changeset
164 -- its bucket) the head of the list in the first non-empty bucket that
kono
parents:
diff changeset
165 -- follows.
kono
parents:
diff changeset
166 --
kono
parents:
diff changeset
167 -- If Node_Position is supplied, then it will be used as a starting point
kono
parents:
diff changeset
168 -- for iteration (Node_Position must be the index of Node's buckets). If it
kono
parents:
diff changeset
169 -- is not supplied, it will be recomputed. It is provided so that clients
kono
parents:
diff changeset
170 -- can implement efficient iterators.
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 generic
kono
parents:
diff changeset
173 with procedure Process (Node : Node_Access; Position : Hash_Type);
kono
parents:
diff changeset
174 procedure Generic_Iteration_With_Position (HT : Hash_Table_Type);
kono
parents:
diff changeset
175 -- Calls Process for each node in hash table HT
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 generic
kono
parents:
diff changeset
178 with procedure Process (Node : Node_Access);
kono
parents:
diff changeset
179 procedure Generic_Iteration (HT : Hash_Table_Type);
kono
parents:
diff changeset
180 -- Calls Process for each node in hash table HT
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 generic
kono
parents:
diff changeset
183 use Ada.Streams;
kono
parents:
diff changeset
184 with procedure Write
kono
parents:
diff changeset
185 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
186 Node : Node_Access);
kono
parents:
diff changeset
187 procedure Generic_Write
kono
parents:
diff changeset
188 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
189 HT : Hash_Table_Type);
kono
parents:
diff changeset
190 -- Used to implement the streaming attribute for hashed containers. It
kono
parents:
diff changeset
191 -- calls Write for each node to write its value into Stream.
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 generic
kono
parents:
diff changeset
194 use Ada.Streams;
kono
parents:
diff changeset
195 with function New_Node
kono
parents:
diff changeset
196 (Stream : not null access Root_Stream_Type'Class)
kono
parents:
diff changeset
197 return Node_Access;
kono
parents:
diff changeset
198 procedure Generic_Read
kono
parents:
diff changeset
199 (Stream : not null access Root_Stream_Type'Class;
kono
parents:
diff changeset
200 HT : out Hash_Table_Type);
kono
parents:
diff changeset
201 -- Used to implement the streaming attribute for hashed containers. It
kono
parents:
diff changeset
202 -- first clears hash table HT, then populates the hash table by calling
kono
parents:
diff changeset
203 -- New_Node for each item in Stream.
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 function New_Buckets (Length : Hash_Type) return Buckets_Access;
kono
parents:
diff changeset
206 pragma Inline (New_Buckets);
kono
parents:
diff changeset
207 -- Allocate a new Buckets_Type array with bounds 0 .. Length - 1
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209 procedure Free_Buckets (Buckets : in out Buckets_Access);
kono
parents:
diff changeset
210 pragma Inline (Free_Buckets);
kono
parents:
diff changeset
211 -- Unchecked_Deallocate Buckets
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 -- Note: New_Buckets and Free_Buckets are needed because Buckets_Access has
kono
parents:
diff changeset
214 -- an empty pool.
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 end Ada.Containers.Hash_Tables.Generic_Operations;