1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- ADA.CONTAINERS.HASH_TABLES.GENERIC_BOUNDED_OPERATIONS --
9 -- Copyright (C) 2004-2010, 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 3, 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. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- This unit was originally developed by Matthew J Heaney. --
28 ------------------------------------------------------------------------------
30 -- Hash_Table_Type is used to implement hashed containers. This package
31 -- declares hash-table operations that do not depend on keys.
36 with package HT_Types
is
37 new Generic_Bounded_Hash_Table_Types
(<>);
41 with function Hash_Node
(Node
: Node_Type
) return Hash_Type
;
43 with function Next
(Node
: Node_Type
) return Count_Type
;
45 with procedure Set_Next
46 (Node
: in out Node_Type
;
49 package Ada
.Containers
.Hash_Tables
.Generic_Bounded_Operations
is
53 (Buckets
: Buckets_Type
;
54 Node
: Node_Type
) return Hash_Type
;
55 pragma Inline
(Index
);
56 -- Uses the hash value of Node to compute its Buckets array index
59 (HT
: Hash_Table_Type
'Class;
60 Node
: Node_Type
) return Hash_Type
;
61 pragma Inline
(Index
);
62 -- Uses the hash value of Node to compute its Hash_Table buckets array
67 (HT
: Hash_Table_Type
'Class;
68 Key
: Node_Type
) return Boolean;
69 function Generic_Equal
(L
, R
: Hash_Table_Type
'Class) return Boolean;
70 -- Used to implement hashed container equality. For each node in hash table
71 -- L, it calls Find to search for an equivalent item in hash table R. If
72 -- Find returns False for any node then Generic_Equal terminates
73 -- immediately and returns False. Otherwise if Find returns True for every
74 -- node then Generic_Equal returns True.
76 procedure Clear
(HT
: in out Hash_Table_Type
'Class);
77 -- Deallocates each node in hash table HT. (Note that it only deallocates
78 -- the nodes, not the buckets array.) Program_Error is raised if the hash
81 procedure Delete_Node_Sans_Free
82 (HT
: in out Hash_Table_Type
'Class;
84 -- Removes node X from the hash table without deallocating the node
87 with procedure Set_Element
(Node
: in out Node_Type
);
88 procedure Generic_Allocate
89 (HT
: in out Hash_Table_Type
'Class;
90 Node
: out Count_Type
);
91 -- Claim a node from the free store. Generic_Allocate first
92 -- calls Set_Element on the potential node, and then returns
93 -- the node's index as the value of the Node parameter.
96 (HT
: in out Hash_Table_Type
'Class;
98 -- Return a node back to the free store, from where it had
99 -- been previously claimed via Generic_Allocate.
101 function First
(HT
: Hash_Table_Type
'Class) return Count_Type
;
102 -- Returns the head of the list in the first (lowest-index) non-empty
106 (HT
: Hash_Table_Type
'Class;
107 Node
: Count_Type
) return Count_Type
;
108 -- Returns the node that immediately follows Node. This corresponds to
109 -- either the next node in the same bucket, or (if Node is the last node in
110 -- its bucket) the head of the list in the first non-empty bucket that
114 with procedure Process
(Node
: Count_Type
);
115 procedure Generic_Iteration
(HT
: Hash_Table_Type
'Class);
116 -- Calls Process for each node in hash table HT
121 (Stream
: not null access Root_Stream_Type
'Class;
123 procedure Generic_Write
124 (Stream
: not null access Root_Stream_Type
'Class;
125 HT
: Hash_Table_Type
'Class);
126 -- Used to implement the streaming attribute for hashed containers. It
127 -- calls Write for each node to write its value into Stream.
131 with function New_Node
(Stream
: not null access Root_Stream_Type
'Class)
133 procedure Generic_Read
134 (Stream
: not null access Root_Stream_Type
'Class;
135 HT
: out Hash_Table_Type
'Class);
136 -- Used to implement the streaming attribute for hashed containers. It
137 -- first clears hash table HT, then populates the hash table by calling
138 -- New_Node for each item in Stream.
140 end Ada
.Containers
.Hash_Tables
.Generic_Bounded_Operations
;