1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- ADA.CONTAINERS.INDEFINITE_HASHED_MAPS --
9 -- Copyright (C) 2004-2013, 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 -----------------------
49 -- Local Subprograms --
50 -----------------------
52 function Copy_Node
(Node
: Node_Access
) return Node_Access
;
53 pragma Inline
(Copy_Node
);
55 function Equivalent_Key_Node
57 Node
: Node_Access
) return Boolean;
58 pragma Inline
(Equivalent_Key_Node
);
60 function Find_Equal_Key
61 (R_HT
: Hash_Table_Type
;
62 L_Node
: Node_Access
) return Boolean;
64 procedure Free
(X
: in out Node_Access
);
65 -- pragma Inline (Free);
67 function Hash_Node
(Node
: Node_Access
) return Hash_Type
;
68 pragma Inline
(Hash_Node
);
70 function Next
(Node
: Node_Access
) return Node_Access
;
74 (Stream
: not null access Root_Stream_Type
'Class) return Node_Access
;
76 procedure Set_Next
(Node
: Node_Access
; Next
: Node_Access
);
77 pragma Inline
(Set_Next
);
79 function Vet
(Position
: Cursor
) return Boolean;
82 (Stream
: not null access Root_Stream_Type
'Class;
85 --------------------------
86 -- Local Instantiations --
87 --------------------------
89 package HT_Ops
is new Ada
.Containers
.Hash_Tables
.Generic_Operations
90 (HT_Types
=> HT_Types
,
91 Hash_Node
=> Hash_Node
,
94 Copy_Node
=> Copy_Node
,
97 package Key_Ops
is new Hash_Tables
.Generic_Keys
98 (HT_Types
=> HT_Types
,
100 Set_Next
=> Set_Next
,
101 Key_Type
=> Key_Type
,
103 Equivalent_Keys
=> Equivalent_Key_Node
);
109 function Is_Equal
is new HT_Ops
.Generic_Equal
(Find_Equal_Key
);
111 overriding
function "=" (Left
, Right
: Map
) return Boolean is
113 return Is_Equal
(Left
.HT
, Right
.HT
);
120 procedure Adjust
(Container
: in out Map
) is
122 HT_Ops
.Adjust
(Container
.HT
);
125 procedure Adjust
(Control
: in out Reference_Control_Type
) is
127 if Control
.Container
/= null then
129 M
: Map
renames Control
.Container
.all;
130 HT
: Hash_Table_Type
renames M
.HT
'Unrestricted_Access.all;
131 B
: Natural renames HT
.Busy
;
132 L
: Natural renames HT
.Lock
;
144 procedure Assign
(Target
: in out Map
; Source
: Map
) is
145 procedure Insert_Item
(Node
: Node_Access
);
146 pragma Inline
(Insert_Item
);
148 procedure Insert_Items
is new HT_Ops
.Generic_Iteration
(Insert_Item
);
154 procedure Insert_Item
(Node
: Node_Access
) is
156 Target
.Insert
(Key
=> Node
.Key
.all, New_Item
=> Node
.Element
.all);
159 -- Start of processing for Assign
162 if Target
'Address = Source
'Address then
168 if Target
.Capacity
< Source
.Length
then
169 Target
.Reserve_Capacity
(Source
.Length
);
172 Insert_Items
(Source
.HT
);
179 function Capacity
(Container
: Map
) return Count_Type
is
181 return HT_Ops
.Capacity
(Container
.HT
);
188 procedure Clear
(Container
: in out Map
) is
190 HT_Ops
.Clear
(Container
.HT
);
193 ------------------------
194 -- Constant_Reference --
195 ------------------------
197 function Constant_Reference
198 (Container
: aliased Map
;
199 Position
: Cursor
) return Constant_Reference_Type
202 if Position
.Container
= null then
203 raise Constraint_Error
with
204 "Position cursor has no element";
207 if Position
.Container
/= Container
'Unrestricted_Access then
208 raise Program_Error
with
209 "Position cursor designates wrong map";
212 if Position
.Node
.Element
= null then
213 raise Program_Error
with
214 "Position cursor has no element";
219 "Position cursor in Constant_Reference is bad");
222 M
: Map
renames Position
.Container
.all;
223 HT
: Hash_Table_Type
renames M
.HT
'Unrestricted_Access.all;
224 B
: Natural renames HT
.Busy
;
225 L
: Natural renames HT
.Lock
;
227 return R
: constant Constant_Reference_Type
:=
228 (Element
=> Position
.Node
.Element
.all'Access,
229 Control
=> (Controlled
with Container
'Unrestricted_Access))
235 end Constant_Reference
;
237 function Constant_Reference
238 (Container
: aliased Map
;
239 Key
: Key_Type
) return Constant_Reference_Type
241 HT
: Hash_Table_Type
renames Container
'Unrestricted_Access.HT
;
242 Node
: constant Node_Access
:= Key_Ops
.Find
(HT
, Key
);
246 raise Constraint_Error
with "key not in map";
249 if Node
.Element
= null then
250 raise Program_Error
with "key has no element";
254 B
: Natural renames HT
.Busy
;
255 L
: Natural renames HT
.Lock
;
257 return R
: constant Constant_Reference_Type
:=
258 (Element
=> Node
.Element
.all'Access,
259 Control
=> (Controlled
with Container
'Unrestricted_Access))
265 end Constant_Reference
;
271 function Contains
(Container
: Map
; Key
: Key_Type
) return Boolean is
273 return Find
(Container
, Key
) /= No_Element
;
282 Capacity
: Count_Type
:= 0) return Map
290 elsif Capacity
>= Source
.Length
then
295 with "Requested capacity is less than Source length";
298 return Target
: Map
do
299 Target
.Reserve_Capacity
(C
);
300 Target
.Assign
(Source
);
308 function Copy_Node
(Node
: Node_Access
) return Node_Access
is
309 K
: Key_Access
:= new Key_Type
'(Node.Key.all);
312 E := new Element_Type'(Node
.Element
.all);
313 return new Node_Type
'(K, E, null);
325 procedure Delete (Container : in out Map; Key : Key_Type) is
329 Key_Ops.Delete_Key_Sans_Free (Container.HT, Key, X);
332 raise Constraint_Error with "attempt to delete key not in map";
338 procedure Delete (Container : in out Map; Position : in out Cursor) is
340 if Position.Node = null then
341 raise Constraint_Error with
342 "Position cursor of Delete equals No_Element";
345 if Position.Container /= Container'Unrestricted_Access then
346 raise Program_Error with
347 "Position cursor of Delete designates wrong map";
350 if Container.HT.Busy > 0 then
351 raise Program_Error with
352 "Delete attempted to tamper with cursors (map is busy)";
355 pragma Assert (Vet (Position), "bad cursor in Delete");
357 HT_Ops.Delete_Node_Sans_Free (Container.HT, Position.Node);
359 Free (Position.Node);
360 Position.Container := null;
367 function Element (Container : Map; Key : Key_Type) return Element_Type is
368 HT : Hash_Table_Type renames Container'Unrestricted_Access.HT;
369 Node : constant Node_Access := Key_Ops.Find (HT, Key);
373 raise Constraint_Error with
374 "no element available because key not in map";
377 return Node.Element.all;
380 function Element (Position : Cursor) return Element_Type is
382 if Position.Node = null then
383 raise Constraint_Error with
384 "Position cursor of function Element equals No_Element";
387 if Position.Node.Element = null then
388 raise Program_Error with
389 "Position cursor of function Element is bad";
392 pragma Assert (Vet (Position), "bad cursor in function Element");
394 return Position.Node.Element.all;
397 -------------------------
398 -- Equivalent_Key_Node --
399 -------------------------
401 function Equivalent_Key_Node
403 Node : Node_Access) return Boolean
406 return Equivalent_Keys (Key, Node.Key.all);
407 end Equivalent_Key_Node;
409 ---------------------
410 -- Equivalent_Keys --
411 ---------------------
413 function Equivalent_Keys (Left, Right : Cursor) return Boolean is
415 if Left.Node = null then
416 raise Constraint_Error with
417 "Left cursor of Equivalent_Keys equals No_Element";
420 if Right.Node = null then
421 raise Constraint_Error with
422 "Right cursor of Equivalent_Keys equals No_Element";
425 if Left.Node.Key = null then
426 raise Program_Error with
427 "Left cursor of Equivalent_Keys is bad";
430 if Right.Node.Key = null then
431 raise Program_Error with
432 "Right cursor of Equivalent_Keys is bad";
435 pragma Assert (Vet (Left), "bad Left cursor in Equivalent_Keys");
436 pragma Assert (Vet (Right), "bad Right cursor in Equivalent_Keys");
438 return Equivalent_Keys (Left.Node.Key.all, Right.Node.Key.all);
441 function Equivalent_Keys
443 Right : Key_Type) return Boolean
446 if Left.Node = null then
447 raise Constraint_Error with
448 "Left cursor of Equivalent_Keys equals No_Element";
451 if Left.Node.Key = null then
452 raise Program_Error with
453 "Left cursor of Equivalent_Keys is bad";
456 pragma Assert (Vet (Left), "bad Left cursor in Equivalent_Keys");
458 return Equivalent_Keys (Left.Node.Key.all, Right);
461 function Equivalent_Keys
463 Right : Cursor) return Boolean
466 if Right.Node = null then
467 raise Constraint_Error with
468 "Right cursor of Equivalent_Keys equals No_Element";
471 if Right.Node.Key = null then
472 raise Program_Error with
473 "Right cursor of Equivalent_Keys is bad";
476 pragma Assert (Vet (Right), "bad Right cursor in Equivalent_Keys");
478 return Equivalent_Keys (Left, Right.Node.Key.all);
485 procedure Exclude (Container : in out Map; Key : Key_Type) is
488 Key_Ops.Delete_Key_Sans_Free (Container.HT, Key, X);
496 procedure Finalize (Container : in out Map) is
498 HT_Ops.Finalize (Container.HT);
501 procedure Finalize (Object : in out Iterator) is
503 if Object.Container /= null then
505 B : Natural renames Object.Container.all.HT.Busy;
512 procedure Finalize (Control : in out Reference_Control_Type) is
514 if Control.Container /= null then
516 M : Map renames Control.Container.all;
517 HT : Hash_Table_Type renames M.HT'Unrestricted_Access.all;
518 B : Natural renames HT.Busy;
519 L : Natural renames HT.Lock;
525 Control.Container := null;
533 function Find (Container : Map; Key : Key_Type) return Cursor is
534 HT : Hash_Table_Type renames Container'Unrestricted_Access.HT;
535 Node : constant Node_Access := Key_Ops.Find (HT, Key);
542 return Cursor'(Container
'Unrestricted_Access, Node
);
549 function Find_Equal_Key
550 (R_HT
: Hash_Table_Type
;
551 L_Node
: Node_Access
) return Boolean
553 R_Index
: constant Hash_Type
:= Key_Ops
.Index
(R_HT
, L_Node
.Key
.all);
554 R_Node
: Node_Access
:= R_HT
.Buckets
(R_Index
);
557 while R_Node
/= null loop
558 if Equivalent_Keys
(L_Node
.Key
.all, R_Node
.Key
.all) then
559 return L_Node
.Element
.all = R_Node
.Element
.all;
562 R_Node
:= R_Node
.Next
;
572 function First
(Container
: Map
) return Cursor
is
573 Node
: constant Node_Access
:= HT_Ops
.First
(Container
.HT
);
578 return Cursor
'(Container'Unrestricted_Access, Node);
582 function First (Object : Iterator) return Cursor is
584 return Object.Container.First;
591 procedure Free (X : in out Node_Access) is
592 procedure Deallocate is
593 new Ada.Unchecked_Deallocation (Node_Type, Node_Access);
600 X.Next := X; -- detect mischief (in Vet)
610 Free_Element (X.Element);
621 Free_Element (X.Element);
636 function Has_Element (Position : Cursor) return Boolean is
638 pragma Assert (Vet (Position), "bad cursor in Has_Element");
639 return Position.Node /= null;
646 function Hash_Node (Node : Node_Access) return Hash_Type is
648 return Hash (Node.Key.all);
656 (Container : in out Map;
658 New_Item : Element_Type)
667 Insert (Container, Key, New_Item, Position, Inserted);
670 if Container.HT.Lock > 0 then
671 raise Program_Error with
672 "Include attempted to tamper with elements (map is locked)";
675 K := Position.Node.Key;
676 E := Position.Node.Element;
678 Position.Node.Key := new Key_Type'(Key
);
681 -- The element allocator may need an accessibility check in the
682 -- case the actual type is class-wide or has access discriminants
683 -- (see RM 4.8(10.1) and AI12-0035).
685 pragma Unsuppress
(Accessibility_Check
);
688 Position
.Node
.Element
:= new Element_Type
'(New_Item);
706 (Container : in out Map;
708 New_Item : Element_Type;
709 Position : out Cursor;
710 Inserted : out Boolean)
712 function New_Node (Next : Node_Access) return Node_Access;
714 procedure Local_Insert is
715 new Key_Ops.Generic_Conditional_Insert (New_Node);
721 function New_Node (Next : Node_Access) return Node_Access is
722 K : Key_Access := new Key_Type'(Key
);
725 -- The element allocator may need an accessibility check in the case
726 -- the actual type is class-wide or has access discriminants (see
727 -- RM 4.8(10.1) and AI12-0035).
729 pragma Unsuppress
(Accessibility_Check
);
732 E
:= new Element_Type
'(New_Item);
733 return new Node_Type'(K
, E
, Next
);
742 HT
: Hash_Table_Type
renames Container
.HT
;
744 -- Start of processing for Insert
747 if HT_Ops
.Capacity
(HT
) = 0 then
748 HT_Ops
.Reserve_Capacity
(HT
, 1);
751 Local_Insert
(HT
, Key
, Position
.Node
, Inserted
);
754 and then HT
.Length
> HT_Ops
.Capacity
(HT
)
756 HT_Ops
.Reserve_Capacity
(HT
, HT
.Length
);
759 Position
.Container
:= Container
'Unchecked_Access;
763 (Container
: in out Map
;
765 New_Item
: Element_Type
)
768 pragma Unreferenced
(Position
);
773 Insert
(Container
, Key
, New_Item
, Position
, Inserted
);
776 raise Constraint_Error
with
777 "attempt to insert key already in map";
785 function Is_Empty
(Container
: Map
) return Boolean is
787 return Container
.HT
.Length
= 0;
796 Process
: not null access procedure (Position
: Cursor
))
798 procedure Process_Node
(Node
: Node_Access
);
799 pragma Inline
(Process_Node
);
801 procedure Local_Iterate
is
802 new HT_Ops
.Generic_Iteration
(Process_Node
);
808 procedure Process_Node
(Node
: Node_Access
) is
810 Process
(Cursor
'(Container'Unrestricted_Access, Node));
813 B : Natural renames Container'Unrestricted_Access.all.HT.Busy;
815 -- Start of processing Iterate
821 Local_Iterate (Container.HT);
832 (Container : Map) return Map_Iterator_Interfaces.Forward_Iterator'Class
834 B : Natural renames Container'Unrestricted_Access.all.HT.Busy;
836 return It : constant Iterator :=
837 (Limited_Controlled with Container => Container'Unrestricted_Access)
847 function Key (Position : Cursor) return Key_Type is
849 if Position.Node = null then
850 raise Constraint_Error with
851 "Position cursor of function Key equals No_Element";
854 if Position.Node.Key = null then
855 raise Program_Error with
856 "Position cursor of function Key is bad";
859 pragma Assert (Vet (Position), "bad cursor in function Key");
861 return Position.Node.Key.all;
868 function Length (Container : Map) return Count_Type is
870 return Container.HT.Length;
878 (Target : in out Map;
882 HT_Ops.Move (Target => Target.HT, Source => Source.HT);
889 function Next (Node : Node_Access) return Node_Access is
894 procedure Next (Position : in out Cursor) is
896 Position := Next (Position);
899 function Next (Position : Cursor) return Cursor is
901 if Position.Node = null then
905 if Position.Node.Key = null
906 or else Position.Node.Element = null
908 raise Program_Error with "Position cursor of Next is bad";
911 pragma Assert (Vet (Position), "Position cursor of Next is bad");
914 HT : Hash_Table_Type renames Position.Container.HT;
915 Node : constant Node_Access := HT_Ops.Next (HT, Position.Node);
920 return Cursor'(Position
.Container
, Node
);
925 function Next
(Object
: Iterator
; Position
: Cursor
) return Cursor
is
927 if Position
.Container
= null then
931 if Position
.Container
/= Object
.Container
then
932 raise Program_Error
with
933 "Position cursor of Next designates wrong map";
936 return Next
(Position
);
943 procedure Query_Element
945 Process
: not null access procedure (Key
: Key_Type
;
946 Element
: Element_Type
))
949 if Position
.Node
= null then
950 raise Constraint_Error
with
951 "Position cursor of Query_Element equals No_Element";
954 if Position
.Node
.Key
= null
955 or else Position
.Node
.Element
= null
957 raise Program_Error
with
958 "Position cursor of Query_Element is bad";
961 pragma Assert
(Vet
(Position
), "bad cursor in Query_Element");
964 M
: Map
renames Position
.Container
.all;
965 HT
: Hash_Table_Type
renames M
.HT
'Unrestricted_Access.all;
967 B
: Natural renames HT
.Busy
;
968 L
: Natural renames HT
.Lock
;
975 K
: Key_Type
renames Position
.Node
.Key
.all;
976 E
: Element_Type
renames Position
.Node
.Element
.all;
998 procedure Read_Nodes
is new HT_Ops
.Generic_Read
(Read_Node
);
1001 (Stream
: not null access Root_Stream_Type
'Class;
1002 Container
: out Map
)
1005 Read_Nodes
(Stream
, Container
.HT
);
1009 (Stream
: not null access Root_Stream_Type
'Class;
1013 raise Program_Error
with "attempt to stream map cursor";
1017 (Stream
: not null access Root_Stream_Type
'Class;
1018 Item
: out Reference_Type
)
1021 raise Program_Error
with "attempt to stream reference";
1025 (Stream
: not null access Root_Stream_Type
'Class;
1026 Item
: out Constant_Reference_Type
)
1029 raise Program_Error
with "attempt to stream reference";
1037 (Stream
: not null access Root_Stream_Type
'Class) return Node_Access
1039 Node
: Node_Access
:= new Node_Type
;
1043 Node
.Key
:= new Key_Type
'(Key_Type'Input (Stream));
1051 Node.Element := new Element_Type'(Element_Type
'Input (Stream
));
1054 Free_Key
(Node
.Key
);
1067 (Container
: aliased in out Map
;
1068 Position
: Cursor
) return Reference_Type
1071 if Position
.Container
= null then
1072 raise Constraint_Error
with
1073 "Position cursor has no element";
1076 if Position
.Container
/= Container
'Unrestricted_Access then
1077 raise Program_Error
with
1078 "Position cursor designates wrong map";
1081 if Position
.Node
.Element
= null then
1082 raise Program_Error
with
1083 "Position cursor has no element";
1088 "Position cursor in function Reference is bad");
1091 M
: Map
renames Position
.Container
.all;
1092 HT
: Hash_Table_Type
renames M
.HT
'Unrestricted_Access.all;
1093 B
: Natural renames HT
.Busy
;
1094 L
: Natural renames HT
.Lock
;
1096 return R
: constant Reference_Type
:=
1097 (Element
=> Position
.Node
.Element
.all'Access,
1098 Control
=> (Controlled
with Position
.Container
))
1107 (Container
: aliased in out Map
;
1108 Key
: Key_Type
) return Reference_Type
1110 HT
: Hash_Table_Type
renames Container
.HT
;
1111 Node
: constant Node_Access
:= Key_Ops
.Find
(HT
, Key
);
1115 raise Constraint_Error
with "key not in map";
1118 if Node
.Element
= null then
1119 raise Program_Error
with "key has no element";
1123 B
: Natural renames HT
.Busy
;
1124 L
: Natural renames HT
.Lock
;
1126 return R
: constant Reference_Type
:=
1127 (Element
=> Node
.Element
.all'Access,
1128 Control
=> (Controlled
with Container
'Unrestricted_Access))
1141 (Container
: in out Map
;
1143 New_Item
: Element_Type
)
1145 Node
: constant Node_Access
:= Key_Ops
.Find
(Container
.HT
, Key
);
1152 raise Constraint_Error
with
1153 "attempt to replace key not in map";
1156 if Container
.HT
.Lock
> 0 then
1157 raise Program_Error
with
1158 "Replace attempted to tamper with elements (map is locked)";
1164 Node
.Key
:= new Key_Type
'(Key);
1167 -- The element allocator may need an accessibility check in the case
1168 -- the actual type is class-wide or has access discriminants (see
1169 -- RM 4.8(10.1) and AI12-0035).
1171 pragma Unsuppress (Accessibility_Check);
1174 Node.Element := new Element_Type'(New_Item
);
1186 ---------------------
1187 -- Replace_Element --
1188 ---------------------
1190 procedure Replace_Element
1191 (Container
: in out Map
;
1193 New_Item
: Element_Type
)
1196 if Position
.Node
= null then
1197 raise Constraint_Error
with
1198 "Position cursor of Replace_Element equals No_Element";
1201 if Position
.Node
.Key
= null
1202 or else Position
.Node
.Element
= null
1204 raise Program_Error
with
1205 "Position cursor of Replace_Element is bad";
1208 if Position
.Container
/= Container
'Unrestricted_Access then
1209 raise Program_Error
with
1210 "Position cursor of Replace_Element designates wrong map";
1213 if Position
.Container
.HT
.Lock
> 0 then
1214 raise Program_Error
with
1215 "Replace_Element attempted to tamper with elements (map is locked)";
1218 pragma Assert
(Vet
(Position
), "bad cursor in Replace_Element");
1221 X
: Element_Access
:= Position
.Node
.Element
;
1223 -- The element allocator may need an accessibility check in the case
1224 -- the actual type is class-wide or has access discriminants (see
1225 -- RM 4.8(10.1) and AI12-0035).
1227 pragma Unsuppress
(Accessibility_Check
);
1230 Position
.Node
.Element
:= new Element_Type
'(New_Item);
1233 end Replace_Element;
1235 ----------------------
1236 -- Reserve_Capacity --
1237 ----------------------
1239 procedure Reserve_Capacity
1240 (Container : in out Map;
1241 Capacity : Count_Type)
1244 HT_Ops.Reserve_Capacity (Container.HT, Capacity);
1245 end Reserve_Capacity;
1251 procedure Set_Next (Node : Node_Access; Next : Node_Access) is
1256 --------------------
1257 -- Update_Element --
1258 --------------------
1260 procedure Update_Element
1261 (Container : in out Map;
1263 Process : not null access procedure (Key : Key_Type;
1264 Element : in out Element_Type))
1267 if Position.Node = null then
1268 raise Constraint_Error with
1269 "Position cursor of Update_Element equals No_Element";
1272 if Position.Node.Key = null
1273 or else Position.Node.Element = null
1275 raise Program_Error with
1276 "Position cursor of Update_Element is bad";
1279 if Position.Container /= Container'Unrestricted_Access then
1280 raise Program_Error with
1281 "Position cursor of Update_Element designates wrong map";
1284 pragma Assert (Vet (Position), "bad cursor in Update_Element");
1287 HT : Hash_Table_Type renames Container.HT;
1289 B : Natural renames HT.Busy;
1290 L : Natural renames HT.Lock;
1297 K : Key_Type renames Position.Node.Key.all;
1298 E : Element_Type renames Position.Node.Element.all;
1319 function Vet (Position : Cursor) return Boolean is
1321 if Position.Node = null then
1322 return Position.Container = null;
1325 if Position.Container = null then
1329 if Position.Node.Next = Position.Node then
1333 if Position.Node.Key = null then
1337 if Position.Node.Element = null then
1342 HT : Hash_Table_Type renames Position.Container.HT;
1346 if HT.Length = 0 then
1350 if HT.Buckets = null
1351 or else HT.Buckets'Length = 0
1356 X := HT.Buckets (Key_Ops.Checked_Index (HT, Position.Node.Key.all));
1358 for J in 1 .. HT.Length loop
1359 if X = Position.Node then
1367 if X = X.Next then -- to prevent unnecessary looping
1382 procedure Write_Nodes is new HT_Ops.Generic_Write (Write_Node);
1385 (Stream : not null access Root_Stream_Type'Class;
1389 Write_Nodes (Stream, Container.HT);
1393 (Stream : not null access Root_Stream_Type'Class;
1397 raise Program_Error with "attempt to stream map cursor";
1401 (Stream : not null access Root_Stream_Type'Class;
1402 Item : Reference_Type)
1405 raise Program_Error with "attempt to stream reference";
1409 (Stream : not null access Root_Stream_Type'Class;
1410 Item : Constant_Reference_Type)
1413 raise Program_Error with "attempt to stream reference";
1420 procedure Write_Node
1421 (Stream : not null access Root_Stream_Type'Class;
1425 Key_Type'Output (Stream, Node.Key.all);
1426 Element_Type'Output (Stream, Node.Element.all);
1429 end Ada.Containers.Indefinite_Hashed_Maps;