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,
243 Control
=> (Controlled
with Container
'Unrestricted_Access))
249 end Constant_Reference
;
251 function Constant_Reference
252 (Container
: aliased Map
;
253 Key
: Key_Type
) return Constant_Reference_Type
255 Node
: constant Node_Access
:= Key_Ops
.Find
(Container
.HT
, Key
);
259 raise Constraint_Error
with "key not in map";
262 if Node
.Element
= null then
263 raise Program_Error
with "key has no element";
267 M
: Map
renames Container
'Unrestricted_Access.all;
268 HT
: Hash_Table_Type
renames M
.HT
'Unrestricted_Access.all;
269 B
: Natural renames HT
.Busy
;
270 L
: Natural renames HT
.Lock
;
272 return R
: constant Constant_Reference_Type
:=
273 (Element
=> Node
.Element
.all'Access,
274 Control
=> (Controlled
with Container
'Unrestricted_Access))
280 end Constant_Reference
;
286 function Contains
(Container
: Map
; Key
: Key_Type
) return Boolean is
288 return Find
(Container
, Key
) /= No_Element
;
297 Capacity
: Count_Type
:= 0) return Map
305 elsif Capacity
>= Source
.Length
then
310 with "Requested capacity is less than Source length";
313 return Target
: Map
do
314 Target
.Reserve_Capacity
(C
);
315 Target
.Assign
(Source
);
323 function Copy_Node
(Node
: Node_Access
) return Node_Access
is
324 K
: Key_Access
:= new Key_Type
'(Node.Key.all);
328 E := new Element_Type'(Node
.Element
.all);
329 return new Node_Type
'(K, E, null);
342 procedure Delete (Container : in out Map; Key : Key_Type) is
346 Key_Ops.Delete_Key_Sans_Free (Container.HT, Key, X);
349 raise Constraint_Error with "attempt to delete key not in map";
355 procedure Delete (Container : in out Map; Position : in out Cursor) is
357 if Position.Node = null then
358 raise Constraint_Error with
359 "Position cursor of Delete equals No_Element";
362 if Position.Container /= Container'Unrestricted_Access then
363 raise Program_Error with
364 "Position cursor of Delete designates wrong map";
367 if Container.HT.Busy > 0 then
368 raise Program_Error with
369 "Delete attempted to tamper with cursors (map is busy)";
372 pragma Assert (Vet (Position), "bad cursor in Delete");
374 HT_Ops.Delete_Node_Sans_Free (Container.HT, Position.Node);
376 Free (Position.Node);
377 Position.Container := null;
384 function Element (Container : Map; Key : Key_Type) return Element_Type is
385 Node : constant Node_Access := Key_Ops.Find (Container.HT, Key);
389 raise Constraint_Error with
390 "no element available because key not in map";
393 return Node.Element.all;
396 function Element (Position : Cursor) return Element_Type is
398 if Position.Node = null then
399 raise Constraint_Error with
400 "Position cursor of function Element equals No_Element";
403 if Position.Node.Element = null then
404 raise Program_Error with
405 "Position cursor of function Element is bad";
408 pragma Assert (Vet (Position), "bad cursor in function Element");
410 return Position.Node.Element.all;
413 -------------------------
414 -- Equivalent_Key_Node --
415 -------------------------
417 function Equivalent_Key_Node
419 Node : Node_Access) return Boolean
422 return Equivalent_Keys (Key, Node.Key.all);
423 end Equivalent_Key_Node;
425 ---------------------
426 -- Equivalent_Keys --
427 ---------------------
429 function Equivalent_Keys (Left, Right : Cursor) return Boolean is
431 if Left.Node = null then
432 raise Constraint_Error with
433 "Left cursor of Equivalent_Keys equals No_Element";
436 if Right.Node = null then
437 raise Constraint_Error with
438 "Right cursor of Equivalent_Keys equals No_Element";
441 if Left.Node.Key = null then
442 raise Program_Error with
443 "Left cursor of Equivalent_Keys is bad";
446 if Right.Node.Key = null then
447 raise Program_Error with
448 "Right cursor of Equivalent_Keys is bad";
451 pragma Assert (Vet (Left), "bad Left cursor in Equivalent_Keys");
452 pragma Assert (Vet (Right), "bad Right cursor in Equivalent_Keys");
454 return Equivalent_Keys (Left.Node.Key.all, Right.Node.Key.all);
457 function Equivalent_Keys
459 Right : Key_Type) return Boolean
462 if Left.Node = null then
463 raise Constraint_Error with
464 "Left cursor of Equivalent_Keys equals No_Element";
467 if Left.Node.Key = null then
468 raise Program_Error with
469 "Left cursor of Equivalent_Keys is bad";
472 pragma Assert (Vet (Left), "bad Left cursor in Equivalent_Keys");
474 return Equivalent_Keys (Left.Node.Key.all, Right);
477 function Equivalent_Keys
479 Right : Cursor) return Boolean
482 if Right.Node = null then
483 raise Constraint_Error with
484 "Right cursor of Equivalent_Keys equals No_Element";
487 if Right.Node.Key = null then
488 raise Program_Error with
489 "Right cursor of Equivalent_Keys is bad";
492 pragma Assert (Vet (Right), "bad Right cursor in Equivalent_Keys");
494 return Equivalent_Keys (Left, Right.Node.Key.all);
501 procedure Exclude (Container : in out Map; Key : Key_Type) is
504 Key_Ops.Delete_Key_Sans_Free (Container.HT, Key, X);
512 procedure Finalize (Container : in out Map) is
514 HT_Ops.Finalize (Container.HT);
517 procedure Finalize (Object : in out Iterator) is
519 if Object.Container /= null then
521 B : Natural renames Object.Container.all.HT.Busy;
528 procedure Finalize (Control : in out Reference_Control_Type) is
530 if Control.Container /= null then
532 M : Map renames Control.Container.all;
533 HT : Hash_Table_Type renames M.HT'Unrestricted_Access.all;
534 B : Natural renames HT.Busy;
535 L : Natural renames HT.Lock;
541 Control.Container := null;
549 function Find (Container : Map; Key : Key_Type) return Cursor is
550 Node : constant Node_Access := Key_Ops.Find (Container.HT, Key);
557 return Cursor'(Container
'Unrestricted_Access, Node
);
564 function Find_Equal_Key
565 (R_HT
: Hash_Table_Type
;
566 L_Node
: Node_Access
) return Boolean
568 R_Index
: constant Hash_Type
:= Key_Ops
.Index
(R_HT
, L_Node
.Key
.all);
569 R_Node
: Node_Access
:= R_HT
.Buckets
(R_Index
);
572 while R_Node
/= null loop
573 if Equivalent_Keys
(L_Node
.Key
.all, R_Node
.Key
.all) then
574 return L_Node
.Element
.all = R_Node
.Element
.all;
577 R_Node
:= R_Node
.Next
;
587 function First
(Container
: Map
) return Cursor
is
588 Node
: constant Node_Access
:= HT_Ops
.First
(Container
.HT
);
593 return Cursor
'(Container'Unrestricted_Access, Node);
597 function First (Object : Iterator) return Cursor is
599 return Object.Container.First;
606 procedure Free (X : in out Node_Access) is
607 procedure Deallocate is
608 new Ada.Unchecked_Deallocation (Node_Type, Node_Access);
615 X.Next := X; -- detect mischief (in Vet)
624 Free_Element (X.Element);
635 Free_Element (X.Element);
651 function Has_Element (Position : Cursor) return Boolean is
653 pragma Assert (Vet (Position), "bad cursor in Has_Element");
654 return Position.Node /= null;
661 function Hash_Node (Node : Node_Access) return Hash_Type is
663 return Hash (Node.Key.all);
671 (Container : in out Map;
673 New_Item : Element_Type)
682 Insert (Container, Key, New_Item, Position, Inserted);
685 if Container.HT.Lock > 0 then
686 raise Program_Error with
687 "Include attempted to tamper with elements (map is locked)";
690 K := Position.Node.Key;
691 E := Position.Node.Element;
693 Position.Node.Key := new Key_Type'(Key
);
696 -- The element allocator may need an accessibility check in the
697 -- case the actual type is class-wide or has access discriminants
698 -- (see RM 4.8(10.1) and AI12-0035).
700 pragma Unsuppress
(Accessibility_Check
);
703 Position
.Node
.Element
:= new Element_Type
'(New_Item);
721 (Container : in out Map;
723 New_Item : Element_Type;
724 Position : out Cursor;
725 Inserted : out Boolean)
727 function New_Node (Next : Node_Access) return Node_Access;
729 procedure Local_Insert is
730 new Key_Ops.Generic_Conditional_Insert (New_Node);
736 function New_Node (Next : Node_Access) return Node_Access is
737 K : Key_Access := new Key_Type'(Key
);
740 -- The element allocator may need an accessibility check in the case
741 -- the actual type is class-wide or has access discriminants (see
742 -- RM 4.8(10.1) and AI12-0035).
744 pragma Unsuppress
(Accessibility_Check
);
747 E
:= new Element_Type
'(New_Item);
748 return new Node_Type'(K
, E
, Next
);
757 HT
: Hash_Table_Type
renames Container
.HT
;
759 -- Start of processing for Insert
762 if HT_Ops
.Capacity
(HT
) = 0 then
763 HT_Ops
.Reserve_Capacity
(HT
, 1);
766 Local_Insert
(HT
, Key
, Position
.Node
, Inserted
);
769 and then HT
.Length
> HT_Ops
.Capacity
(HT
)
771 HT_Ops
.Reserve_Capacity
(HT
, HT
.Length
);
774 Position
.Container
:= Container
'Unchecked_Access;
778 (Container
: in out Map
;
780 New_Item
: Element_Type
)
783 pragma Unreferenced
(Position
);
788 Insert
(Container
, Key
, New_Item
, Position
, Inserted
);
791 raise Constraint_Error
with
792 "attempt to insert key already in map";
800 function Is_Empty
(Container
: Map
) return Boolean is
802 return Container
.HT
.Length
= 0;
811 Process
: not null access procedure (Position
: Cursor
))
813 procedure Process_Node
(Node
: Node_Access
);
814 pragma Inline
(Process_Node
);
816 procedure Local_Iterate
is
817 new HT_Ops
.Generic_Iteration
(Process_Node
);
823 procedure Process_Node
(Node
: Node_Access
) is
825 Process
(Cursor
'(Container'Unrestricted_Access, Node));
828 B : Natural renames Container'Unrestricted_Access.all.HT.Busy;
830 -- Start of processing Iterate
836 Local_Iterate (Container.HT);
847 (Container : Map) return Map_Iterator_Interfaces.Forward_Iterator'Class
849 B : Natural renames Container'Unrestricted_Access.all.HT.Busy;
851 return It : constant Iterator :=
852 (Limited_Controlled with Container => Container'Unrestricted_Access)
862 function Key (Position : Cursor) return Key_Type is
864 if Position.Node = null then
865 raise Constraint_Error with
866 "Position cursor of function Key equals No_Element";
869 if Position.Node.Key = null then
870 raise Program_Error with
871 "Position cursor of function Key is bad";
874 pragma Assert (Vet (Position), "bad cursor in function Key");
876 return Position.Node.Key.all;
883 function Length (Container : Map) return Count_Type is
885 return Container.HT.Length;
893 (Target : in out Map;
897 HT_Ops.Move (Target => Target.HT, Source => Source.HT);
904 function Next (Node : Node_Access) return Node_Access is
909 procedure Next (Position : in out Cursor) is
911 Position := Next (Position);
914 function Next (Position : Cursor) return Cursor is
916 if Position.Node = null then
920 if Position.Node.Key = null
921 or else Position.Node.Element = null
923 raise Program_Error with "Position cursor of Next is bad";
926 pragma Assert (Vet (Position), "Position cursor of Next is bad");
929 HT : Hash_Table_Type renames Position.Container.HT;
930 Node : constant Node_Access := HT_Ops.Next (HT, Position.Node);
935 return Cursor'(Position
.Container
, Node
);
940 function Next
(Object
: Iterator
; Position
: Cursor
) return Cursor
is
942 if Position
.Container
= null then
946 if Position
.Container
/= Object
.Container
then
947 raise Program_Error
with
948 "Position cursor of Next designates wrong map";
951 return Next
(Position
);
958 procedure Query_Element
960 Process
: not null access procedure (Key
: Key_Type
;
961 Element
: Element_Type
))
964 if Position
.Node
= null then
965 raise Constraint_Error
with
966 "Position cursor of Query_Element equals No_Element";
969 if Position
.Node
.Key
= null
970 or else Position
.Node
.Element
= null
972 raise Program_Error
with
973 "Position cursor of Query_Element is bad";
976 pragma Assert
(Vet
(Position
), "bad cursor in Query_Element");
979 M
: Map
renames Position
.Container
.all;
980 HT
: Hash_Table_Type
renames M
.HT
'Unrestricted_Access.all;
982 B
: Natural renames HT
.Busy
;
983 L
: Natural renames HT
.Lock
;
990 K
: Key_Type
renames Position
.Node
.Key
.all;
991 E
: Element_Type
renames Position
.Node
.Element
.all;
1011 procedure Read_Nodes
is new HT_Ops
.Generic_Read
(Read_Node
);
1014 (Stream
: not null access Root_Stream_Type
'Class;
1015 Container
: out Map
)
1018 Read_Nodes
(Stream
, Container
.HT
);
1022 (Stream
: not null access Root_Stream_Type
'Class;
1026 raise Program_Error
with "attempt to stream map cursor";
1030 (Stream
: not null access Root_Stream_Type
'Class;
1031 Item
: out Reference_Type
)
1034 raise Program_Error
with "attempt to stream reference";
1038 (Stream
: not null access Root_Stream_Type
'Class;
1039 Item
: out Constant_Reference_Type
)
1042 raise Program_Error
with "attempt to stream reference";
1050 (Stream
: not null access Root_Stream_Type
'Class) return Node_Access
1052 Node
: Node_Access
:= new Node_Type
;
1056 Node
.Key
:= new Key_Type
'(Key_Type'Input (Stream));
1064 Node.Element := new Element_Type'(Element_Type
'Input (Stream
));
1067 Free_Key
(Node
.Key
);
1080 (Container
: aliased in out Map
;
1081 Position
: Cursor
) return Reference_Type
1084 if Position
.Container
= null then
1085 raise Constraint_Error
with
1086 "Position cursor has no element";
1089 if Position
.Container
/= Container
'Unrestricted_Access then
1090 raise Program_Error
with
1091 "Position cursor designates wrong map";
1094 if Position
.Node
.Element
= null then
1095 raise Program_Error
with
1096 "Position cursor has no element";
1101 "Position cursor in function Reference is bad");
1104 M
: Map
renames Position
.Container
.all;
1105 HT
: Hash_Table_Type
renames M
.HT
'Unrestricted_Access.all;
1106 B
: Natural renames HT
.Busy
;
1107 L
: Natural renames HT
.Lock
;
1109 return R
: constant Reference_Type
:=
1110 (Element
=> Position
.Node
.Element
.all'Access,
1111 Control
=> (Controlled
with Position
.Container
))
1120 (Container
: aliased in out Map
;
1121 Key
: Key_Type
) return Reference_Type
1123 Node
: constant Node_Access
:= Key_Ops
.Find
(Container
.HT
, Key
);
1127 raise Constraint_Error
with "key not in map";
1130 if Node
.Element
= null then
1131 raise Program_Error
with "key has no element";
1135 M
: Map
renames Container
'Unrestricted_Access.all;
1136 HT
: Hash_Table_Type
renames M
.HT
'Unrestricted_Access.all;
1137 B
: Natural renames HT
.Busy
;
1138 L
: Natural renames HT
.Lock
;
1140 return R
: constant Reference_Type
:=
1141 (Element
=> Node
.Element
.all'Access,
1142 Control
=> (Controlled
with Container
'Unrestricted_Access))
1155 (Container
: in out Map
;
1157 New_Item
: Element_Type
)
1159 Node
: constant Node_Access
:= Key_Ops
.Find
(Container
.HT
, Key
);
1166 raise Constraint_Error
with
1167 "attempt to replace key not in map";
1170 if Container
.HT
.Lock
> 0 then
1171 raise Program_Error
with
1172 "Replace attempted to tamper with elements (map is locked)";
1178 Node
.Key
:= new Key_Type
'(Key);
1181 -- The element allocator may need an accessibility check in the case
1182 -- the actual type is class-wide or has access discriminants (see
1183 -- RM 4.8(10.1) and AI12-0035).
1185 pragma Unsuppress (Accessibility_Check);
1188 Node.Element := new Element_Type'(New_Item
);
1200 ---------------------
1201 -- Replace_Element --
1202 ---------------------
1204 procedure Replace_Element
1205 (Container
: in out Map
;
1207 New_Item
: Element_Type
)
1210 if Position
.Node
= null then
1211 raise Constraint_Error
with
1212 "Position cursor of Replace_Element equals No_Element";
1215 if Position
.Node
.Key
= null
1216 or else Position
.Node
.Element
= null
1218 raise Program_Error
with
1219 "Position cursor of Replace_Element is bad";
1222 if Position
.Container
/= Container
'Unrestricted_Access then
1223 raise Program_Error
with
1224 "Position cursor of Replace_Element designates wrong map";
1227 if Position
.Container
.HT
.Lock
> 0 then
1228 raise Program_Error
with
1229 "Replace_Element attempted to tamper with elements (map is locked)";
1232 pragma Assert
(Vet
(Position
), "bad cursor in Replace_Element");
1235 X
: Element_Access
:= Position
.Node
.Element
;
1237 -- The element allocator may need an accessibility check in the case
1238 -- the actual type is class-wide or has access discriminants (see
1239 -- RM 4.8(10.1) and AI12-0035).
1241 pragma Unsuppress
(Accessibility_Check
);
1244 Position
.Node
.Element
:= new Element_Type
'(New_Item);
1247 end Replace_Element;
1249 ----------------------
1250 -- Reserve_Capacity --
1251 ----------------------
1253 procedure Reserve_Capacity
1254 (Container : in out Map;
1255 Capacity : Count_Type)
1258 HT_Ops.Reserve_Capacity (Container.HT, Capacity);
1259 end Reserve_Capacity;
1265 procedure Set_Next (Node : Node_Access; Next : Node_Access) is
1270 --------------------
1271 -- Update_Element --
1272 --------------------
1274 procedure Update_Element
1275 (Container : in out Map;
1277 Process : not null access procedure (Key : Key_Type;
1278 Element : in out Element_Type))
1281 if Position.Node = null then
1282 raise Constraint_Error with
1283 "Position cursor of Update_Element equals No_Element";
1286 if Position.Node.Key = null
1287 or else Position.Node.Element = null
1289 raise Program_Error with
1290 "Position cursor of Update_Element is bad";
1293 if Position.Container /= Container'Unrestricted_Access then
1294 raise Program_Error with
1295 "Position cursor of Update_Element designates wrong map";
1298 pragma Assert (Vet (Position), "bad cursor in Update_Element");
1301 HT : Hash_Table_Type renames Container.HT;
1303 B : Natural renames HT.Busy;
1304 L : Natural renames HT.Lock;
1311 K : Key_Type renames Position.Node.Key.all;
1312 E : Element_Type renames Position.Node.Element.all;
1333 function Vet (Position : Cursor) return Boolean is
1335 if Position.Node = null then
1336 return Position.Container = null;
1339 if Position.Container = null then
1343 if Position.Node.Next = Position.Node then
1347 if Position.Node.Key = null then
1351 if Position.Node.Element = null then
1356 HT : Hash_Table_Type renames Position.Container.HT;
1360 if HT.Length = 0 then
1364 if HT.Buckets = null
1365 or else HT.Buckets'Length = 0
1370 X := HT.Buckets (Key_Ops.Index (HT, Position.Node.Key.all));
1372 for J in 1 .. HT.Length loop
1373 if X = Position.Node then
1381 if X = X.Next then -- to prevent unnecessary looping
1396 procedure Write_Nodes is new HT_Ops.Generic_Write (Write_Node);
1399 (Stream : not null access Root_Stream_Type'Class;
1403 Write_Nodes (Stream, Container.HT);
1407 (Stream : not null access Root_Stream_Type'Class;
1411 raise Program_Error with "attempt to stream map cursor";
1415 (Stream : not null access Root_Stream_Type'Class;
1416 Item : Reference_Type)
1419 raise Program_Error with "attempt to stream reference";
1423 (Stream : not null access Root_Stream_Type'Class;
1424 Item : Constant_Reference_Type)
1427 raise Program_Error with "attempt to stream reference";
1434 procedure Write_Node
1435 (Stream : not null access Root_Stream_Type'Class;
1439 Key_Type'Output (Stream, Node.Key.all);
1440 Element_Type'Output (Stream, Node.Element.all);
1443 end Ada.Containers.Indefinite_Hashed_Maps;