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_Set --
36   --------------------
37
38   package body Membership_Set is
39
40      --------------
41      -- Contains --
42      --------------
43
44      function Contains (S : Instance; Elem : Element_Type) return Boolean is
45      begin
46         return Hashed_Set.Get (Hashed_Set.Instance (S), Elem);
47      end Contains;
48
49      ------------
50      -- Create --
51      ------------
52
53      function Create (Initial_Size : Positive) return Instance is
54      begin
55         return Instance (Hashed_Set.Create (Initial_Size));
56      end Create;
57
58      ------------
59      -- Delete --
60      ------------
61
62      procedure Delete (S : Instance; Elem : Element_Type) is
63      begin
64         Hashed_Set.Delete (Hashed_Set.Instance (S), Elem);
65      end Delete;
66
67      -------------
68      -- Destroy --
69      -------------
70
71      procedure Destroy (S : in out Instance) is
72      begin
73         Hashed_Set.Destroy (Hashed_Set.Instance (S));
74      end Destroy;
75
76      --------------
77      -- Has_Next --
78      --------------
79
80      function Has_Next (Iter : Iterator) return Boolean is
81      begin
82         return Hashed_Set.Has_Next (Hashed_Set.Iterator (Iter));
83      end Has_Next;
84
85      ------------
86      -- Insert --
87      ------------
88
89      procedure Insert (S : Instance; Elem : Element_Type) is
90      begin
91         Hashed_Set.Put (Hashed_Set.Instance (S), Elem, True);
92      end Insert;
93
94      --------------
95      -- Is_Empty --
96      --------------
97
98      function Is_Empty (S : Instance) return Boolean is
99      begin
100         return Hashed_Set.Is_Empty (Hashed_Set.Instance (S));
101      end Is_Empty;
102
103      -------------
104      -- Iterate --
105      -------------
106
107      function Iterate (S : Instance) return Iterator is
108      begin
109         return Iterator (Hashed_Set.Iterate (Hashed_Set.Instance (S)));
110      end Iterate;
111
112      ----------
113      -- Next --
114      ----------
115
116      procedure Next (Iter : in out Iterator; Elem : out Element_Type) is
117      begin
118         Hashed_Set.Next (Hashed_Set.Iterator (Iter), Elem);
119      end Next;
120
121      ----------
122      -- Size --
123      ----------
124
125      function Size (S : Instance) return Natural is
126      begin
127         return Hashed_Set.Size (Hashed_Set.Instance (S));
128      end Size;
129   end Membership_Set;
130
131end GNAT.Sets;
132