1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- ADA.CONTAINERS.RED_BLACK_TREES.GENERIC_SET_OPERATIONS --
9 -- Copyright (C) 2004-2018, Free Software Foundation, Inc. --
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. --
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. --
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/>. --
27 -- This unit was originally developed by Matthew J Heaney. --
28 ------------------------------------------------------------------------------
30 -- Tree_Type is used to implement ordered containers. This package declares
31 -- set-based tree operations.
33 with Ada
.Containers
.Red_Black_Trees
.Generic_Operations
;
36 with package Tree_Operations
is new Generic_Operations
(<>);
38 use Tree_Operations
.Tree_Types
, Tree_Operations
.Tree_Types
.Implementation
;
40 with procedure Insert_With_Hint
41 (Dst_Tree
: in out Tree_Type
;
42 Dst_Hint
: Node_Access
;
43 Src_Node
: Node_Access
;
44 Dst_Node
: out Node_Access
);
46 with function Copy_Tree
(Source_Root
: Node_Access
)
49 with procedure Delete_Tree
(X
: in out Node_Access
);
51 with function Is_Less
(Left
, Right
: Node_Access
) return Boolean;
53 with procedure Free
(X
: in out Node_Access
);
55 package Ada
.Containers
.Red_Black_Trees
.Generic_Set_Operations
is
58 procedure Union
(Target
: in out Tree_Type
; Source
: Tree_Type
);
59 -- Attempts to insert each element of Source in Target. If Target is
60 -- busy then Program_Error is raised. We say "attempts" here because
61 -- if these are unique-element sets, then the insertion should fail
62 -- (not insert a new item) when the insertion item from Source is
63 -- equivalent to an item already in Target. If these are multisets
64 -- then of course the attempt should always succeed.
66 function Union
(Left
, Right
: Tree_Type
) return Tree_Type
;
67 -- Makes a copy of Left, and attempts to insert each element of
68 -- Right into the copy, then returns the copy.
70 procedure Intersection
(Target
: in out Tree_Type
; Source
: Tree_Type
);
71 -- Removes elements from Target that are not equivalent to items in
72 -- Source. If Target is busy then Program_Error is raised.
74 function Intersection
(Left
, Right
: Tree_Type
) return Tree_Type
;
75 -- Returns a set comprising all the items in Left equivalent to items in
78 procedure Difference
(Target
: in out Tree_Type
; Source
: Tree_Type
);
79 -- Removes elements from Target that are equivalent to items in Source. If
80 -- Target is busy then Program_Error is raised.
82 function Difference
(Left
, Right
: Tree_Type
) return Tree_Type
;
83 -- Returns a set comprising all the items in Left not equivalent to items
86 procedure Symmetric_Difference
87 (Target
: in out Tree_Type
;
89 -- Removes from Target elements that are equivalent to items in Source, and
90 -- inserts into Target items from Source not equivalent elements in
91 -- Target. If Target is busy then Program_Error is raised.
93 function Symmetric_Difference
(Left
, Right
: Tree_Type
) return Tree_Type
;
94 -- Returns a set comprising the union of the elements in Left not
95 -- equivalent to items in Right, and the elements in Right not equivalent
98 function Is_Subset
(Subset
: Tree_Type
; Of_Set
: Tree_Type
) return Boolean;
99 -- Returns False if Subset contains at least one element not equivalent to
100 -- any item in Of_Set; returns True otherwise.
102 function Overlap
(Left
, Right
: Tree_Type
) return Boolean;
103 -- Returns True if at least one element of Left is equivalent to an item in
104 -- Right; returns False otherwise.
106 end Ada
.Containers
.Red_Black_Trees
.Generic_Set_Operations
;