mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-18 19:03:45 +00:00
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.
42 lines
1.2 KiB
Mathematica
42 lines
1.2 KiB
Mathematica
%---------------------------------------------------------------------------%
|
|
% vim: ts=4 sw=4 et ft=mercury
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module version_hash_table_test.
|
|
:- interface.
|
|
|
|
:- import_module io.
|
|
|
|
:- pred main(io::di, io::uo) is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module list.
|
|
:- import_module pair.
|
|
:- import_module string.
|
|
:- import_module version_hash_table.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
main(!IO) :-
|
|
% Test `fold' which had an off-by-one bug.
|
|
some [!HT] (
|
|
!:HT = version_hash_table.init_default(string.hash),
|
|
version_hash_table.set("one", 1, !HT),
|
|
version_hash_table.set("two", 2, !HT),
|
|
version_hash_table.set("three", 3, !HT),
|
|
version_hash_table.fold(concat, !.HT, []) = KVs,
|
|
list.sort(KVs, SortedKVs),
|
|
io.write(SortedKVs, !IO),
|
|
io.nl(!IO)
|
|
).
|
|
|
|
:- func concat(K, V, list(pair(K, V))) = list(pair(K, V)).
|
|
|
|
concat(K, V, Acc) = [K - V | Acc].
|
|
|
|
%---------------------------------------------------------------------------%
|