1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- A D A . C O N T A I N E R S . --
6 -- H A S H _ T A B L E S . G E N E R I C _ K E Y S --
10 -- Copyright (C) 2004-2006, Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
21 -- Boston, MA 02110-1301, USA. --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
30 -- This unit was originally developed by Matthew J Heaney. --
31 ------------------------------------------------------------------------------
33 -- Hash_Table_Type is used to implement hashed containers. This package
34 -- declares hash-table operations that depend on keys.
37 with package HT_Types is
38 new Generic_Hash_Table_Types (<>);
42 with function Next (Node : Node_Access) return Node_Access;
44 with procedure Set_Next
48 type Key_Type (<>) is limited private;
50 with function Hash (Key : Key_Type) return Hash_Type;
52 with function Equivalent_Keys
54 Node : Node_Access) return Boolean;
56 package Ada.Containers.Hash_Tables.Generic_Keys is
60 (HT : Hash_Table_Type;
61 Key : Key_Type) return Hash_Type;
62 pragma Inline (Index);
63 -- Returns the bucket number (array index value) for the given key
65 procedure Delete_Key_Sans_Free
66 (HT : in out Hash_Table_Type;
69 -- Removes the node (if any) with the given key from the hash table,
70 -- without deallocating it. Program_Error is raised if the hash
73 function Find (HT : Hash_Table_Type; Key : Key_Type) return Node_Access;
74 -- Returns the node (if any) corresponding to the given key
77 with function New_Node (Next : Node_Access) return Node_Access;
78 procedure Generic_Conditional_Insert
79 (HT : in out Hash_Table_Type;
81 Node : out Node_Access;
82 Inserted : out Boolean);
83 -- Attempts to insert a new node with the given key into the hash table.
84 -- If a node with that key already exists in the table, then that node
85 -- is returned and Inserted returns False. Otherwise New_Node is called
86 -- to allocate a new node, and Inserted returns True. Program_Error is
87 -- raised if the hash table is busy.
90 with function Hash (Node : Node_Access) return Hash_Type;
91 with procedure Assign (Node : Node_Access; Key : Key_Type);
92 procedure Generic_Replace_Element
93 (HT : in out Hash_Table_Type;
96 -- Assigns Key to Node, possibly changing its equivalence class. If Node
97 -- is in the same equivalence class as Key (that is, it's already in the
98 -- bucket implied by Key), then if the hash table is locked then
99 -- Program_Error is raised; otherwise Assign is called to assign Key to
100 -- Node. If Node is in a different bucket from Key, then Program_Error is
101 -- raised if the hash table is busy. Otherwise it Assigns Key to Node and
102 -- moves the Node from its current bucket to the bucket implied by Key.
103 -- Note that it is never proper to assign to Node a key value already
104 -- in the map, and so if Key is equivalent to some other node then
105 -- Program_Error is raised.
107 end Ada.Containers.Hash_Tables.Generic_Keys;