2 -- { dg-options "-gnata" }
5 with Ada
.Containers
.Hashed_Sets
;
6 with Ada
.Containers
.Hashed_Maps
;
7 with Ada
.Containers
.Indefinite_Hashed_Sets
;
8 with Ada
.Containers
.Indefinite_Hashed_Maps
;
10 procedure Containers2
is
11 -- Check that Cursors of the hashed containers follow the correct
12 -- predefined equality rules - that two Cursors to the same element
13 -- are equal, one one is obtained through, for example, iteration,
14 -- and the other is obtained through a search
16 subtype Definite_Name
is String (1 .. 5);
25 function Equivalent_Item
(Left
, Right
: Named_Item
) return Boolean
26 is (Left
.Name
= Right
.Name
);
28 function DI_Hash
(Item
: Named_Item
) return Ada
.Containers
.Hash_Type
29 is (Ada
.Strings
.Hash
(Item
.Name
));
31 package HS
is new Ada
.Containers
.Hashed_Sets
32 (Element_Type
=> Named_Item
,
34 Equivalent_Elements
=> Equivalent_Item
);
36 package IHS
is new Ada
.Containers
.Indefinite_Hashed_Sets
37 (Element_Type
=> Named_Item
,
39 Equivalent_Elements
=> Equivalent_Item
);
41 package HM
is new Ada
.Containers
.Hashed_Maps
42 (Key_Type
=> Definite_Name
,
43 Element_Type
=> Integer,
44 Hash
=> Ada
.Strings
.Hash
,
45 Equivalent_Keys
=> "=");
47 package IHM
is new Ada
.Containers
.Indefinite_Hashed_Maps
48 (Key_Type
=> Definite_Name
,
49 Element_Type
=> Integer,
50 Hash
=> Ada
.Strings
.Hash
,
51 Equivalent_Keys
=> "=");
53 Item_Data
: constant array (1 .. 5) of Named_Item
54 := ((Name
=> "ABCDE", others => <>),
55 (Name
=> "FGHIJ", others => <>),
56 (Name
=> "KLMNO", others => <>),
57 (Name
=> "PQRST", others => <>),
58 (Name
=> "UVWXY", others => <>));
65 type HS_Cursor_Vec
is array (Item_Data
'Range) of HS
.Cursor
;
66 type IHS_Cursor_Vec
is array (Item_Data
'Range) of IHS
.Cursor
;
67 type HM_Cursor_Vec
is array (Item_Data
'Range) of HM
.Cursor
;
68 type IHM_Cursor_Vec
is array (Item_Data
'Range) of IHM
.Cursor
;
75 HS_Create_Cursors
: HS_Cursor_Vec
;
76 IHS_Create_Cursors
: IHS_Cursor_Vec
;
77 HM_Create_Cursors
: HM_Cursor_Vec
;
78 IHM_Create_Cursors
: IHM_Cursor_Vec
;
81 IHS_Index
: IHS
.Cursor
;
83 IHM_Index
: IHM
.Cursor
;
86 IHS_Find
: IHS
.Cursor
;
88 IHM_Find
: IHM
.Cursor
;
95 for I
in Item_Data
'Range loop
96 HSC
.Insert
(New_Item
=> Item_Data
(I
),
97 Position
=> HS_Create_Cursors
(I
),
98 Inserted
=> Inserted
);
100 pragma Assert
(Inserted
);
103 IHSC
.Insert
(New_Item
=> Item_Data
(I
),
104 Position
=> IHS_Create_Cursors
(I
),
105 Inserted
=> Inserted
);
107 pragma Assert
(Inserted
);
109 HMC
.Insert
(New_Item
=> Item_Data
(I
).Item
,
110 Key
=> Item_Data
(I
).Name
,
111 Position
=> HM_Create_Cursors
(I
),
112 Inserted
=> Inserted
);
114 pragma Assert
(Inserted
);
116 IHMC
.Insert
(New_Item
=> Item_Data
(I
).Item
,
117 Key
=> Item_Data
(I
).Name
,
118 Position
=> IHM_Create_Cursors
(I
),
119 Inserted
=> Inserted
);
121 pragma Assert
(Inserted
);
125 HS_Index
:= HSC
.First
;
126 IHS_Index
:= IHSC
.First
;
127 HM_Index
:= HMC
.First
;
128 IHM_Index
:= IHMC
.First
;
130 for I
in Item_Data
'Range loop
131 pragma Assert
(HS
.Has_Element
(HS_Index
));
132 pragma Assert
(IHS
.Has_Element
(IHS_Index
));
133 pragma Assert
(HM
.Has_Element
(HM_Index
));
134 pragma Assert
(IHM
.Has_Element
(IHM_Index
));
136 HS_Find
:= HSC
.Find
(Item_Data
(I
));
137 pragma Assert
(HS_Create_Cursors
(I
) = HS_Index
);
138 pragma Assert
(HS_Find
= HS_Index
);
140 IHS_Find
:= IHSC
.Find
(Item_Data
(I
));
141 pragma Assert
(IHS_Create_Cursors
(I
) = IHS_Index
);
142 pragma Assert
(IHS_Find
= IHS_Index
);
144 HM_Find
:= HMC
.Find
(Item_Data
(I
).Name
);
145 pragma Assert
(HM_Create_Cursors
(I
) = HM_Index
);
146 pragma Assert
(HM_Find
= HM_Index
);
148 IHM_Find
:= IHMC
.Find
(Item_Data
(I
).Name
);
149 pragma Assert
(IHM_Create_Cursors
(I
) = IHM_Index
);
150 pragma Assert
(IHM_Find
= IHM_Index
);
153 IHS
.Next
(IHS_Index
);
155 IHM
.Next
(IHM_Index
);