1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- ADA.CONTAINERS.HASH_TABLES.GENERIC_KEYS --
9 -- Copyright (C) 2004 Free Software Foundation, Inc. --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the contents of the part following the private keyword. --
15 -- GNAT is free software; you can redistribute it and/or modify it under --
16 -- terms of the GNU General Public License as published by the Free Soft- --
17 -- ware Foundation; either version 2, or (at your option) any later ver- --
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
21 -- for more details. You should have received a copy of the GNU General --
22 -- Public License distributed with GNAT; see file COPYING. If not, write --
23 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
24 -- MA 02111-1307, USA. --
26 -- As a special exception, if other files instantiate generics from this --
27 -- unit, or you link this unit with other files to produce an executable, --
28 -- this unit does not by itself cause the resulting executable to be --
29 -- covered by the GNU General Public License. This exception does not --
30 -- however invalidate any other reasons why the executable file might be --
31 -- covered by the GNU Public License. --
33 -- This unit was originally developed by Matthew J Heaney. --
34 ------------------------------------------------------------------------------
36 package body Ada.Containers.Hash_Tables.Generic_Keys is
38 --------------------------
39 -- Delete_Key_Sans_Free --
40 --------------------------
42 procedure Delete_Key_Sans_Free
56 Indx := Index (HT, Key);
57 X := HT.Buckets (Indx);
63 if Equivalent_Keys (Key, X) then
64 HT.Buckets (Indx) := Next (X);
65 HT.Length := HT.Length - 1;
77 if Equivalent_Keys (Key, X) then
78 Set_Next (Node => Prev, Next => Next (X));
79 HT.Length := HT.Length - 1;
83 end Delete_Key_Sans_Free;
91 Key : Key_Type) return Node_Access is
101 Indx := Index (HT, Key);
103 Node := HT.Buckets (Indx);
104 while Node /= Null_Node loop
105 if Equivalent_Keys (Key, Node) then
114 --------------------------------
115 -- Generic_Conditional_Insert --
116 --------------------------------
118 procedure Generic_Conditional_Insert
119 (HT : in out HT_Type;
121 Node : out Node_Access;
122 Success : out Boolean)
124 Indx : constant Hash_Type := Index (HT, Key);
125 B : Node_Access renames HT.Buckets (Indx);
127 subtype Length_Subtype is Count_Type range 0 .. Count_Type'Last - 1;
130 if B = Null_Node then
132 Length : constant Length_Subtype := HT.Length;
134 Node := New_Node (Next => Null_Node);
138 HT.Length := Length + 1;
146 if Equivalent_Keys (Key, Node) then
153 exit when Node = Null_Node;
157 Length : constant Length_Subtype := HT.Length;
159 Node := New_Node (Next => B);
163 HT.Length := Length + 1;
165 end Generic_Conditional_Insert;
173 Key : Key_Type) return Hash_Type is
175 return Hash (Key) mod HT.Buckets'Length;
178 end Ada.Containers.Hash_Tables.Generic_Keys;