| 1 |
-- { dg-do run } |
| 2 |
|
| 3 |
with Ada.Text_IO; use Ada.Text_IO; |
| 4 |
with GNAT; use GNAT; |
| 5 |
with GNAT.Dynamic_HTables; use GNAT.Dynamic_HTables; |
| 6 |
|
| 7 |
procedure Dynhash1 is |
| 8 |
procedure Destroy (Val : in out Integer) is null; |
| 9 |
function Hash (Key : Integer) return Bucket_Range_Type is |
| 10 |
begin |
| 11 |
return Bucket_Range_Type (Key); |
| 12 |
end Hash; |
| 13 |
|
| 14 |
package Integer_Hash_Tables is new Dynamic_Hash_Tables |
| 15 |
(Key_Type => Integer, |
| 16 |
Value_Type => Integer, |
| 17 |
No_Value => 0, |
| 18 |
Expansion_Threshold => 1.3, |
| 19 |
Expansion_Factor => 2, |
| 20 |
Compression_Threshold => 0.3, |
| 21 |
Compression_Factor => 2, |
| 22 |
"=" => "=", |
| 23 |
Destroy_Value => Destroy, |
| 24 |
Hash => Hash); |
| 25 |
use Integer_Hash_Tables; |
| 26 |
|
| 27 |
Siz : Natural; |
| 28 |
T : Dynamic_Hash_Table; |
| 29 |
|
| 30 |
begin |
| 31 |
T := Create (8); |
| 32 |
|
| 33 |
Put (T, 1, 1); |
| 34 |
Put (T, 1, 2); |
| 35 |
Put (T, 1, 3); |
| 36 |
|
| 37 |
Siz := Size (T); |
| 38 |
|
| 39 |
if Siz /= 1 then |
| 40 |
Put_Line ("ERROR: Put: wrong size"); |
| 41 |
Put_Line ("expected: 1"); |
| 42 |
Put_Line ("got :" & Siz'Img); |
| 43 |
end if; |
| 44 |
|
| 45 |
Delete (T, 1); |
| 46 |
Delete (T, 1); |
| 47 |
|
| 48 |
Siz := Size (T); |
| 49 |
|
| 50 |
if Siz /= 0 then |
| 51 |
Put_Line ("ERROR: Delete: wrong size"); |
| 52 |
Put_Line ("expected: 0"); |
| 53 |
Put_Line ("got :" & Siz'Img); |
| 54 |
end if; |
| 55 |
|
| 56 |
Destroy (T); |
| 57 |
end Dynhash1; |