111
|
1 ------------------------------------------------------------------------------
|
|
2 -- --
|
|
3 -- GNAT LIBRARY COMPONENTS --
|
|
4 -- --
|
|
5 -- ADA.CONTAINERS.HASH_TABLES.GENERIC_KEYS --
|
|
6 -- --
|
|
7 -- S p e c --
|
|
8 -- --
|
131
|
9 -- Copyright (C) 2004-2018, Free Software Foundation, Inc. --
|
111
|
10 -- --
|
|
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. --
|
|
17 -- --
|
|
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. --
|
|
21 -- --
|
|
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/>. --
|
|
26 -- --
|
|
27 -- This unit was originally developed by Matthew J Heaney. --
|
|
28 ------------------------------------------------------------------------------
|
|
29
|
|
30 -- Hash_Table_Type is used to implement hashed containers. This package
|
|
31 -- declares hash-table operations that depend on keys.
|
|
32
|
|
33 generic
|
|
34 with package HT_Types is
|
|
35 new Generic_Hash_Table_Types (<>);
|
|
36
|
|
37 use HT_Types, HT_Types.Implementation;
|
|
38
|
|
39 with function Next (Node : Node_Access) return Node_Access;
|
|
40
|
|
41 with procedure Set_Next
|
|
42 (Node : Node_Access;
|
|
43 Next : Node_Access);
|
|
44
|
|
45 type Key_Type (<>) is limited private;
|
|
46
|
|
47 with function Hash (Key : Key_Type) return Hash_Type;
|
|
48
|
|
49 with function Equivalent_Keys
|
|
50 (Key : Key_Type;
|
|
51 Node : Node_Access) return Boolean;
|
|
52
|
|
53 package Ada.Containers.Hash_Tables.Generic_Keys is
|
|
54 pragma Preelaborate;
|
|
55
|
|
56 function Index
|
|
57 (HT : Hash_Table_Type;
|
|
58 Key : Key_Type) return Hash_Type;
|
|
59 pragma Inline (Index);
|
|
60 -- Returns the bucket number (array index value) for the given key
|
|
61
|
|
62 function Checked_Index
|
|
63 (HT : aliased in out Hash_Table_Type;
|
|
64 Key : Key_Type) return Hash_Type;
|
|
65 pragma Inline (Checked_Index);
|
|
66 -- Calls Index, but also locks and unlocks the container, per AI05-0022, in
|
|
67 -- order to detect element tampering by the generic actual Hash function.
|
|
68
|
|
69 function Checked_Equivalent_Keys
|
|
70 (HT : aliased in out Hash_Table_Type;
|
|
71 Key : Key_Type;
|
|
72 Node : Node_Access) return Boolean;
|
|
73 -- Calls Equivalent_Keys, but locks and unlocks the container, per
|
|
74 -- AI05-0022, in order to detect element tampering by that generic actual.
|
|
75
|
|
76 procedure Delete_Key_Sans_Free
|
|
77 (HT : in out Hash_Table_Type;
|
|
78 Key : Key_Type;
|
|
79 X : out Node_Access);
|
|
80 -- Removes the node (if any) with the given key from the hash table,
|
|
81 -- without deallocating it. Program_Error is raised if the hash
|
|
82 -- table is busy.
|
|
83
|
|
84 function Find
|
|
85 (HT : aliased in out Hash_Table_Type;
|
|
86 Key : Key_Type) return Node_Access;
|
|
87 -- Returns the node (if any) corresponding to the given key
|
|
88
|
|
89 generic
|
|
90 with function New_Node (Next : Node_Access) return Node_Access;
|
|
91 procedure Generic_Conditional_Insert
|
|
92 (HT : in out Hash_Table_Type;
|
|
93 Key : Key_Type;
|
|
94 Node : out Node_Access;
|
|
95 Inserted : out Boolean);
|
|
96 -- Attempts to insert a new node with the given key into the hash table.
|
|
97 -- If a node with that key already exists in the table, then that node
|
|
98 -- is returned and Inserted returns False. Otherwise New_Node is called
|
|
99 -- to allocate a new node, and Inserted returns True. Program_Error is
|
|
100 -- raised if the hash table is busy.
|
|
101
|
|
102 generic
|
|
103 with function Hash (Node : Node_Access) return Hash_Type;
|
|
104 with procedure Assign (Node : Node_Access; Key : Key_Type);
|
|
105 procedure Generic_Replace_Element
|
|
106 (HT : in out Hash_Table_Type;
|
|
107 Node : Node_Access;
|
|
108 Key : Key_Type);
|
|
109 -- Assigns Key to Node, possibly changing its equivalence class. If Node
|
|
110 -- is in the same equivalence class as Key (that is, it's already in the
|
|
111 -- bucket implied by Key), then if the hash table is locked then
|
|
112 -- Program_Error is raised; otherwise Assign is called to assign Key to
|
|
113 -- Node. If Node is in a different bucket from Key, then Program_Error is
|
|
114 -- raised if the hash table is busy. Otherwise it Assigns Key to Node and
|
|
115 -- moves the Node from its current bucket to the bucket implied by Key.
|
|
116 -- Note that it is never proper to assign to Node a key value already
|
|
117 -- in the map, and so if Key is equivalent to some other node then
|
|
118 -- Program_Error is raised.
|
|
119
|
|
120 end Ada.Containers.Hash_Tables.Generic_Keys;
|