Skip to content

Replace generic hash table by functorial in WeakTopological#99

Merged
backtracking merged 1 commit intobacktracking:masterfrom
TDacik:fix_wto_hashtable_comparison
Mar 30, 2020
Merged

Replace generic hash table by functorial in WeakTopological#99
backtracking merged 1 commit intobacktracking:masterfrom
TDacik:fix_wto_hashtable_comparison

Conversation

@TDacik
Copy link
Contributor

@TDacik TDacik commented Mar 28, 2020

In WeakTopological module, a generic hash table is used to store vertices. This could result in the error when a custom compare function is used. A trivial example is:

open Graph

module V = struct
  type t = int * int
  let compare x y = Pervasives.compare (fst x) (fst y)
  let equal x y = Pervasives.(=) (fst x) (fst y)
  let hash x = Hashtbl.hash (fst x)
end

module G = Imperative.Digraph.ConcreteBidirectional(V)
module WTO = WeakTopological.Make(G)

let () =
  let g = G.create () in
  G.add_edge g (1,0) (2,0);
  G.add_edge g (1,0) (3,0);
  G.add_edge g (2,0) (4,0);
  G.add_edge g (3,0) (4,1);
  let _ = WTO.recursive_scc g (1,0) in
  ()

During iterating on successors of the vertex (3,0) at WeakTopological:L65, due to use of Pervasives.compare function by the generic hash table, search of the vertex (4,1) raises Not_found exception, because only the vertex (4,0) is present.

I believe this could be fixed by using a functorial hash table.

@thizanne
Copy link
Contributor

The fix looks perfect. Do you think your example should be added to tests/test_wto.ml ?

@backtracking
Copy link
Owner

Good catch. Many thanks for the fix.

@backtracking backtracking merged commit 9f79a0c into backtracking:master Mar 30, 2020
@TDacik
Copy link
Contributor Author

TDacik commented Mar 30, 2020

The fix looks perfect. Do you think your example should be added to tests/test_wto.ml ?

I don't think this can be reintroduced again so adding the test is not necessary.

@TDacik TDacik deleted the fix_wto_hashtable_comparison branch March 30, 2020 14:49
backtracking added a commit to backtracking/opam-repository that referenced this pull request Oct 2, 2020
CHANGES:

- port to dune and opam 2.0
  - ❗ opam package now split into two packages: ocamlgraph and ocamlgraph_gtk
  - [WeakTopological] fixed incorrect use of generic hash tables
    (backtracking/ocamlgraph#99, Tomáš Dacík)
  - [Oper] fixed transitive_reduction (backtracking/ocamlgraph#91)
  - fix incorrect uses of polymorphic equality (Steffen Smolka, Boris Yakobowski)
  - [Coloring] fixed generation of OCamlDoc documentation
    (contributed by Earnestly)
  - ❗ [Coloring] functions now fail if the graph is directed
  - ❗ [Coloring] now uses a single, global exception [NoColoring]
  - [Coloring] new function two_color to 2-color a graph (or fail)
  - ❗ [Fixpoint] Take initial labeling of nodes into account (Johannes Kloos)
mseri pushed a commit to ocaml/opam-repository that referenced this pull request Oct 8, 2020
* [new release] ocamlgraph_gtk and ocamlgraph (2.0.0)

CHANGES:

- port to dune and opam 2.0
  - ❗ opam package now split into two packages: ocamlgraph and ocamlgraph_gtk
  - [WeakTopological] fixed incorrect use of generic hash tables
    (backtracking/ocamlgraph#99, Tomáš Dacík)
  - [Oper] fixed transitive_reduction (backtracking/ocamlgraph#91)
  - fix incorrect uses of polymorphic equality (Steffen Smolka, Boris Yakobowski)
  - [Coloring] fixed generation of OCamlDoc documentation
    (contributed by Earnestly)
  - ❗ [Coloring] functions now fail if the graph is directed
  - ❗ [Coloring] now uses a single, global exception [NoColoring]
  - [Coloring] new function two_color to 2-color a graph (or fail)
  - ❗ [Fixpoint] Take initial labeling of nodes into account (Johannes Kloos)

* ocamlgraph.2.0.0: added depends graphics with-test

* ocamlgraph_gtk.2.0.0: added depends graphics with-test

* ocamlgraph 2.0.0 requires OCaml >= 4.03.0

* added a constraint 'ocamlgraph <= 1.8.8'

* better constraints (suggested by David Allsopp)
fdopen added a commit to fdopen/opam-repository-mingw that referenced this pull request Oct 8, 2020
* [new release] ocamlgraph_gtk and ocamlgraph (2.0.0)

CHANGES:

- port to dune and opam 2.0
  - ❗ opam package now split into two packages: ocamlgraph and ocamlgraph_gtk
  - [WeakTopological] fixed incorrect use of generic hash tables
    (backtracking/ocamlgraph#99, Tomáš Dacík)
  - [Oper] fixed transitive_reduction (backtracking/ocamlgraph#91)
  - fix incorrect uses of polymorphic equality (Steffen Smolka, Boris Yakobowski)
  - [Coloring] fixed generation of OCamlDoc documentation
    (contributed by Earnestly)
  - ❗ [Coloring] functions now fail if the graph is directed
  - ❗ [Coloring] now uses a single, global exception [NoColoring]
  - [Coloring] new function two_color to 2-color a graph (or fail)
  - ❗ [Fixpoint] Take initial labeling of nodes into account (Johannes Kloos)

* ocamlgraph.2.0.0: added depends graphics with-test

* ocamlgraph_gtk.2.0.0: added depends graphics with-test

* ocamlgraph 2.0.0 requires OCaml >= 4.03.0

* added a constraint 'ocamlgraph <= 1.8.8'

* better constraints (suggested by David Allsopp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants