1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- ADA.CONTAINERS.INDEFINITE_HASHED_MAPS --
9 -- Copyright (C) 2004-2012, 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 with Ada
.Containers
.Hash_Tables
.Generic_Operations
;
31 pragma Elaborate_All
(Ada
.Containers
.Hash_Tables
.Generic_Operations
);
33 with Ada
.Containers
.Hash_Tables
.Generic_Keys
;
34 pragma Elaborate_All
(Ada
.Containers
.Hash_Tables
.Generic_Keys
);
36 with Ada
.Unchecked_Deallocation
;
38 with System
; use type System
.Address
;
40 package body Ada
.Containers
.Indefinite_Hashed_Maps
is
43 new Ada
.Unchecked_Deallocation
(Key_Type
, Key_Access
);
45 procedure Free_Element
is
46 new Ada
.Unchecked_Deallocation
(Element_Type
, Element_Access
);
48 type Iterator
is new Limited_Controlled
and
49 Map_Iterator_Interfaces
.Forward_Iterator
with
51 Container
: Map_Access
;
54 overriding
procedure Finalize
(Object
: in out Iterator
);
56 overriding
function First
(Object
: Iterator
) return Cursor
;
58 overriding
function Next
60 Position
: Cursor
) return Cursor
;
62 -----------------------
63 -- Local Subprograms --
64 -----------------------
66 function Copy_Node
(Node
: Node_Access
) return Node_Access
;
67 pragma Inline
(Copy_Node
);
69 function Equivalent_Key_Node
71 Node
: Node_Access
) return Boolean;
72 pragma Inline
(Equivalent_Key_Node
);
74 function Find_Equal_Key
75 (R_HT
: Hash_Table_Type
;
76 L_Node
: Node_Access
) return Boolean;
78 procedure Free
(X
: in out Node_Access
);
79 -- pragma Inline (Free);
81 function Hash_Node
(Node
: Node_Access
) return Hash_Type
;
82 pragma Inline
(Hash_Node
);
84 function Next
(Node
: Node_Access
) return Node_Access
;
88 (Stream
: not null access Root_Stream_Type
'Class) return Node_Access
;
90 procedure Set_Next
(Node
: Node_Access
; Next
: Node_Access
);
91 pragma Inline
(Set_Next
);
93 function Vet
(Position
: Cursor
) return Boolean;
96 (Stream
: not null access Root_Stream_Type
'Class;
99 --------------------------
100 -- Local Instantiations --
101 --------------------------
103 package HT_Ops
is new Ada
.Containers
.Hash_Tables
.Generic_Operations
104 (HT_Types
=> HT_Types
,
105 Hash_Node
=> Hash_Node
,
107 Set_Next
=> Set_Next
,
108 Copy_Node
=> Copy_Node
,
111 package Key_Ops
is new Hash_Tables
.Generic_Keys
112 (HT_Types
=> HT_Types
,
114 Set_Next
=> Set_Next
,
115 Key_Type
=> Key_Type
,
117 Equivalent_Keys
=> Equivalent_Key_Node
);
123 function Is_Equal
is new HT_Ops
.Generic_Equal
(Find_Equal_Key
);
125 overriding
function "=" (Left
, Right
: Map
) return Boolean is
127 return Is_Equal
(Left
.HT
, Right
.HT
);
134 procedure Adjust
(Container
: in out Map
) is
136 HT_Ops
.Adjust
(Container
.HT
);
139 procedure Adjust
(Control
: in out Reference_Control_Type
) is
141 if Control
.Container
/= null then
143 M
: Map
renames Control
.Container
.all;
144 HT
: Hash_Table_Type
renames M
.HT
'Unrestricted_Access.all;
145 B
: Natural renames HT
.Busy
;
146 L
: Natural renames HT
.Lock
;
158 procedure Assign
(Target
: in out Map
; Source
: Map
) is
159 procedure Insert_Item
(Node
: Node_Access
);
160 pragma Inline
(Insert_Item
);
162 procedure Insert_Items
is new HT_Ops
.Generic_Iteration
(Insert_Item
);
168 procedure Insert_Item
(Node
: Node_Access
) is
170 Target
.Insert
(Key
=> Node
.Key
.all, New_Item
=> Node
.Element
.all);
173 -- Start of processing for Assign
176 if Target
'Address = Source
'Address then
182 if Target
.Capacity
< Source
.Length
then
183 Target
.Reserve_Capacity
(Source
.Length
);
186 Insert_Items
(Target
.HT
);
193 function Capacity
(Container
: Map
) return Count_Type
is
195 return HT_Ops
.Capacity
(Container
.HT
);
202 procedure Clear
(Container
: in out Map
) is
204 HT_Ops
.Clear
(Container
.HT
);
207 ------------------------
208 -- Constant_Reference --
209 ------------------------
211 function Constant_Reference
212 (Container
: aliased Map
;
213 Position
: Cursor
) return Constant_Reference_Type
216 if Position
.Container
= null then
217 raise Constraint_Error
with
218 "Position cursor has no element";
221 if Position
.Container
/= Container
'Unrestricted_Access then
222 raise Program_Error
with
223 "Position cursor designates wrong map";
226 if Position
.Node
.Element
= null then
227 raise Program_Error
with
228 "Position cursor has no element";
233 "Position cursor in Constant_Reference is bad");
236 M
: Map
renames Position
.Container
.all;
237 HT
: Hash_Table_Type
renames M
.HT
'Unrestricted_Access.all;
238 B
: Natural renames HT
.Busy
;
239 L
: Natural renames HT
.Lock
;
241 return R
: constant Constant_Reference_Type
:=
242 (Element
=> Position
.Node
.Element
.all'Access,
244 (Controlled
with Container
'Unrestricted_Access))
250 end Constant_Reference
;
252 function Constant_Reference
253 (Container
: aliased Map
;
254 Key
: Key_Type
) return Constant_Reference_Type
256 Node
: constant Node_Access
:= Key_Ops
.Find
(Container
.HT
, Key
);
260 raise Constraint_Error
with "key not in map";
263 if Node
.Element
= null then
264 raise Program_Error
with "key has no element";
268 M
: Map
renames Container
'Unrestricted_Access.all;
269 HT
: Hash_Table_Type
renames M
.HT
'Unrestricted_Access.all;
270 B
: Natural renames HT
.Busy
;
271 L
: Natural renames HT
.Lock
;
273 return R
: constant Constant_Reference_Type
:=
274 (Element
=> Node
.Element
.all'Access,
276 (Controlled
with Container
'Unrestricted_Access))
282 end Constant_Reference
;
288 function Contains
(Container
: Map
; Key
: Key_Type
) return Boolean is
290 return Find
(Container
, Key
) /= No_Element
;
299 Capacity
: Count_Type
:= 0) return Map
307 elsif Capacity
>= Source
.Length
then
312 with "Requested capacity is less than Source length";
315 return Target
: Map
do
316 Target
.Reserve_Capacity
(C
);
317 Target
.Assign
(Source
);
325 function Copy_Node
(Node
: Node_Access
) return Node_Access
is
326 K
: Key_Access
:= new Key_Type
'(Node.Key.all);
330 E := new Element_Type'(Node
.Element
.all);
331 return new Node_Type
'(K, E, null);
344 procedure Delete (Container : in out Map; Key : Key_Type) is
348 Key_Ops.Delete_Key_Sans_Free (Container.HT, Key, X);
351 raise Constraint_Error with "attempt to delete key not in map";
357 procedure Delete (Container : in out Map; Position : in out Cursor) is
359 if Position.Node = null then
360 raise Constraint_Error with
361 "Position cursor of Delete equals No_Element";
364 if Position.Container /= Container'Unrestricted_Access then
365 raise Program_Error with
366 "Position cursor of Delete designates wrong map";
369 if Container.HT.Busy > 0 then
370 raise Program_Error with
371 "Delete attempted to tamper with cursors (map is busy)";
374 pragma Assert (Vet (Position), "bad cursor in Delete");
376 HT_Ops.Delete_Node_Sans_Free (Container.HT, Position.Node);
378 Free (Position.Node);
379 Position.Container := null;
386 function Element (Container : Map; Key : Key_Type) return Element_Type is
387 Node : constant Node_Access := Key_Ops.Find (Container.HT, Key);
391 raise Constraint_Error with
392 "no element available because key not in map";
395 return Node.Element.all;
398 function Element (Position : Cursor) return Element_Type is
400 if Position.Node = null then
401 raise Constraint_Error with
402 "Position cursor of function Element equals No_Element";
405 if Position.Node.Element = null then
406 raise Program_Error with
407 "Position cursor of function Element is bad";
410 pragma Assert (Vet (Position), "bad cursor in function Element");
412 return Position.Node.Element.all;
415 -------------------------
416 -- Equivalent_Key_Node --
417 -------------------------
419 function Equivalent_Key_Node
421 Node : Node_Access) return Boolean
424 return Equivalent_Keys (Key, Node.Key.all);
425 end Equivalent_Key_Node;
427 ---------------------
428 -- Equivalent_Keys --
429 ---------------------
431 function Equivalent_Keys (Left, Right : Cursor) return Boolean is
433 if Left.Node = null then
434 raise Constraint_Error with
435 "Left cursor of Equivalent_Keys equals No_Element";
438 if Right.Node = null then
439 raise Constraint_Error with
440 "Right cursor of Equivalent_Keys equals No_Element";
443 if Left.Node.Key = null then
444 raise Program_Error with
445 "Left cursor of Equivalent_Keys is bad";
448 if Right.Node.Key = null then
449 raise Program_Error with
450 "Right cursor of Equivalent_Keys is bad";
453 pragma Assert (Vet (Left), "bad Left cursor in Equivalent_Keys");
454 pragma Assert (Vet (Right), "bad Right cursor in Equivalent_Keys");
456 return Equivalent_Keys (Left.Node.Key.all, Right.Node.Key.all);
459 function Equivalent_Keys
461 Right : Key_Type) return Boolean
464 if Left.Node = null then
465 raise Constraint_Error with
466 "Left cursor of Equivalent_Keys equals No_Element";
469 if Left.Node.Key = null then
470 raise Program_Error with
471 "Left cursor of Equivalent_Keys is bad";
474 pragma Assert (Vet (Left), "bad Left cursor in Equivalent_Keys");
476 return Equivalent_Keys (Left.Node.Key.all, Right);
479 function Equivalent_Keys
481 Right : Cursor) return Boolean
484 if Right.Node = null then
485 raise Constraint_Error with
486 "Right cursor of Equivalent_Keys equals No_Element";
489 if Right.Node.Key = null then
490 raise Program_Error with
491 "Right cursor of Equivalent_Keys is bad";
494 pragma Assert (Vet (Right), "bad Right cursor in Equivalent_Keys");
496 return Equivalent_Keys (Left, Right.Node.Key.all);
503 procedure Exclude (Container : in out Map; Key : Key_Type) is
506 Key_Ops.Delete_Key_Sans_Free (Container.HT, Key, X);
514 procedure Finalize (Container : in out Map) is
516 HT_Ops.Finalize (Container.HT);
519 procedure Finalize (Object : in out Iterator) is
521 if Object.Container /= null then
523 B : Natural renames Object.Container.all.HT.Busy;
530 procedure Finalize (Control : in out Reference_Control_Type) is
532 if Control.Container /= null then
534 M : Map renames Control.Container.all;
535 HT : Hash_Table_Type renames M.HT'Unrestricted_Access.all;
536 B : Natural renames HT.Busy;
537 L : Natural renames HT.Lock;
543 Control.Container := null;
551 function Find (Container : Map; Key : Key_Type) return Cursor is
552 Node : constant Node_Access := Key_Ops.Find (Container.HT, Key);
559 return Cursor'(Container
'Unrestricted_Access, Node
);
566 function Find_Equal_Key
567 (R_HT
: Hash_Table_Type
;
568 L_Node
: Node_Access
) return Boolean
570 R_Index
: constant Hash_Type
:= Key_Ops
.Index
(R_HT
, L_Node
.Key
.all);
571 R_Node
: Node_Access
:= R_HT
.Buckets
(R_Index
);
574 while R_Node
/= null loop
575 if Equivalent_Keys
(L_Node
.Key
.all, R_Node
.Key
.all) then
576 return L_Node
.Element
.all = R_Node
.Element
.all;
579 R_Node
:= R_Node
.Next
;
589 function First
(Container
: Map
) return Cursor
is
590 Node
: constant Node_Access
:= HT_Ops
.First
(Container
.HT
);
595 return Cursor
'(Container'Unrestricted_Access, Node);
599 function First (Object : Iterator) return Cursor is
601 return Object.Container.First;
608 procedure Free (X : in out Node_Access) is
609 procedure Deallocate is
610 new Ada.Unchecked_Deallocation (Node_Type, Node_Access);
617 X.Next := X; -- detect mischief (in Vet)
626 Free_Element (X.Element);
637 Free_Element (X.Element);
653 function Has_Element (Position : Cursor) return Boolean is
655 pragma Assert (Vet (Position), "bad cursor in Has_Element");
656 return Position.Node /= null;
663 function Hash_Node (Node : Node_Access) return Hash_Type is
665 return Hash (Node.Key.all);
673 (Container : in out Map;
675 New_Item : Element_Type)
684 Insert (Container, Key, New_Item, Position, Inserted);
687 if Container.HT.Lock > 0 then
688 raise Program_Error with
689 "Include attempted to tamper with elements (map is locked)";
692 K := Position.Node.Key;
693 E := Position.Node.Element;
695 Position.Node.Key := new Key_Type'(Key
);
698 -- The element allocator may need an accessibility check in the
699 -- case the actual type is class-wide or has access discriminants
700 -- (see RM 4.8(10.1) and AI12-0035).
702 pragma Unsuppress
(Accessibility_Check
);
705 Position
.Node
.Element
:= new Element_Type
'(New_Item);
723 (Container : in out Map;
725 New_Item : Element_Type;
726 Position : out Cursor;
727 Inserted : out Boolean)
729 function New_Node (Next : Node_Access) return Node_Access;
731 procedure Local_Insert is
732 new Key_Ops.Generic_Conditional_Insert (New_Node);
738 function New_Node (Next : Node_Access) return Node_Access is
739 K : Key_Access := new Key_Type'(Key
);
742 -- The element allocator may need an accessibility check in the case
743 -- the actual type is class-wide or has access discriminants (see
744 -- RM 4.8(10.1) and AI12-0035).
746 pragma Unsuppress
(Accessibility_Check
);
749 E
:= new Element_Type
'(New_Item);
750 return new Node_Type'(K
, E
, Next
);
759 HT
: Hash_Table_Type
renames Container
.HT
;
761 -- Start of processing for Insert
764 if HT_Ops
.Capacity
(HT
) = 0 then
765 HT_Ops
.Reserve_Capacity
(HT
, 1);
768 Local_Insert
(HT
, Key
, Position
.Node
, Inserted
);
771 and then HT
.Length
> HT_Ops
.Capacity
(HT
)
773 HT_Ops
.Reserve_Capacity
(HT
, HT
.Length
);
776 Position
.Container
:= Container
'Unchecked_Access;
780 (Container
: in out Map
;
782 New_Item
: Element_Type
)
785 pragma Unreferenced
(Position
);
790 Insert
(Container
, Key
, New_Item
, Position
, Inserted
);
793 raise Constraint_Error
with
794 "attempt to insert key already in map";
802 function Is_Empty
(Container
: Map
) return Boolean is
804 return Container
.HT
.Length
= 0;
813 Process
: not null access procedure (Position
: Cursor
))
815 procedure Process_Node
(Node
: Node_Access
);
816 pragma Inline
(Process_Node
);
818 procedure Local_Iterate
is
819 new HT_Ops
.Generic_Iteration
(Process_Node
);
825 procedure Process_Node
(Node
: Node_Access
) is
827 Process
(Cursor
'(Container'Unrestricted_Access, Node));
830 B : Natural renames Container'Unrestricted_Access.all.HT.Busy;
832 -- Start of processing Iterate
838 Local_Iterate (Container.HT);
849 (Container : Map) return Map_Iterator_Interfaces.Forward_Iterator'Class
851 B : Natural renames Container'Unrestricted_Access.all.HT.Busy;
853 return It : constant Iterator :=
854 (Limited_Controlled with
855 Container => Container'Unrestricted_Access)
865 function Key (Position : Cursor) return Key_Type is
867 if Position.Node = null then
868 raise Constraint_Error with
869 "Position cursor of function Key equals No_Element";
872 if Position.Node.Key = null then
873 raise Program_Error with
874 "Position cursor of function Key is bad";
877 pragma Assert (Vet (Position), "bad cursor in function Key");
879 return Position.Node.Key.all;
886 function Length (Container : Map) return Count_Type is
888 return Container.HT.Length;
896 (Target : in out Map;
900 HT_Ops.Move (Target => Target.HT, Source => Source.HT);
907 function Next (Node : Node_Access) return Node_Access is
912 procedure Next (Position : in out Cursor) is
914 Position := Next (Position);
917 function Next (Position : Cursor) return Cursor is
919 if Position.Node = null then
923 if Position.Node.Key = null
924 or else Position.Node.Element = null
926 raise Program_Error with "Position cursor of Next is bad";
929 pragma Assert (Vet (Position), "Position cursor of Next is bad");
932 HT : Hash_Table_Type renames Position.Container.HT;
933 Node : constant Node_Access := HT_Ops.Next (HT, Position.Node);
938 return Cursor'(Position
.Container
, Node
);
943 function Next
(Object
: Iterator
; Position
: Cursor
) return Cursor
is
945 if Position
.Container
= null then
949 if Position
.Container
/= Object
.Container
then
950 raise Program_Error
with
951 "Position cursor of Next designates wrong map";
954 return Next
(Position
);
961 procedure Query_Element
963 Process
: not null access procedure (Key
: Key_Type
;
964 Element
: Element_Type
))
967 if Position
.Node
= null then
968 raise Constraint_Error
with
969 "Position cursor of Query_Element equals No_Element";
972 if Position
.Node
.Key
= null
973 or else Position
.Node
.Element
= null
975 raise Program_Error
with
976 "Position cursor of Query_Element is bad";
979 pragma Assert
(Vet
(Position
), "bad cursor in Query_Element");
982 M
: Map
renames Position
.Container
.all;
983 HT
: Hash_Table_Type
renames M
.HT
'Unrestricted_Access.all;
985 B
: Natural renames HT
.Busy
;
986 L
: Natural renames HT
.Lock
;
993 K
: Key_Type
renames Position
.Node
.Key
.all;
994 E
: Element_Type
renames Position
.Node
.Element
.all;
1014 procedure Read_Nodes
is new HT_Ops
.Generic_Read
(Read_Node
);
1017 (Stream
: not null access Root_Stream_Type
'Class;
1018 Container
: out Map
)
1021 Read_Nodes
(Stream
, Container
.HT
);
1025 (Stream
: not null access Root_Stream_Type
'Class;
1029 raise Program_Error
with "attempt to stream map cursor";
1033 (Stream
: not null access Root_Stream_Type
'Class;
1034 Item
: out Reference_Type
)
1037 raise Program_Error
with "attempt to stream reference";
1041 (Stream
: not null access Root_Stream_Type
'Class;
1042 Item
: out Constant_Reference_Type
)
1045 raise Program_Error
with "attempt to stream reference";
1053 (Stream
: not null access Root_Stream_Type
'Class) return Node_Access
1055 Node
: Node_Access
:= new Node_Type
;
1059 Node
.Key
:= new Key_Type
'(Key_Type'Input (Stream));
1067 Node.Element := new Element_Type'(Element_Type
'Input (Stream
));
1070 Free_Key
(Node
.Key
);
1083 (Container
: aliased in out Map
;
1084 Position
: Cursor
) return Reference_Type
1087 if Position
.Container
= null then
1088 raise Constraint_Error
with
1089 "Position cursor has no element";
1092 if Position
.Container
/= Container
'Unrestricted_Access then
1093 raise Program_Error
with
1094 "Position cursor designates wrong map";
1097 if Position
.Node
.Element
= null then
1098 raise Program_Error
with
1099 "Position cursor has no element";
1104 "Position cursor in function Reference is bad");
1107 M
: Map
renames Position
.Container
.all;
1108 HT
: Hash_Table_Type
renames M
.HT
'Unrestricted_Access.all;
1109 B
: Natural renames HT
.Busy
;
1110 L
: Natural renames HT
.Lock
;
1112 return R
: constant Reference_Type
:=
1113 (Element
=> Position
.Node
.Element
.all'Access,
1114 Control
=> (Controlled
with Position
.Container
))
1123 (Container
: aliased in out Map
;
1124 Key
: Key_Type
) return Reference_Type
1126 Node
: constant Node_Access
:= Key_Ops
.Find
(Container
.HT
, Key
);
1130 raise Constraint_Error
with "key not in map";
1133 if Node
.Element
= null then
1134 raise Program_Error
with "key has no element";
1138 M
: Map
renames Container
'Unrestricted_Access.all;
1139 HT
: Hash_Table_Type
renames M
.HT
'Unrestricted_Access.all;
1140 B
: Natural renames HT
.Busy
;
1141 L
: Natural renames HT
.Lock
;
1143 return R
: constant Reference_Type
:=
1144 (Element
=> Node
.Element
.all'Access,
1146 (Controlled
with Container
'Unrestricted_Access))
1159 (Container
: in out Map
;
1161 New_Item
: Element_Type
)
1163 Node
: constant Node_Access
:= Key_Ops
.Find
(Container
.HT
, Key
);
1170 raise Constraint_Error
with
1171 "attempt to replace key not in map";
1174 if Container
.HT
.Lock
> 0 then
1175 raise Program_Error
with
1176 "Replace attempted to tamper with elements (map is locked)";
1182 Node
.Key
:= new Key_Type
'(Key);
1185 -- The element allocator may need an accessibility check in the case
1186 -- the actual type is class-wide or has access discriminants (see
1187 -- RM 4.8(10.1) and AI12-0035).
1189 pragma Unsuppress (Accessibility_Check);
1192 Node.Element := new Element_Type'(New_Item
);
1204 ---------------------
1205 -- Replace_Element --
1206 ---------------------
1208 procedure Replace_Element
1209 (Container
: in out Map
;
1211 New_Item
: Element_Type
)
1214 if Position
.Node
= null then
1215 raise Constraint_Error
with
1216 "Position cursor of Replace_Element equals No_Element";
1219 if Position
.Node
.Key
= null
1220 or else Position
.Node
.Element
= null
1222 raise Program_Error
with
1223 "Position cursor of Replace_Element is bad";
1226 if Position
.Container
/= Container
'Unrestricted_Access then
1227 raise Program_Error
with
1228 "Position cursor of Replace_Element designates wrong map";
1231 if Position
.Container
.HT
.Lock
> 0 then
1232 raise Program_Error
with
1233 "Replace_Element attempted to tamper with elements (map is locked)";
1236 pragma Assert
(Vet
(Position
), "bad cursor in Replace_Element");
1239 X
: Element_Access
:= Position
.Node
.Element
;
1241 -- The element allocator may need an accessibility check in the case
1242 -- the actual type is class-wide or has access discriminants (see
1243 -- RM 4.8(10.1) and AI12-0035).
1245 pragma Unsuppress
(Accessibility_Check
);
1248 Position
.Node
.Element
:= new Element_Type
'(New_Item);
1251 end Replace_Element;
1253 ----------------------
1254 -- Reserve_Capacity --
1255 ----------------------
1257 procedure Reserve_Capacity
1258 (Container : in out Map;
1259 Capacity : Count_Type)
1262 HT_Ops.Reserve_Capacity (Container.HT, Capacity);
1263 end Reserve_Capacity;
1269 procedure Set_Next (Node : Node_Access; Next : Node_Access) is
1274 --------------------
1275 -- Update_Element --
1276 --------------------
1278 procedure Update_Element
1279 (Container : in out Map;
1281 Process : not null access procedure (Key : Key_Type;
1282 Element : in out Element_Type))
1285 if Position.Node = null then
1286 raise Constraint_Error with
1287 "Position cursor of Update_Element equals No_Element";
1290 if Position.Node.Key = null
1291 or else Position.Node.Element = null
1293 raise Program_Error with
1294 "Position cursor of Update_Element is bad";
1297 if Position.Container /= Container'Unrestricted_Access then
1298 raise Program_Error with
1299 "Position cursor of Update_Element designates wrong map";
1302 pragma Assert (Vet (Position), "bad cursor in Update_Element");
1305 HT : Hash_Table_Type renames Container.HT;
1307 B : Natural renames HT.Busy;
1308 L : Natural renames HT.Lock;
1315 K : Key_Type renames Position.Node.Key.all;
1316 E : Element_Type renames Position.Node.Element.all;
1337 function Vet (Position : Cursor) return Boolean is
1339 if Position.Node = null then
1340 return Position.Container = null;
1343 if Position.Container = null then
1347 if Position.Node.Next = Position.Node then
1351 if Position.Node.Key = null then
1355 if Position.Node.Element = null then
1360 HT : Hash_Table_Type renames Position.Container.HT;
1364 if HT.Length = 0 then
1368 if HT.Buckets = null
1369 or else HT.Buckets'Length = 0
1374 X := HT.Buckets (Key_Ops.Index (HT, Position.Node.Key.all));
1376 for J in 1 .. HT.Length loop
1377 if X = Position.Node then
1385 if X = X.Next then -- to prevent unnecessary looping
1400 procedure Write_Nodes is new HT_Ops.Generic_Write (Write_Node);
1403 (Stream : not null access Root_Stream_Type'Class;
1407 Write_Nodes (Stream, Container.HT);
1411 (Stream : not null access Root_Stream_Type'Class;
1415 raise Program_Error with "attempt to stream map cursor";
1419 (Stream : not null access Root_Stream_Type'Class;
1420 Item : Reference_Type)
1423 raise Program_Error with "attempt to stream reference";
1427 (Stream : not null access Root_Stream_Type'Class;
1428 Item : Constant_Reference_Type)
1431 raise Program_Error with "attempt to stream reference";
1438 procedure Write_Node
1439 (Stream : not null access Root_Stream_Type'Class;
1443 Key_Type'Output (Stream, Node.Key.all);
1444 Element_Type'Output (Stream, Node.Element.all);
1447 end Ada.Containers.Indefinite_Hashed_Maps;