Files
mercury/tests/hard_coded/version_hash_table_test_2.m
Zoltan Somogyi 38f1f5faf2 Shut up many warnings in executable test dirs.
tests/hard_coded/bitmap_test_helper_1.m:
tests/hard_coded/curry_2_helper_1.m:
tests/hard_coded/deep_copy_bug.m:
tests/hard_coded/erroneous_liveness.m:
tests/hard_coded/foreign_type_1.m:
tests/hard_coded/hash_table_test.m:
tests/hard_coded/ho_float_reg.m:
tests/hard_coded/impl_def_lex_string.m:
tests/hard_coded/impure_foreign.m:
tests/hard_coded/intermod_multimode_helper_1.m:
tests/hard_coded/multimode.m:
tests/hard_coded/qual_is_test.m:
tests/hard_coded/string_codepoint.m:
tests/hard_coded/string_codepoint_offset_ilseq.m:
tests/hard_coded/string_count_codepoints_ilseq.m:
tests/hard_coded/string_set_char.m:
tests/hard_coded/version_hash_table_test_2.m:
tests/submodules/parent_t2.m:
tests/typeclasses/arbitrary_constraint_pred_1.m:
tests/typeclasses/arbitrary_constraint_pred_2.m:
tests/typeclasses/instance_unconstrained_tvar_type_spec.m:
tests/typeclasses/typeclass_order_bug_1.m:
    Change code to avoid compiler warnings where this is (a) possible,
    and (b) does not interfere with the purpose of the test.

tests/hard_coded/string_codepoint.exp:
tests/hard_coded/string_codepoint_offset_ilseq.exp:
tests/hard_coded/string_codepoint_offset_ilseq.exp2:
    The changes to the source files of these tests changed all references
    to "codepoint" to "code_point", including in the text they output.
    Expect the updated output.

tests/general/Mercury.options:
tests/hard_coded/Mercury.options:
tests/typeclasses/Mercury.options:
tests/submodules/Mercury.options:
    Disable many of the remaining warnings.
2025-02-20 23:11:53 +11:00

137 lines
3.8 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
:- module version_hash_table_test_2.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module benchmarking.
:- import_module int.
:- import_module list.
:- import_module require.
:- import_module string.
:- import_module version_hash_table.
%---------------------------------------------------------------------------%
main(!IO) :-
io.command_line_arguments(Args, !IO),
(
Args = [],
A = "1000000",
B = "0.9"
;
Args = [A],
B = "0.9"
;
Args = [A, B | _]
),
Max = string.det_to_int(A),
MaxOccupancy = string.det_to_float(B),
some [!HT] (
!:HT = version_hash_table.init(int.hash, 1, MaxOccupancy),
io.write_string("Inserting elements\n", !IO),
int.fold_up(do_insert, 0, Max - 1, !HT),
trace [runtime(env("HASH_TABLE_STATS")), io(!TIO)] (
benchmarking.report_standard_stats(!TIO)
),
io.write_string("Looking up elements\n", !IO),
int.fold_up(do_lookup, 0, Max - 1, !HT),
trace [runtime(env("HASH_TABLE_STATS")), io(!TIO)] (
benchmarking.report_standard_stats(!TIO)
),
NumOccupants0 = version_hash_table.num_occupants(!.HT),
( if NumOccupants0 = Max then
true
else
error("num_occupants failed")
),
Half = Max / 2,
io.write_string("Deleting some elements\n", !IO),
int.fold_up(do_delete, 0, Half - 1, !HT),
trace [runtime(env("HASH_TABLE_STATS")), io(!TIO)] (
benchmarking.report_standard_stats(!TIO)
),
NumOccupants = version_hash_table.num_occupants(!.HT),
( if NumOccupants = Max - Half then
true
else
error("num_occupants failed")
),
AL = version_hash_table.to_assoc_list(!.HT),
( if list.length(AL) = NumOccupants then
true
else
error("to_assoc_list failed")
),
io.write_string("Replacing elements\n", !IO),
int.fold_up(do_replace_neg, 0, Max - 1, !HT),
trace [runtime(env("HASH_TABLE_STATS")), io(!TIO)] (
benchmarking.report_standard_stats(!TIO)
),
io.write_string("Looking up elements\n", !IO),
int.fold_up(do_lookup_neg, 0, Max - 1, !HT),
trace [runtime(env("HASH_TABLE_STATS")), io(!TIO)] (
benchmarking.report_standard_stats(!TIO)
),
_ = !.HT
).
:- pred do_insert(int::in, version_hash_table(int, int)::in,
version_hash_table(int, int)::out) is det.
do_insert(I, !HT) :-
version_hash_table.det_insert(I, I, !HT).
:- pred do_lookup(int::in, version_hash_table(int, int)::in,
version_hash_table(int, int)::out) is det.
do_lookup(I, !HT) :-
V = version_hash_table.lookup(!.HT, I),
( if I = V then
true
else
error("do_lookup failed")
).
:- pred do_lookup_neg(int::in, version_hash_table(int, int)::in,
version_hash_table(int, int)::out) is det.
do_lookup_neg(I, !HT) :-
V = version_hash_table.lookup(!.HT, I),
( if -I = V then
true
else
error("do_lookup failed")
).
:- pred do_delete(int::in, version_hash_table(int, int)::in,
version_hash_table(int, int)::out) is det.
do_delete(I, !HT) :-
version_hash_table.delete(I, !HT).
:- pred do_replace_neg(int::in, version_hash_table(int, int)::in,
version_hash_table(int, int)::out) is det.
do_replace_neg(I, !HT) :-
version_hash_table.set(I, -I, !HT).