--------------------
package body Dynamic_HTable is
- Minimum_Size : constant Bucket_Range_Type := 32;
+ Minimum_Size : constant Bucket_Range_Type := 8;
-- Minimum size of the buckets
Safe_Compression_Size : constant Bucket_Range_Type :=
procedure Ensure_Unlocked (T : Instance);
pragma Inline (Ensure_Unlocked);
- -- Verify that hash table T is unlocked. Raise Table_Locked if this is
- -- not the case.
+ -- Verify that hash table T is unlocked. Raise Iterated if this is not
+ -- the case.
function Find_Bucket
(Bkts : Bucket_Table_Ptr;
-- Create --
------------
- function Create (Initial_Size : Bucket_Range_Type) return Instance is
+ function Create (Initial_Size : Positive) return Instance is
Size : constant Bucket_Range_Type :=
- Bucket_Range_Type'Max (Initial_Size, Minimum_Size);
+ Bucket_Range_Type'Max
+ (Bucket_Range_Type (Initial_Size), Minimum_Size);
-- Ensure that the buckets meet a minimum size
T : constant Instance := new Hash_Table;
-- The hash table has at least one outstanding iterator
- if T.Locked > 0 then
- raise Table_Locked;
+ if T.Iterators > 0 then
+ raise Iterated;
end if;
end Ensure_Unlocked;
Nod := Head.Next;
while Is_Valid (Nod, Head) loop
- if Equivalent_Keys (Nod.Key, Key) then
+ if Nod.Key = Key then
return Nod;
end if;
return Is_OK;
end Has_Next;
+ --------------
+ -- Is_Empty --
+ --------------
+
+ function Is_Empty (T : Instance) return Boolean is
+ begin
+ Ensure_Created (T);
+
+ return T.Pairs = 0;
+ end Is_Empty;
+
--------------
-- Is_Valid --
--------------
-- The hash table may be locked multiple times if multiple iterators
-- are operating over it.
- T.Locked := T.Locked + 1;
+ T.Iterators := T.Iterators + 1;
end Lock;
-----------------------
-- Put --
---------
- procedure Put
- (T : Instance;
- Key : Key_Type;
- Value : Value_Type)
- is
+ procedure Put (T : Instance; Key : Key_Type; Value : Value_Type) is
procedure Expand;
pragma Inline (Expand);
-- Determine whether hash table T requires expansion, and if so,
Nod := Head.Next;
while Is_Valid (Nod, Head) loop
- if Equivalent_Keys (Nod.Key, Key) then
+ if Nod.Key = Key then
Nod.Value := Value;
return;
end if;
-- Size --
----------
- function Size (T : Instance) return Pair_Count_Type is
+ function Size (T : Instance) return Natural is
begin
Ensure_Created (T);
-- The hash table may be locked multiple times if multiple iterators
-- are operating over it.
- T.Locked := T.Locked - 1;
+ T.Iterators := T.Iterators - 1;
end Unlock;
end Dynamic_HTable;