mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-30 16:54:41 +00:00
Branches: main Replace the implementations of (version) hash tables by separate chaining hash tables. The old open addressing scheme was broken in the presence of deletes. Fixes bug #68. library/hash_table.m: library/version_hash_table.m: As above. We no longer use double hashing in case of a hash collision, so hash predicates only need to return one value now. Add fold with predicate arguments. library/array.m: Add array.foldl for a predicate argument. Add array.foldl2 with a unique state pair. library/version_array.m: Add version_array.foldl for a predicate argument. compiler/make.m: compiler/make.program_target.m: compiler/make.util.m: library/robdd.m: Conform to change in hashing predicates. deep_profiler/dense_bitset.m: Add module qualifier to avoid ambiguity. tests/hard_coded/Mmakefile: tests/hard_coded/hash_table_delete.exp: tests/hard_coded/hash_table_delete.m: tests/hard_coded/hash_table_test.exp: tests/hard_coded/hash_table_test.m: tests/hard_coded/version_hash_table_delete.exp: tests/hard_coded/version_hash_table_delete.m: tests/hard_coded/version_hash_table_test2.exp: tests/hard_coded/version_hash_table_test2.m: Add new test cases. tests/hard_coded/hash_bug.m: tests/hard_coded/hash_init_bug.m: tests/hard_coded/version_hash_table_test.m: Conform to change in hashing predicates. NEWS: Document additions.
55 lines
1.5 KiB
Mathematica
55 lines
1.5 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
|
|
:- module hash_table_delete.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module list.
|
|
:- import_module string.
|
|
:- import_module hash_table.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
main(!IO) :-
|
|
some [!HT] (
|
|
!:HT = hash_table.new_default(generic_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).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=8 sw=4 et wm=0 tw=0
|