1------------------------------------------------------------------------------
2--                                                                          --
3--                         GNAT RUN-TIME COMPONENTS                         --
4--                                                                          --
5--                            G N A T . S E T S                             --
6--                                                                          --
7--                                 B o d y                                  --
8--                                                                          --
9--                        Copyright (C) 2018-2019, AdaCore                  --
10--                                                                          --
11-- GNAT is free software;  you can  redistribute it  and/or modify it under --
12-- terms of the  GNU General Public License as published  by the Free Soft- --
13-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
14-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
17--                                                                          --
18-- As a special exception under Section 7 of GPL version 3, you are granted --
19-- additional permissions described in the GCC Runtime Library Exception,   --
20-- version 3.1, as published by the Free Software Foundation.               --
21--                                                                          --
22-- You should have received a copy of the GNU General Public License and    --
23-- a copy of the GCC Runtime Library Exception along with this program;     --
24-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
25-- <http://www.gnu.org/licenses/>.                                          --
26--                                                                          --
27-- GNAT was originally developed  by the GNAT team at  New York University. --
28-- Extensive contributions were provided by Ada Core Technologies Inc.      --
29--                                                                          --
30------------------------------------------------------------------------------
31
32package body GNAT.Sets is
33
34   ---------------------
35   -- Membership_Sets --
36   ---------------------
37
38   package body Membership_Sets is
39
40      --------------
41      -- Contains --
42      --------------
43
44      function Contains
45        (S    : Membership_Set;
46         Elem : Element_Type) return Boolean
47      is
48      begin
49         return Hashed_Set.Contains (Hashed_Set.Dynamic_Hash_Table (S), Elem);
50      end Contains;
51
52      ------------
53      -- Create --
54      ------------
55
56      function Create (Initial_Size : Positive) return Membership_Set is
57      begin
58         return Membership_Set (Hashed_Set.Create (Initial_Size));
59      end Create;
60
61      ------------
62      -- Delete --
63      ------------
64
65      procedure Delete (S : Membership_Set; Elem : Element_Type) is
66      begin
67         Hashed_Set.Delete (Hashed_Set.Dynamic_Hash_Table (S), Elem);
68      end Delete;
69
70      -------------
71      -- Destroy --
72      -------------
73
74      procedure Destroy (B : in out Boolean) is
75         pragma Unreferenced (B);
76      begin
77         null;
78      end Destroy;
79
80      -------------
81      -- Destroy --
82      -------------
83
84      procedure Destroy (S : in out Membership_Set) is
85      begin
86         Hashed_Set.Destroy (Hashed_Set.Dynamic_Hash_Table (S));
87      end Destroy;
88
89      --------------
90      -- Has_Next --
91      --------------
92
93      function Has_Next (Iter : Iterator) return Boolean is
94      begin
95         return Hashed_Set.Has_Next (Hashed_Set.Iterator (Iter));
96      end Has_Next;
97
98      ------------
99      -- Insert --
100      ------------
101
102      procedure Insert
103        (S    : Membership_Set;
104         Elem : Element_Type)
105      is
106      begin
107         Hashed_Set.Put (Hashed_Set.Dynamic_Hash_Table (S), Elem, True);
108      end Insert;
109
110      --------------
111      -- Is_Empty --
112      --------------
113
114      function Is_Empty (S : Membership_Set) return Boolean is
115      begin
116         return Hashed_Set.Is_Empty (Hashed_Set.Dynamic_Hash_Table (S));
117      end Is_Empty;
118
119      -------------
120      -- Iterate --
121      -------------
122
123      function Iterate (S : Membership_Set) return Iterator is
124      begin
125         return
126           Iterator (Hashed_Set.Iterate (Hashed_Set.Dynamic_Hash_Table (S)));
127      end Iterate;
128
129      ----------
130      -- Next --
131      ----------
132
133      procedure Next
134        (Iter : in out Iterator;
135         Elem : out Element_Type)
136      is
137      begin
138         Hashed_Set.Next (Hashed_Set.Iterator (Iter), Elem);
139      end Next;
140
141      -------------
142      -- Present --
143      -------------
144
145      function Present (S : Membership_Set) return Boolean is
146      begin
147         return Hashed_Set.Present (Hashed_Set.Dynamic_Hash_Table (S));
148      end Present;
149
150      -----------
151      -- Reset --
152      -----------
153
154      procedure Reset (S : Membership_Set) is
155      begin
156         Hashed_Set.Reset (Hashed_Set.Dynamic_Hash_Table (S));
157      end Reset;
158
159      ----------
160      -- Size --
161      ----------
162
163      function Size (S : Membership_Set) return Natural is
164      begin
165         return Hashed_Set.Size (Hashed_Set.Dynamic_Hash_Table (S));
166      end Size;
167   end Membership_Sets;
168
169end GNAT.Sets;
170