mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-29 16:24:43 +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.
68 lines
1.7 KiB
Mathematica
68 lines
1.7 KiB
Mathematica
:- module hash_init_bug.
|
|
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io__state::di, io__state::uo) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module assoc_list, exception, hash_table, list.
|
|
:- import_module map, require, std_util, string.
|
|
|
|
main(!IO) :-
|
|
HashPred = (pred(Name::in, Hash::out) is det :-
|
|
sym_name_to_string(Name, ".", Str),
|
|
Hash = hash(Str)
|
|
),
|
|
HT0 = new(HashPred, 10, 0.8),
|
|
build_table(entries, HT0, HT),
|
|
(
|
|
hash_table__search(HT,
|
|
qualified(unqualified("io"), "read_word"), _)
|
|
->
|
|
io__write_string("error: search succeeded\n", !IO)
|
|
;
|
|
io__write_string("search failed as expected\n", !IO)
|
|
).
|
|
|
|
:- pred build_table(list(sym_name)::in, name_ht::hash_table_di,
|
|
name_ht::hash_table_uo) is det.
|
|
|
|
build_table([], HT, HT).
|
|
build_table([K | T], HT0, HT) :-
|
|
build_table(T, det_insert(HT0, K, 1), HT).
|
|
|
|
:- type name_ht == hash_table(sym_name, int).
|
|
|
|
:- type sym_name
|
|
---> unqualified(string)
|
|
; qualified(sym_name, string).
|
|
|
|
% sym_name_to_string(SymName, Separator, String):
|
|
% convert a symbol name to a string,
|
|
% with module qualifiers separated by Separator.
|
|
:- pred sym_name_to_string(sym_name, string, string).
|
|
:- mode sym_name_to_string(in, in, out) is det.
|
|
|
|
sym_name_to_string(SymName, Separator, String) :-
|
|
sym_name_to_string_2(SymName, Separator, Parts, []),
|
|
string__append_list(Parts, String).
|
|
|
|
:- pred sym_name_to_string_2(sym_name, string,
|
|
list(string), list(string)).
|
|
:- mode sym_name_to_string_2(in, in, out, in) is det.
|
|
|
|
sym_name_to_string_2(qualified(ModuleSpec,Name), Separator) -->
|
|
sym_name_to_string_2(ModuleSpec, Separator),
|
|
[Separator, Name].
|
|
sym_name_to_string_2(unqualified(Name), _) -->
|
|
[Name].
|
|
|
|
:- func entries = list(sym_name).
|
|
|
|
entries = [
|
|
unqualified("main")
|
|
].
|