Files
mercury/tests/hard_coded/hash_table_delete.m
Julien Fischer d33647299a Rationalise hash functions across the standard library.
Currently, the hash functions for (some of) the primitive types are defined in
three places:

   1. The hash_table module.
   2. The version_hash_table module (duplicates of the above).
   3. Some (but not all) of the library modules for the primitive types.

This change makes the library module for a primitive type provide the hash
function for that type and deprecates the versions in the hash table modules.

Additionally, deprecate the "generic" has functions in the hash table modules.

library/hash_table.m:
library/version_hash_table.m:
    As above.

library/char.m:
library/int.m:
library/uint.m:
    Add hash/1 and hash/2.

library/float.m:
    Add hash/2.

library/robdd.m:
    Replace a call to the deprecated function.

NEWS:
    Announce the above additions and deprecations.

tests/hard_coded/hash_table_delete.m:
tests/hard_coded/hash_table_test.m:
tests/hard_coded/version_hash_table_delete.m:
tests/hard_coded/version_hash_table_test.m:
    Conform to the above change.
2020-02-11 14:22:42 +11:00

53 lines
1.5 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ts=4 sw=4 et ft=mercury
%---------------------------------------------------------------------------%
:- module hash_table_delete.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module hash_table.
:- import_module list.
:- import_module string.
%---------------------------------------------------------------------------%
main(!IO) :-
some [!HT] (
!:HT = hash_table.init_default(string.hash),
myfoldl(fill, keys, !HT),
myfoldl(hash_table.delete, keys, !HT),
Residue = hash_table.to_assoc_list(!.HT),
io.write(Residue, !IO),
io.nl(!IO)
).
:- pred myfoldl(pred(T, A, A), list(T), A, A).
:- mode myfoldl(in(pred(in, hash_table_di, hash_table_uo) is det), in,
hash_table_di, hash_table_uo) is det.
myfoldl(_, [], !HT).
myfoldl(P, [T | Ts], !HT) :-
P(T, !HT),
myfoldl(P, Ts, !HT).
:- func keys = list(string).
keys =
["aback", "abaft", "abandon", "abandoned", "abandoning", "abandonment",
"abandons", "abase", "abased", "abasement", "abasements", "abases"].
:- pred fill(string::in, hash_table(string, int)::hash_table_di,
hash_table(string, int)::hash_table_uo) is det.
fill(Key, !HT) :-
hash_table.det_insert(Key, string.length(Key), !HT).