[m-rev.] diff: delete obsolete hash predicates

Julien Fischer jfischer at opturion.com
Sun Apr 3 13:38:34 AEST 2022


Delete obsolete hash predicates.

library/hash_table.m:
library/version_hash_table.m:
      Delete hash predicates that were made obsolete in Mercury 20.06.

tests/hard_coded/test_int_hash.m:
      Replace a call to a now deleted predicate.

NEWS:
      Announce the deletions.

Julien.

diff --git a/NEWS b/NEWS
index 78e9107..c3abee9 100644
--- a/NEWS
+++ b/NEWS
@@ -55,6 +55,17 @@ Changes to the Mercury standard library
      - pred `write_bitmap_range/5`
      - pred `write_bitmap_range/6`

+### Changes to the `hash_table` module
+
+The following obsolete predicates have been removed:
+
+    - pred `char_hash/2`
+    - pred `float_hash/2`
+    - pred `generic_hash/2`
+    - pred `int_hash/2`
+    - pred `string_hash/2`
+    - pred `uint_hash/2`
+
  ### Changes to the `io` module

  * The following obsolete predicates have been removed:
@@ -235,6 +246,17 @@ As a result, the following predicates have been removed:

      - pred `sorted_keys_match/2`

+### Changes to the `version_hash_table` module
+
+The following obsolete predicates have been removed:
+
+    - pred `char_hash/2`
+    - pred `float_hash/2`
+    - pred `generic_hash/2`
+    - pred `int_hash/2`
+    - pred `string_hash/2`
+    - pred `uint_hash/2`
+
  Changes to the Mercury compiler
  -------------------------------

diff --git a/library/hash_table.m b/library/hash_table.m
index 597f20b..359e545 100644
--- a/library/hash_table.m
+++ b/library/hash_table.m
@@ -2,7 +2,7 @@
  % vim: ts=4 sw=4 et ft=mercury
  %---------------------------------------------------------------------------%
  % Copyright (C) 2001, 2003-2006, 2010-2012 The University of Melbourne
-% Copyright (C) 2013-2020 The Mercury team.
+% Copyright (C) 2013-2022 The Mercury team.
  % This file is distributed under the terms specified in COPYING.LIB.
  %---------------------------------------------------------------------------%
  %
@@ -38,7 +38,6 @@

  :- import_module array.
  :- import_module assoc_list.
-:- import_module char.

  %---------------------------------------------------------------------------%

@@ -251,38 +250,17 @@
      hash_table_ui, in, out, in, out, di, uo) is semidet.

  %---------------------------------------------------------------------------%
-
-    % Default hash_preds for ints and strings and everything (buwahahaha!)
-    %
-:- pragma obsolete(pred(int_hash/2), [int.hash/2]).
-:- pred int_hash(int::in, int::out) is det.
-:- pragma obsolete(pred(uint_hash/2), [uint.hash/2]).
-:- pred uint_hash(uint::in, int::out) is det.
-:- pragma obsolete(pred(float_hash/2), [float.hash/2]).
-:- pred float_hash(float::in, int::out) is det.
-:- pragma obsolete(pred(char_hash/2), [char.hash/2]).
-:- pred char_hash(char::in, int::out) is det.
-:- pragma obsolete(pred(string_hash/2), [string.hash/2]).
-:- pred string_hash(string::in, int::out) is det.
-:- pragma obsolete(pred(generic_hash/2)).
-:- pred generic_hash(T::in, int::out) is det.
-
-%---------------------------------------------------------------------------%
  %---------------------------------------------------------------------------%

  :- implementation.

  :- import_module bool.
-:- import_module deconstruct.
  :- import_module float.
  :- import_module int.
  :- import_module kv_list.
  :- import_module list.
  :- import_module pair.
  :- import_module require.
-:- import_module string.
-:- import_module uint.
-:- import_module univ.

  %---------------------------------------------------------------------------%

@@ -895,63 +873,5 @@ fold3_p(P, HB, !A, !B, !C) :-
      ).

  %---------------------------------------------------------------------------%
-
-int_hash(Key, Hash) :-
-    UKey = uint.cast_from_int(Key),
-    uint_hash(UKey, Hash).
-
-uint_hash(Key, Hash) :-
-    uint.hash(Key, Hash).
-
-float_hash(F, Hash) :-
-    float.hash(F, Hash).
-
-char_hash(C, Hash) :-
-    char.hash(C, Hash).
-
-string_hash(S, Hash) :-
-    string.hash(S, Hash).
-
-%---------------------------------------------------------------------------%
-
-generic_hash(T, Hash) :-
-    % This, again, is straight off the top of [rafe's] head.
-    %
-    ( if dynamic_cast(T, Int) then
-        int_hash(Int, Hash)
-    else if dynamic_cast(T, String) then
-        string_hash(String, Hash)
-    else if dynamic_cast(T, Float) then
-        float_hash(Float, Hash)
-    else if dynamic_cast(T, Char) then
-        char_hash(Char, Hash)
-    else if dynamic_cast(T, Univ) then
-        generic_hash(univ_value(Univ), Hash)
-    else if dynamic_cast_to_array(T, Array) then
-        array.foldl(hash_and_accumulate_hash_value, Array, 0, Hash)
-    else
-        deconstruct(T, canonicalize, FunctorName, Arity, Args),
-        string_hash(FunctorName, Hash0),
-        accumulate_hash_value(Arity, Hash0, Hash1),
-        list.foldl(hash_and_accumulate_hash_value, Args, Hash1, Hash)
-    ).
-
-:- pragma obsolete(pred(hash_and_accumulate_hash_value/3)).
-:- pred hash_and_accumulate_hash_value(T::in, int::in, int::out) is det.
-
-hash_and_accumulate_hash_value(T, !HashAcc) :-
-    generic_hash(T, HashValue),
-    accumulate_hash_value(HashValue, !HashAcc).
-
-:- pred accumulate_hash_value(int::in, int::in, int::out) is det.
-
-accumulate_hash_value(HashValue, HashAcc0, HashAcc) :-
-    % XXX This is a REALLY BAD algorithm, with shift amounts that
-    % will routinely exceed the word size.
-    HashAcc =
-        (HashAcc0 `unchecked_left_shift` HashValue) `xor`
-        (HashAcc0 `unchecked_right_shift` (int.bits_per_int - HashValue)).
-
-%---------------------------------------------------------------------------%
  :- end_module hash_table.
  %---------------------------------------------------------------------------%
diff --git a/library/version_hash_table.m b/library/version_hash_table.m
index 2d1e72b..5a2fa60 100644
--- a/library/version_hash_table.m
+++ b/library/version_hash_table.m
@@ -2,7 +2,7 @@
  % vim: ft=mercury ts=4 sw=4 et
  %---------------------------------------------------------------------------%
  % Copyright (C) 2004-2006, 2010-2012 The University of Melbourne.
-% Copyright (C) 2013-2015, 2017-2020 The Mercury team.
+% Copyright (C) 2013-2015, 2017-2022 The Mercury team.
  % This file is distributed under the terms specified in COPYING.LIB.
  %---------------------------------------------------------------------------%
  %
@@ -25,7 +25,6 @@
  :- interface.

  :- import_module assoc_list.
-:- import_module char.

  %---------------------------------------------------------------------------%

@@ -89,23 +88,6 @@
      %
  :- func num_occupants(version_hash_table(K, V)) = int.

-    % Default hash_preds for ints and strings and everything.
-    % They are very simple and almost certainly not very good
-    % for your purpose, whatever your purpose is.
-    %
-:- pred int_hash(int::in, int::out) is det.
-:- pragma obsolete(pred(int_hash/2), [int.hash/2]).
-:- pred uint_hash(uint::in, int::out) is det.
-:- pragma obsolete(pred(uint_hash/2), [uint.hash/2]).
-:- pred char_hash(char::in, int::out) is det.
-:- pragma obsolete(pred(char_hash/2), [char.hash/2]).
-:- pred string_hash(string::in, int::out) is det.
-:- pragma obsolete(pred(string_hash/2), [string.hash/2]).
-:- pred float_hash(float::in, int::out) is det.
-:- pragma obsolete(pred(float_hash/2), [float.hash/2]).
-:- pred generic_hash(T::in, int::out) is det.
-:- pragma obsolete(pred(generic_hash/2)).
-
      % Copy the hash table explicitly.
      %
      % An explicit copy allows programmers to control the cost of copying
@@ -214,19 +196,14 @@

  :- implementation.

-:- import_module array.
  :- import_module bool.
-:- import_module deconstruct.
  :- import_module exception.
  :- import_module float.
  :- import_module int.
  :- import_module list.
  :- import_module pair.
  :- import_module require.
-:- import_module string.
-:- import_module uint.
  :- import_module unit.
-:- import_module univ.
  :- import_module version_array.

  %---------------------------------------------------------------------------%
@@ -353,54 +330,6 @@ find_slot_2(HashPred, K, NumBuckets, H) :-

  %---------------------------------------------------------------------------%

-int_hash(Key, Hash) :-
-    int.hash(Key, Hash).
-
-uint_hash(Key, Hash) :-
-    uint.hash(Key, Hash).
-
-char_hash(C, H) :-
-    char.hash(C, H).
-
-string_hash(S, H) :-
-    string.hash(S, H).
-
-float_hash(F, H) :-
-    float.hash(F, H).
-
-generic_hash(T, H) :-
-    % This, again, is straight off the top of my head.
-    ( if dynamic_cast(T, Int) then
-        int_hash(Int, H)
-    else if dynamic_cast(T, String) then
-        string_hash(String, H)
-    else if dynamic_cast(T, Float) then
-        float_hash(Float, H)
-    else if dynamic_cast(T, Char) then
-        char_hash(Char, H)
-    else if dynamic_cast(T, Univ) then
-        generic_hash(univ_value(Univ), H)
-    else if dynamic_cast_to_array(T, Array) then
-        SubHash =
-            ( func(X, HA0) = HA :-
-                generic_hash(X, HX),
-                munge(HX, HA0) = HA
-            ),
-        H = array.foldl(SubHash, Array, 0)
-    else
-        deconstruct(T, canonicalize, FunctorName, Arity, Args),
-        string_hash(FunctorName, H0),
-        munge(Arity, H0) = H1,
-        SubHash =
-            ( pred(U::in, HA0::in, HA::out) is det :-
-                generic_hash(U, HUA),
-                munge(HUA, HA0) = HA
-            ),
-        list.foldl(SubHash, Args, H1, H)
-    ).
-
-%---------------------------------------------------------------------------%
-
  copy(HT0) = HT :-
      promise_equivalent_solutions [HT] (
          HT0 = ht(NumOccupants, MaxOccupants, HashPred, Buckets0),
@@ -726,14 +655,6 @@ unsafe_insert(K, V, HashPred, NumBuckets, Buckets0, Buckets) :-

  %---------------------------------------------------------------------------%

-:- func munge(int, int) = int.
-
-munge(N, X) =
-    (X `unchecked_left_shift` N) `xor`
-    (X `unchecked_right_shift` (int.bits_per_int - N)).
-
-%---------------------------------------------------------------------------%
-
  fold(F, HT, X0) = X :-
      promise_equivalent_solutions [Buckets] (
          Buckets = HT ^ ht_buckets
diff --git a/tests/hard_coded/test_int_hash.m b/tests/hard_coded/test_int_hash.m
index cb0d7cd..4293514 100644
--- a/tests/hard_coded/test_int_hash.m
+++ b/tests/hard_coded/test_int_hash.m
@@ -37,7 +37,7 @@ main(!IO) :-

  do_test(_, !RNG, !NumFails, !IO) :-
      next(Num, !RNG),
-    int_hash(Num, LibHash),
+    int.hash(Num, LibHash),
      cint_hash(Num, OrigHash),
      %io.format("hash(%d) = %d\n", [i(Num), i(LibHash)], !IO),
      ( if LibHash = OrigHash then


More information about the reviews mailing list