1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- ADA.CONTAINERS.HASH_TABLES.GENERIC_KEYS --
9 -- Copyright (C) 2004-2007, 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 2, 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- This unit was originally developed by Matthew J Heaney. --
30 ------------------------------------------------------------------------------
32 -- Hash_Table_Type is used to implement hashed containers. This package
33 -- declares hash-table operations that depend on keys.
36 with package HT_Types is
37 new Generic_Hash_Table_Types (<>);
41 with function Next (Node : Node_Access) return Node_Access;
43 with procedure Set_Next
47 type Key_Type (<>) is limited private;
49 with function Hash (Key : Key_Type) return Hash_Type;
51 with function Equivalent_Keys
53 Node : Node_Access) return Boolean;
55 package Ada.Containers.Hash_Tables.Generic_Keys is
59 (HT : Hash_Table_Type;
60 Key : Key_Type) return Hash_Type;
61 pragma Inline (Index);
62 -- Returns the bucket number (array index value) for the given key
64 procedure Delete_Key_Sans_Free
65 (HT : in out Hash_Table_Type;
68 -- Removes the node (if any) with the given key from the hash table,
69 -- without deallocating it. Program_Error is raised if the hash
72 function Find (HT : Hash_Table_Type; Key : Key_Type) return Node_Access;
73 -- Returns the node (if any) corresponding to the given key
76 with function New_Node (Next : Node_Access) return Node_Access;
77 procedure Generic_Conditional_Insert
78 (HT : in out Hash_Table_Type;
80 Node : out Node_Access;
81 Inserted : out Boolean);
82 -- Attempts to insert a new node with the given key into the hash table.
83 -- If a node with that key already exists in the table, then that node
84 -- is returned and Inserted returns False. Otherwise New_Node is called
85 -- to allocate a new node, and Inserted returns True. Program_Error is
86 -- raised if the hash table is busy.
89 with function Hash (Node : Node_Access) return Hash_Type;
90 with procedure Assign (Node : Node_Access; Key : Key_Type);
91 procedure Generic_Replace_Element
92 (HT : in out Hash_Table_Type;
95 -- Assigns Key to Node, possibly changing its equivalence class. If Node
96 -- is in the same equivalence class as Key (that is, it's already in the
97 -- bucket implied by Key), then if the hash table is locked then
98 -- Program_Error is raised; otherwise Assign is called to assign Key to
99 -- Node. If Node is in a different bucket from Key, then Program_Error is
100 -- raised if the hash table is busy. Otherwise it Assigns Key to Node and
101 -- moves the Node from its current bucket to the bucket implied by Key.
102 -- Note that it is never proper to assign to Node a key value already
103 -- in the map, and so if Key is equivalent to some other node then
104 -- Program_Error is raised.
106 end Ada.Containers.Hash_Tables.Generic_Keys;