1------------------------------------------------------------------------------
2--                                                                          --
3--                         GNAT LIBRARY COMPONENTS                          --
4--                                                                          --
5--           A D A . C O N T A I N E R S . H A S H E D _ S E T S            --
6--                                                                          --
7--                                 S p e c                                  --
8--                                                                          --
9--          Copyright (C) 2004-2021, Free Software Foundation, Inc.         --
10--                                                                          --
11-- This specification is derived from the Ada Reference Manual for use with --
12-- GNAT. The copyright notice above, and the license provisions that follow --
13-- apply solely to the  contents of the part following the private keyword. --
14--                                                                          --
15-- GNAT is free software;  you can  redistribute it  and/or modify it under --
16-- terms of the  GNU General Public License as published  by the Free Soft- --
17-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
18-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
19-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
20-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
21--                                                                          --
22-- As a special exception under Section 7 of GPL version 3, you are granted --
23-- additional permissions described in the GCC Runtime Library Exception,   --
24-- version 3.1, as published by the Free Software Foundation.               --
25--                                                                          --
26-- You should have received a copy of the GNU General Public License and    --
27-- a copy of the GCC Runtime Library Exception along with this program;     --
28-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
29-- <http://www.gnu.org/licenses/>.                                          --
30--                                                                          --
31-- This unit was originally developed by Matthew J Heaney.                  --
32------------------------------------------------------------------------------
33
34with Ada.Iterator_Interfaces;
35
36private with Ada.Containers.Hash_Tables;
37with Ada.Containers.Helpers;
38private with Ada.Finalization;
39private with Ada.Streams;
40private with Ada.Strings.Text_Buffers;
41
42generic
43   type Element_Type is private;
44
45   with function Hash (Element : Element_Type) return Hash_Type;
46
47   with function Equivalent_Elements
48          (Left, Right : Element_Type) return Boolean;
49
50   with function "=" (Left, Right : Element_Type) return Boolean is <>;
51
52package Ada.Containers.Hashed_Sets with
53  SPARK_Mode => Off
54is
55   pragma Annotate (CodePeer, Skip_Analysis);
56   pragma Preelaborate;
57   pragma Remote_Types;
58
59   type Set is tagged private
60   with
61      Constant_Indexing => Constant_Reference,
62      Default_Iterator  => Iterate,
63      Iterator_Element  => Element_Type,
64      Aggregate         => (Empty       => Empty,
65                            Add_Unnamed => Include);
66
67   pragma Preelaborable_Initialization (Set);
68
69   type Cursor is private;
70   pragma Preelaborable_Initialization (Cursor);
71
72   function "=" (Left, Right : Cursor) return Boolean;
73   --  The representation of cursors includes a component used to optimize
74   --  iteration over sets. This component may become unreliable after
75   --  multiple set insertions, and must be excluded from cursor equality,
76   --  so we need to provide an explicit definition for it, instead of
77   --  using predefined equality (as implied by a questionable comment
78   --  in the RM). This is also the case for hashed maps, and affects the
79   --  use of Insert primitives in hashed structures.
80
81   Empty_Set : constant Set;
82   --  Set objects declared without an initialization expression are
83   --  initialized to the value Empty_Set.
84
85   No_Element : constant Cursor;
86   --  Cursor objects declared without an initialization expression are
87   --  initialized to the value No_Element.
88
89   function Has_Element (Position : Cursor) return Boolean;
90   --  Equivalent to Position /= No_Element
91
92   package Set_Iterator_Interfaces is new
93     Ada.Iterator_Interfaces (Cursor, Has_Element);
94
95   function Empty (Capacity : Count_Type := 1000) return Set;
96
97   function "=" (Left, Right : Set) return Boolean;
98   --  For each element in Left, set equality attempts to find the equal
99   --  element in Right; if a search fails, then set equality immediately
100   --  returns False. The search works by calling Hash to find the bucket in
101   --  the Right set that corresponds to the Left element. If the bucket is
102   --  non-empty, the search calls the generic formal element equality operator
103   --  to compare the element (in Left) to the element of each node in the
104   --  bucket (in Right); the search terminates when a matching node in the
105   --  bucket is found, or the nodes in the bucket are exhausted. (Note that
106   --  element equality is called here, not Equivalent_Elements. Set equality
107   --  is the only operation in which element equality is used. Compare set
108   --  equality to Equivalent_Sets, which does call Equivalent_Elements.)
109
110   function Equivalent_Sets (Left, Right : Set) return Boolean;
111   --  Similar to set equality, with the difference that the element in Left is
112   --  compared to the elements in Right using the generic formal
113   --  Equivalent_Elements operation instead of element equality.
114
115   function To_Set (New_Item : Element_Type) return Set;
116   --  Constructs a singleton set comprising New_Element. To_Set calls Hash to
117   --  determine the bucket for New_Item.
118
119   function Capacity (Container : Set) return Count_Type;
120   --  Returns the current capacity of the set. Capacity is the maximum length
121   --  before which rehashing in guaranteed not to occur.
122
123   procedure Reserve_Capacity (Container : in out Set; Capacity : Count_Type);
124   --  Adjusts the current capacity, by allocating a new buckets array. If the
125   --  requested capacity is less than the current capacity, then the capacity
126   --  is contracted (to a value not less than the current length). If the
127   --  requested capacity is greater than the current capacity, then the
128   --  capacity is expanded (to a value not less than what is requested). In
129   --  either case, the nodes are rehashed from the old buckets array onto the
130   --  new buckets array (Hash is called once for each existing element in
131   --  order to compute the new index), and then the old buckets array is
132   --  deallocated.
133
134   function Length (Container : Set) return Count_Type;
135   --  Returns the number of items in the set
136
137   function Is_Empty (Container : Set) return Boolean;
138   --  Equivalent to Length (Container) = 0
139
140   procedure Clear (Container : in out Set);
141   --  Removes all of the items from the set
142
143   function Element (Position : Cursor) return Element_Type;
144   --  Returns the element of the node designated by the cursor
145
146   procedure Replace_Element
147     (Container : in out Set;
148      Position  : Cursor;
149      New_Item  : Element_Type);
150   --  If New_Item is equivalent (as determined by calling Equivalent_Elements)
151   --  to the element of the node designated by Position, then New_Element is
152   --  assigned to that element. Otherwise, it calls Hash to determine the
153   --  bucket for New_Item. If the bucket is not empty, then it calls
154   --  Equivalent_Elements for each node in that bucket to determine whether
155   --  New_Item is equivalent to an element in that bucket. If
156   --  Equivalent_Elements returns True then Program_Error is raised (because
157   --  an element may appear only once in the set); otherwise, New_Item is
158   --  assigned to the node designated by Position, and the node is moved to
159   --  its new bucket.
160
161   procedure Query_Element
162     (Position : Cursor;
163      Process  : not null access procedure (Element : Element_Type));
164   --  Calls Process with the element (having only a constant view) of the node
165   --  designed by the cursor.
166
167   type Constant_Reference_Type
168     (Element : not null access constant Element_Type) is private
169        with Implicit_Dereference => Element;
170
171   function Constant_Reference
172     (Container : aliased Set;
173      Position  : Cursor) return Constant_Reference_Type;
174   pragma Inline (Constant_Reference);
175
176   procedure Assign (Target : in out Set; Source : Set);
177
178   function Copy (Source : Set; Capacity : Count_Type := 0) return Set;
179
180   procedure Move (Target : in out Set; Source : in out Set);
181   --  Clears Target (if it's not empty), and then moves (not copies) the
182   --  buckets array and nodes from Source to Target.
183
184   procedure Insert
185     (Container : in out Set;
186      New_Item  : Element_Type;
187      Position  : out Cursor;
188      Inserted  : out Boolean);
189   --  Conditionally inserts New_Item into the set. If New_Item is already in
190   --  the set, then Inserted returns False and Position designates the node
191   --  containing the existing element (which is not modified). If New_Item is
192   --  not already in the set, then Inserted returns True and Position
193   --  designates the newly-inserted node containing New_Item. The search for
194   --  an existing element works as follows. Hash is called to determine
195   --  New_Item's bucket; if the bucket is non-empty, then Equivalent_Elements
196   --  is called to compare New_Item to the element of each node in that
197   --  bucket. If the bucket is empty, or there were no equivalent elements in
198   --  the bucket, the search "fails" and the New_Item is inserted in the set
199   --  (and Inserted returns True); otherwise, the search "succeeds" (and
200   --  Inserted returns False).
201
202   procedure Insert  (Container : in out Set; New_Item : Element_Type);
203   --  Attempts to insert New_Item into the set, performing the usual insertion
204   --  search (which involves calling both Hash and Equivalent_Elements); if
205   --  the search succeeds (New_Item is equivalent to an element already in the
206   --  set, and so was not inserted), then this operation raises
207   --  Constraint_Error. (This version of Insert is similar to Replace, but
208   --  having the opposite exception behavior. It is intended for use when you
209   --  want to assert that the item is not already in the set.)
210
211   procedure Include (Container : in out Set; New_Item : Element_Type);
212   --  Attempts to insert New_Item into the set. If an element equivalent to
213   --  New_Item is already in the set (the insertion search succeeded, and
214   --  hence New_Item was not inserted), then the value of New_Item is assigned
215   --  to the existing element. (This insertion operation only raises an
216   --  exception if cursor tampering occurs. It is intended for use when you
217   --  want to insert the item in the set, and you don't care whether an
218   --  equivalent element is already present.)
219
220   procedure Replace (Container : in out Set; New_Item : Element_Type);
221   --  Searches for New_Item in the set; if the search fails (because an
222   --  equivalent element was not in the set), then it raises
223   --  Constraint_Error. Otherwise, the existing element is assigned the value
224   --  New_Item. (This is similar to Insert, but with the opposite exception
225   --  behavior. It is intended for use when you want to assert that the item
226   --  is already in the set.)
227
228   procedure Exclude (Container : in out Set; Item : Element_Type);
229   --  Searches for Item in the set, and if found, removes its node from the
230   --  set and then deallocates it. The search works as follows. The operation
231   --  calls Hash to determine the item's bucket; if the bucket is not empty,
232   --  it calls Equivalent_Elements to compare Item to the element of each node
233   --  in the bucket. (This is the deletion analog of Include. It is intended
234   --  for use when you want to remove the item from the set, but don't care
235   --  whether the item is already in the set.)
236
237   procedure Delete  (Container : in out Set; Item : Element_Type);
238   --  Searches for Item in the set (which involves calling both Hash and
239   --  Equivalent_Elements). If the search fails, then the operation raises
240   --  Constraint_Error. Otherwise it removes the node from the set and then
241   --  deallocates it. (This is the deletion analog of non-conditional
242   --  Insert. It is intended for use when you want to assert that the item is
243   --  already in the set.)
244
245   procedure Delete (Container : in out Set; Position : in out Cursor);
246   --  Removes the node designated by Position from the set, and then
247   --  deallocates the node. The operation calls Hash to determine the bucket,
248   --  and then compares Position to each node in the bucket until there's a
249   --  match (it does not call Equivalent_Elements).
250
251   procedure Union (Target : in out Set; Source : Set);
252   --  The operation first calls Reserve_Capacity if the current capacity is
253   --  less than the sum of the lengths of Source and Target. It then iterates
254   --  over the Source set, and conditionally inserts each element into Target.
255
256   function Union (Left, Right : Set) return Set;
257   --  The operation first copies the Left set to the result, and then iterates
258   --  over the Right set to conditionally insert each element into the result.
259
260   function "or" (Left, Right : Set) return Set renames Union;
261
262   procedure Intersection (Target : in out Set; Source : Set);
263   --  Iterates over the Target set (calling First and Next), calling Find to
264   --  determine whether the element is in Source. If an equivalent element is
265   --  not found in Source, the element is deleted from Target.
266
267   function Intersection (Left, Right : Set) return Set;
268   --  Iterates over the Left set, calling Find to determine whether the
269   --  element is in Right. If an equivalent element is found, it is inserted
270   --  into the result set.
271
272   function "and" (Left, Right : Set) return Set renames Intersection;
273
274   procedure Difference (Target : in out Set; Source : Set);
275   --  Iterates over the Source (calling First and Next), calling Find to
276   --  determine whether the element is in Target. If an equivalent element is
277   --  found, it is deleted from Target.
278
279   function Difference (Left, Right : Set) return Set;
280   --  Iterates over the Left set, calling Find to determine whether the
281   --  element is in the Right set. If an equivalent element is not found, the
282   --  element is inserted into the result set.
283
284   function "-" (Left, Right : Set) return Set renames Difference;
285
286   procedure Symmetric_Difference (Target : in out Set; Source : Set);
287   --  The operation first calls Reserve_Capacity if the current capacity is
288   --  less than the sum of the lengths of Source and Target. It then iterates
289   --  over the Source set, searching for the element in Target (calling Hash
290   --  and Equivalent_Elements). If an equivalent element is found, it is
291   --  removed from Target; otherwise it is inserted into Target.
292
293   function Symmetric_Difference (Left, Right : Set) return Set;
294   --  The operation first iterates over the Left set. It calls Find to
295   --  determine whether the element is in the Right set. If no equivalent
296   --  element is found, the element from Left is inserted into the result. The
297   --  operation then iterates over the Right set, to determine whether the
298   --  element is in the Left set. If no equivalent element is found, the Right
299   --  element is inserted into the result.
300
301   function "xor" (Left, Right : Set) return Set
302     renames Symmetric_Difference;
303
304   function Overlap (Left, Right : Set) return Boolean;
305   --  Iterates over the Left set (calling First and Next), calling Find to
306   --  determine whether the element is in the Right set. If an equivalent
307   --  element is found, the operation immediately returns True. The operation
308   --  returns False if the iteration over Left terminates without finding any
309   --  equivalent element in Right.
310
311   function Is_Subset (Subset : Set; Of_Set : Set) return Boolean;
312   --  Iterates over Subset (calling First and Next), calling Find to determine
313   --  whether the element is in Of_Set. If no equivalent element is found in
314   --  Of_Set, the operation immediately returns False. The operation returns
315   --  True if the iteration over Subset terminates without finding an element
316   --  not in Of_Set (that is, every element in Subset is equivalent to an
317   --  element in Of_Set).
318
319   function First (Container : Set) return Cursor;
320   --  Returns a cursor that designates the first non-empty bucket, by
321   --  searching from the beginning of the buckets array.
322
323   function Next (Position : Cursor) return Cursor;
324   --  Returns a cursor that designates the node that follows the current one
325   --  designated by Position. If Position designates the last node in its
326   --  bucket, the operation calls Hash to compute the index of this bucket,
327   --  and searches the buckets array for the first non-empty bucket, starting
328   --  from that index; otherwise, it simply follows the link to the next node
329   --  in the same bucket.
330
331   procedure Next (Position : in out Cursor);
332   --  Equivalent to Position := Next (Position)
333
334   function Find
335     (Container : Set;
336      Item      : Element_Type) return Cursor;
337   --  Searches for Item in the set. Find calls Hash to determine the item's
338   --  bucket; if the bucket is not empty, it calls Equivalent_Elements to
339   --  compare Item to each element in the bucket. If the search succeeds, Find
340   --  returns a cursor designating the node containing the equivalent element;
341   --  otherwise, it returns No_Element.
342
343   function Contains (Container : Set; Item : Element_Type) return Boolean;
344   --  Equivalent to Find (Container, Item) /= No_Element
345
346   function Equivalent_Elements (Left, Right : Cursor) return Boolean;
347   --  Returns the result of calling Equivalent_Elements with the elements of
348   --  the nodes designated by cursors Left and Right.
349
350   function Equivalent_Elements
351     (Left  : Cursor;
352      Right : Element_Type) return Boolean;
353   --  Returns the result of calling Equivalent_Elements with element of the
354   --  node designated by Left and element Right.
355
356   function Equivalent_Elements
357     (Left  : Element_Type;
358      Right : Cursor) return Boolean;
359   --  Returns the result of calling Equivalent_Elements with element Left and
360   --  the element of the node designated by Right.
361
362   procedure Iterate
363     (Container : Set;
364      Process   : not null access procedure (Position : Cursor));
365   --  Calls Process for each node in the set
366
367   function Iterate
368     (Container : Set) return Set_Iterator_Interfaces.Forward_Iterator'Class;
369
370   generic
371      type Key_Type (<>) is private;
372
373      with function Key (Element : Element_Type) return Key_Type;
374
375      with function Hash (Key : Key_Type) return Hash_Type;
376
377      with function Equivalent_Keys (Left, Right : Key_Type) return Boolean;
378
379   package Generic_Keys is
380
381      function Key (Position : Cursor) return Key_Type;
382      --  Applies generic formal operation Key to the element of the node
383      --  designated by Position.
384
385      function Element (Container : Set; Key : Key_Type) return Element_Type;
386      --  Searches (as per the key-based Find) for the node containing Key, and
387      --  returns the associated element.
388
389      procedure Replace
390        (Container : in out Set;
391         Key       : Key_Type;
392         New_Item  : Element_Type);
393      --  Searches (as per the key-based Find) for the node containing Key, and
394      --  then replaces the element of that node (as per the element-based
395      --  Replace_Element).
396
397      procedure Exclude (Container : in out Set; Key : Key_Type);
398      --  Searches for Key in the set, and if found, removes its node from the
399      --  set and then deallocates it. The search works by first calling Hash
400      --  (on Key) to determine the bucket; if the bucket is not empty, it
401      --  calls Equivalent_Keys to compare parameter Key to the value of
402      --  generic formal operation Key applied to element of each node in the
403      --  bucket.
404
405      procedure Delete (Container : in out Set; Key : Key_Type);
406      --  Deletes the node containing Key as per Exclude, with the difference
407      --  that Constraint_Error is raised if Key is not found.
408
409      function Find (Container : Set; Key : Key_Type) return Cursor;
410      --  Searches for the node containing Key, and returns a cursor
411      --  designating the node. The search works by first calling Hash (on Key)
412      --  to determine the bucket. If the bucket is not empty, the search
413      --  compares Key to the element of each node in the bucket, and returns
414      --  the matching node. The comparison itself works by applying the
415      --  generic formal Key operation to the element of the node, and then
416      --  calling generic formal operation Equivalent_Keys.
417
418      function Contains (Container : Set; Key : Key_Type) return Boolean;
419      --  Equivalent to Find (Container, Key) /= No_Element
420
421      procedure Update_Element_Preserving_Key
422        (Container : in out Set;
423         Position  : Cursor;
424         Process   : not null access
425                       procedure (Element : in out Element_Type));
426      --  Calls Process with the element of the node designated by Position,
427      --  but with the restriction that the key-value of the element is not
428      --  modified. The operation first makes a copy of the value returned by
429      --  applying generic formal operation Key on the element of the node, and
430      --  then calls Process with the element. The operation verifies that the
431      --  key-part has not been modified by calling generic formal operation
432      --  Equivalent_Keys to compare the saved key-value to the value returned
433      --  by applying generic formal operation Key to the post-Process value of
434      --  element. If the key values compare equal then the operation
435      --  completes. Otherwise, the node is removed from the set and
436      --  Program_Error is raised.
437
438      type Reference_Type (Element : not null access Element_Type) is private
439        with Implicit_Dereference => Element;
440
441      function Reference_Preserving_Key
442        (Container : aliased in out Set;
443         Position  : Cursor) return Reference_Type;
444
445      function Constant_Reference
446        (Container : aliased Set;
447         Key       : Key_Type) return Constant_Reference_Type;
448
449      function Reference_Preserving_Key
450        (Container : aliased in out Set;
451         Key       : Key_Type) return Reference_Type;
452
453   private
454      use Ada.Streams;
455      type Set_Access is access all Set;
456      for Set_Access'Storage_Size use 0;
457
458      --  Key_Preserving references must carry information to allow removal
459      --  of elements whose value may have been altered improperly, i.e. have
460      --  been given values incompatible with the hash-code of the previous
461      --  value, and are thus in the wrong bucket. (RM 18.7 (96.6/3))
462
463      --  We cannot store the key directly because it is an unconstrained type.
464      --  To avoid using additional dynamic allocation we store the old cursor
465      --  which simplifies possible removal. This is not possible for some
466      --  other set types.
467
468      --  The mechanism is different for Update_Element_Preserving_Key, as
469      --  in that case the check that buckets have not changed is performed
470      --  at the time of the update, not when the reference is finalized.
471
472      package Impl is new Helpers.Generic_Implementation;
473
474      type Reference_Control_Type is
475         new Impl.Reference_Control_Type with
476      record
477         Container : Set_Access;
478         Index     : Hash_Type;
479         Old_Pos   : Cursor;
480         Old_Hash  : Hash_Type;
481      end record;
482
483      overriding procedure Finalize (Control : in out Reference_Control_Type);
484      pragma Inline (Finalize);
485
486      type Reference_Type (Element : not null access Element_Type) is record
487         Control  : Reference_Control_Type;
488      end record;
489
490      procedure Read
491        (Stream : not null access Root_Stream_Type'Class;
492         Item   : out Reference_Type);
493
494      for Reference_Type'Read use Read;
495
496      procedure Write
497        (Stream : not null access Root_Stream_Type'Class;
498         Item   : Reference_Type);
499
500      for Reference_Type'Write use Write;
501   end Generic_Keys;
502
503private
504   pragma Inline (Next);
505
506   type Node_Type;
507   type Node_Access is access Node_Type;
508
509   type Node_Type is limited record
510      Element : aliased Element_Type;
511      Next    : Node_Access;
512   end record;
513
514   package HT_Types is
515     new Hash_Tables.Generic_Hash_Table_Types (Node_Type, Node_Access);
516
517   type Set is new Ada.Finalization.Controlled with record
518      HT : HT_Types.Hash_Table_Type;
519   end record with Put_Image => Put_Image;
520
521   procedure Put_Image
522     (S : in out Ada.Strings.Text_Buffers.Root_Buffer_Type'Class; V : Set);
523
524   overriding procedure Adjust (Container : in out Set);
525
526   overriding procedure Finalize (Container : in out Set);
527
528   use HT_Types, HT_Types.Implementation;
529   use Ada.Finalization;
530   use Ada.Streams;
531
532   procedure Write
533     (Stream    : not null access Root_Stream_Type'Class;
534      Container : Set);
535
536   for Set'Write use Write;
537
538   procedure Read
539     (Stream    : not null access Root_Stream_Type'Class;
540      Container : out Set);
541
542   for Set'Read use Read;
543
544   type Set_Access is access all Set;
545   for Set_Access'Storage_Size use 0;
546
547   type Cursor is record
548      Container : Set_Access;
549      --  Access to this cursor's container
550
551      Node      : Node_Access;
552      --  Access to the node pointed to by this cursor
553
554      Position  : Hash_Type := Hash_Type'Last;
555      --  Position of the node in the buckets of the container. If this is
556      --  equal to Hash_Type'Last, then it will not be used. Position is
557      --  not requried by the implementation, but improves the efficiency
558      --  of various operations.
559      --
560      --  However, this value must be maintained so that the predefined
561      --  equality operation acts as required by RM A.18.7-17/2, which
562      --  states: "The predefined "=" operator for type Cursor returns True
563      --  if both cursors are No_Element, or designate the same element
564      --  in the same container."
565   end record;
566
567   procedure Write
568     (Stream : not null access Root_Stream_Type'Class;
569      Item   : Cursor);
570
571   for Cursor'Write use Write;
572
573   procedure Read
574     (Stream : not null access Root_Stream_Type'Class;
575      Item   : out Cursor);
576
577   for Cursor'Read use Read;
578
579   subtype Reference_Control_Type is Implementation.Reference_Control_Type;
580   --  It is necessary to rename this here, so that the compiler can find it
581
582   type Constant_Reference_Type
583     (Element : not null access constant Element_Type) is
584      record
585         Control : Reference_Control_Type :=
586           raise Program_Error with "uninitialized reference";
587         --  The RM says, "The default initialization of an object of
588         --  type Constant_Reference_Type or Reference_Type propagates
589         --  Program_Error."
590      end record;
591
592   procedure Read
593     (Stream : not null access Root_Stream_Type'Class;
594      Item   : out Constant_Reference_Type);
595
596   for Constant_Reference_Type'Read use Read;
597
598   procedure Write
599     (Stream : not null access Root_Stream_Type'Class;
600      Item   : Constant_Reference_Type);
601
602   for Constant_Reference_Type'Write use Write;
603
604   --  Three operations are used to optimize in the expansion of "for ... of"
605   --  loops: the Next(Cursor) procedure in the visible part, and the following
606   --  Pseudo_Reference and Get_Element_Access functions. See Sem_Ch5 for
607   --  details.
608
609   function Pseudo_Reference
610     (Container : aliased Set'Class) return Reference_Control_Type;
611   pragma Inline (Pseudo_Reference);
612   --  Creates an object of type Reference_Control_Type pointing to the
613   --  container, and increments the Lock. Finalization of this object will
614   --  decrement the Lock.
615
616   type Element_Access is access all Element_Type with
617     Storage_Size => 0;
618
619   function Get_Element_Access
620     (Position : Cursor) return not null Element_Access;
621   --  Returns a pointer to the element designated by Position.
622
623   Empty_Set : constant Set := (Controlled with others => <>);
624
625   No_Element : constant Cursor :=
626     (Container => null, Node => null, Position => Hash_Type'Last);
627
628   type Iterator is new Limited_Controlled and
629     Set_Iterator_Interfaces.Forward_Iterator with
630   record
631      Container : Set_Access;
632   end record
633     with Disable_Controlled => not T_Check;
634
635   overriding function First (Object : Iterator) return Cursor;
636
637   overriding function Next
638     (Object   : Iterator;
639      Position : Cursor) return Cursor;
640   overriding procedure Finalize (Object : in out Iterator);
641
642end Ada.Containers.Hashed_Sets;
643