mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
IntGraph provided as facility;
BFS properly handles the optional start id
This commit is contained in:
parent
5454f2dd32
commit
c72cc692a7
3 changed files with 16 additions and 2 deletions
|
|
@ -5,3 +5,4 @@
|
||||||
#load "containers.cma";;
|
#load "containers.cma";;
|
||||||
#require "threads";;
|
#require "threads";;
|
||||||
#load "thread_containers.cma";;
|
#load "thread_containers.cma";;
|
||||||
|
open Enum.Infix;;
|
||||||
|
|
|
||||||
15
lazyGraph.ml
15
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 *)
|
let q = Queue.create () in (* queue of nodes to explore *)
|
||||||
Queue.push (v,[]) q;
|
Queue.push (v,[]) q;
|
||||||
let explored = H.create 5 in (* explored nodes *)
|
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 () =
|
let rec next () =
|
||||||
if Queue.is_empty q then raise Enum.EOG else
|
if Queue.is_empty q then raise Enum.EOG else
|
||||||
let v', path = Queue.pop q in
|
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 *)
|
let dfs_full ?(id=0) graph v = Enum.empty (* TODO *)
|
||||||
end
|
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 *)
|
let dfs ?id graph v = Enum.empty (* TODO *)
|
||||||
|
|
||||||
|
|
@ -323,3 +328,9 @@ end
|
||||||
(** {2 Build a graph based on physical equality} *)
|
(** {2 Build a graph based on physical equality} *)
|
||||||
module PhysicalMake(X : sig type t end) : S with type vertex = X.t
|
module PhysicalMake(X : sig type t end) : S with type vertex = X.t
|
||||||
= Make(PhysicalHash(X))
|
= Make(PhysicalHash(X))
|
||||||
|
|
||||||
|
module IntGraph = Make(struct
|
||||||
|
type t = int
|
||||||
|
let equal i j = i = j
|
||||||
|
let hash i = i
|
||||||
|
end)
|
||||||
|
|
|
||||||
|
|
@ -185,3 +185,5 @@ module Make(X : HASHABLE) : S with type vertex = X.t
|
||||||
|
|
||||||
(** {2 Build a graph based on physical equality} *)
|
(** {2 Build a graph based on physical equality} *)
|
||||||
module PhysicalMake(X : sig type t end) : S with type vertex = X.t
|
module PhysicalMake(X : sig type t end) : S with type vertex = X.t
|
||||||
|
|
||||||
|
module IntGraph : S with type vertex = int
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue