From c72cc692a7223eac1241c7e02234f379ef09051b Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 19 Mar 2013 21:45:05 +0100 Subject: [PATCH] IntGraph provided as facility; BFS properly handles the optional start id --- .ocamlinit | 1 + lazyGraph.ml | 15 +++++++++++++-- lazyGraph.mli | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.ocamlinit b/.ocamlinit index afbd4804..114a4bf8 100644 --- a/.ocamlinit +++ b/.ocamlinit @@ -5,3 +5,4 @@ #load "containers.cma";; #require "threads";; #load "thread_containers.cma";; +open Enum.Infix;; diff --git a/lazyGraph.ml b/lazyGraph.ml index 28fedd4c..81e8827c 100644 --- a/lazyGraph.ml +++ b/lazyGraph.ml @@ -235,7 +235,7 @@ module Make(X : HASHABLE) : S with type vertex = X.t = struct let q = Queue.create () in (* queue of nodes to explore *) Queue.push (v,[]) q; let explored = H.create 5 in (* explored nodes *) - let n = ref 0 in (* index of vertices *) + let n = ref id in (* index of vertices *) let rec next () = if Queue.is_empty q then raise Enum.EOG else let v', path = Queue.pop q in @@ -259,7 +259,12 @@ module Make(X : HASHABLE) : S with type vertex = X.t = struct let dfs_full ?(id=0) graph v = Enum.empty (* TODO *) end - let bfs ?id graph v = Enum.empty (* TODO *) + let bfs ?id graph v = + Enum.filterMap + (function + | Full.EnterVertex (v, l, i, _) -> Some (v, l, i) + | _ -> None) + (Full.bfs_full ?id graph v) let dfs ?id graph v = Enum.empty (* TODO *) @@ -323,3 +328,9 @@ end (** {2 Build a graph based on physical equality} *) module PhysicalMake(X : sig type t end) : S with type vertex = X.t = Make(PhysicalHash(X)) + +module IntGraph = Make(struct + type t = int + let equal i j = i = j + let hash i = i +end) diff --git a/lazyGraph.mli b/lazyGraph.mli index 129481b5..e4c4a6c7 100644 --- a/lazyGraph.mli +++ b/lazyGraph.mli @@ -185,3 +185,5 @@ module Make(X : HASHABLE) : S with type vertex = X.t (** {2 Build a graph based on physical equality} *) module PhysicalMake(X : sig type t end) : S with type vertex = X.t + +module IntGraph : S with type vertex = int