OSDN Git Service

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