OSDN Git Service

2007-04-20 Ed Schonberg <schonberg@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / a-chtgke.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT LIBRARY COMPONENTS                          --
4 --                                                                          --
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              --
7 --                                                                          --
8 --                                 S p e c                                  --
9 --                                                                          --
10 --          Copyright (C) 2004-2006, Free Software Foundation, Inc.         --
11 --                                                                          --
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.                                              --
22 --                                                                          --
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.                                      --
29 --                                                                          --
30 -- This unit was originally developed by Matthew J Heaney.                  --
31 ------------------------------------------------------------------------------
32
33 --  Hash_Table_Type is used to implement hashed containers. This package
34 --  declares hash-table operations that depend on keys.
35
36 generic
37    with package HT_Types is
38      new Generic_Hash_Table_Types (<>);
39
40    use HT_Types;
41
42    with function Next (Node : Node_Access) return Node_Access;
43
44    with procedure Set_Next
45      (Node : Node_Access;
46       Next : Node_Access);
47
48    type Key_Type (<>) is limited private;
49
50    with function Hash (Key : Key_Type) return Hash_Type;
51
52    with function Equivalent_Keys
53      (Key  : Key_Type;
54       Node : Node_Access) return Boolean;
55
56 package Ada.Containers.Hash_Tables.Generic_Keys is
57    pragma Preelaborate;
58
59    function Index
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
64
65    procedure Delete_Key_Sans_Free
66      (HT  : in out Hash_Table_Type;
67       Key : Key_Type;
68       X   : out Node_Access);
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
71    --  table is busy.
72
73    function Find (HT : Hash_Table_Type; Key : Key_Type) return Node_Access;
74    --  Returns the node (if any) corresponding to the given key
75
76    generic
77       with function New_Node (Next : Node_Access) return Node_Access;
78    procedure Generic_Conditional_Insert
79      (HT       : in out Hash_Table_Type;
80       Key      : Key_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.
88
89    generic
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;
94       Node : Node_Access;
95       Key  : Key_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.
106
107 end Ada.Containers.Hash_Tables.Generic_Keys;