split into package core (no pack, 'CC' prefix, stable)

and misc where oneshot ideas go
This commit is contained in:
Simon Cruanes 2014-05-16 20:58:28 +02:00
parent 05d21db298
commit 4bc6c8a008
115 changed files with 278 additions and 247 deletions

View file

@ -1,7 +1,9 @@
S .
S core
S misc
S tests
S examples
B _build
B _build/core
B _build/misc
B _build/tests
B _build/examples
PKG oUnit

View file

@ -51,7 +51,10 @@ push_doc: doc
scp -r containers.docdir/* cedeela.fr:~/simon/root/software/containers/
DONTTEST=myocamlbuild.ml setup.ml
QTESTABLE=$(filter-out $(DONTTEST), $(wildcard *.ml) $(wildcard *.mli))
QTESTABLE=$(filter-out $(DONTTEST), \
$(wildcard core/*.ml) $(wildcard core/*.mli) \
$(wildcard misc/*.ml) $(wildcard misc/*.mli) \
)
qtest-clean:
@rm -rf qtest/
@ -59,7 +62,7 @@ qtest-clean:
qtest: qtest-clean build
@mkdir -p qtest
@qtest extract -o qtest/qtest_all.ml $(QTESTABLE) 2> /dev/null
@ocamlbuild $(OPTIONS) -pkg oUnit,QTest2Lib -I . qtest/qtest_all.native
@ocamlbuild $(OPTIONS) -pkg oUnit,QTest2Lib -I core -I misc qtest/qtest_all.native
@echo
./qtest_all.native

48
_oasis
View file

@ -15,6 +15,11 @@ Description:
abstractions, serialization systems, testing systems and various
experiments.
Flag "misc"
Description: Build the misc library, containing everything from
the rotating kitchen sink to automatic banana distributors
Default: false
Flag "cgi"
Description: Build modules related to FastCGI, depending on CamlGI
Default: false
@ -25,24 +30,33 @@ Flag "lwt"
Flag "thread"
Description: Build modules that depend on threads
Default: true
Default: false
Flag "bench"
Description: Build and run benchmarks
Default: false
Library "containers"
Path: .
Path: core
Modules: CCVector, CCDeque, CCGen, CCSequence, CCFQueue, CCMultiMap,
CCMultiSet, CCBV, CCKMP, CCPrint, CCPersistentHashtbl,
CCLeftistheap
FindlibName: containers
Library "containers_misc"
Path: misc
Pack: true
Modules: Cache, Deque, Gen, FHashtbl, FQueue, FlatHashtbl, Hashset,
Heap, LazyGraph, PersistentGraph, PersistentHashtbl,
PHashtbl, Sequence, SkipList, SplayTree, SplayMap, Univ,
Vector, Bij, PiCalculus, Bencode, Sexp, RAL, MultiSet,
UnionFind, SmallSet, Leftistheap, AbsSet, CSM, MultiMap,
ActionMan, BV, QCheck, BencodeOnDisk, Show, TTree,
Modules: Cache, FHashtbl, FlatHashtbl, Hashset,
Heap, LazyGraph, PersistentGraph,
PHashtbl, SkipList, SplayTree, SplayMap, Univ,
Bij, PiCalculus, Bencode, Sexp, RAL,
UnionFind, SmallSet, AbsSet, CSM,
ActionMan, QCheck, BencodeOnDisk, TTree,
HGraph, Automaton, Conv, Levenshtein, Bidir, Iteratee,
Ty, Tell, BencodeStream, RatTerm, Cause, KMP, CircList
BuildDepends: unix
Ty, Tell, BencodeStream, RatTerm, Cause
BuildDepends: unix,containers
FindlibName: misc
FindlibParent: containers
Library "containers_thread"
Path: threads/
@ -55,7 +69,7 @@ Library "containers_thread"
XMETARequires: containers,threads,lwt
Library "containers_lwt"
Path: lwt/
Path: .
Modules: Behavior, Lwt_automaton
Pack: true
FindlibName: lwt
@ -84,12 +98,12 @@ Document containers
XOCamlbuildLibraries: containers
Executable benchs
Path: tests/
Install: false
CompiledObject: native
Build$: flag(bench)
MainIs: benchs.ml
BuildDepends: containers,bench
Path: tests/
Install: false
CompiledObject: native
Build$: flag(bench)
MainIs: benchs.ml
BuildDepends: containers,containers.misc,bench
Executable bench_conv
Path: tests/

View file

@ -1,4 +0,0 @@
# OASIS_START
# DO NOT EDIT (digest: 5382aaf8b3d2fdeb6717f9805b0dd511)
Containers
# OASIS_STOP

View file

@ -1,4 +0,0 @@
# OASIS_START
# DO NOT EDIT (digest: bc144ef7b5b54947fab9662a822f9179)
Containers_lwt
# OASIS_STOP

View file

View file

@ -120,11 +120,13 @@ let length (d : _ t) =
iter (fun _ -> incr r) d;
!r
type 'a sequence = ('a -> unit) -> unit
let of_seq ?(deque=create ()) seq =
Sequence.iter (fun x -> push_back deque x) seq;
seq (fun x -> push_back deque x);
deque
let to_seq d = Sequence.from_iter (fun k -> iter k d)
let to_seq d k = iter k d
(* naive implem of copy, for now *)
let copy d =

View file

@ -60,8 +60,9 @@ val take_front : 'a t -> 'a
val iter : ('a -> unit) -> 'a t -> unit
(** Iterate on elements *)
val of_seq : ?deque:'a t -> 'a Sequence.t -> 'a t
val to_seq : 'a t -> 'a Sequence.t
type 'a sequence = ('a -> unit) -> unit
val of_seq : ?deque:'a t -> 'a sequence -> 'a t
val to_seq : 'a t -> 'a sequence
val copy : 'a t -> 'a t
(** Fresh copy *)

View file

@ -80,6 +80,11 @@ let fold f acc q =
let iter f q = fold (fun () x -> f x) () q
type 'a sequence = ('a -> unit) -> unit
let to_seq q = fun k -> iter k q
let of_seq seq = Sequence.fold push empty seq
let of_seq seq =
let q = ref empty in
seq (fun x -> q := push !q x);
!q

View file

@ -55,7 +55,7 @@ val fold : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b
val iter : ('a -> unit) -> 'a t -> unit
val to_seq : 'a t -> 'a Sequence.t
val of_seq : 'a Sequence.t -> 'a t
type 'a sequence = ('a -> unit) -> unit
val to_seq : 'a t -> 'a sequence
val of_seq : 'a sequence -> 'a t

View file

@ -27,6 +27,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(** Polymorphic implementation, following Okasaki *)
type 'a sequence = ('a -> unit) -> unit
type 'a t = {
tree : 'a tree;
leq : 'a -> 'a -> bool;
@ -117,7 +119,8 @@ let size heap =
!r
let of_seq heap seq =
Sequence.fold insert heap seq
let h = ref heap in
seq (fun x -> h := insert !h x);
!h
let to_seq heap =
Sequence.from_iter (fun k -> iter heap k)
let to_seq = iter

View file

@ -27,6 +27,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(** Polymorphic implementation, following Okasaki *)
type 'a sequence = ('a -> unit) -> unit
type 'a t
(** Heap containing values of type 'a *)
@ -61,6 +63,6 @@ val iter : 'a t -> ('a -> unit) -> unit
val size : _ t -> int
(** Number of elements (linear) *)
val of_seq : 'a t -> 'a Sequence.t -> 'a t
val of_seq : 'a t -> 'a sequence -> 'a t
val to_seq : 'a t -> 'a Sequence.t
val to_seq : 'a t -> 'a sequence

View file

@ -24,7 +24,9 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*)
(** {6 Multimap} *)
(** {1 Multimap} *)
type 'a sequence = ('a -> unit) -> unit
module type S = sig
type key
@ -86,13 +88,13 @@ module type S = sig
val submap : t -> t -> bool
(** [submap m1 m2] is true iff all bindings of [m1] are also in [m2] *)
val to_seq : t -> (key * value) Sequence.t
val to_seq : t -> (key * value) sequence
val of_seq : ?init:t -> (key * value) Sequence.t -> t
val of_seq : ?init:t -> (key * value) sequence -> t
val keys : t -> key Sequence.t
val keys : t -> key sequence
val values : t -> value Sequence.t
val values : t -> value sequence
(** Some values may occur several times *)
end
@ -212,15 +214,14 @@ module Make(K : OrderedType)(V : OrderedType) = struct
false)
m1
let to_seq m =
Sequence.from_iter (fun k -> iter m (fun x y -> k (x,y)))
let to_seq m k = iter m (fun x y -> k (x,y))
let of_seq ?(init=empty) seq =
Sequence.fold (fun m (k,v) -> add m k v) init seq
let m = ref init in
seq (fun (k,v) -> m := add !m k v);
!m
let keys m =
Sequence.from_iter (fun k -> M.iter (fun x _ -> k x) m)
let keys m k = M.iter (fun x _ -> k x) m
let values m =
Sequence.from_iter (fun k -> iter m (fun _ v -> k v))
let values m k = iter m (fun _ v -> k v)
end

View file

@ -24,7 +24,9 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*)
(** {6 Multimap} *)
(** {1 Multimap} *)
type 'a sequence = ('a -> unit) -> unit
module type S = sig
type key
@ -86,13 +88,13 @@ module type S = sig
val submap : t -> t -> bool
(** [submap m1 m2] is true iff all bindings of [m1] are also in [m2] *)
val to_seq : t -> (key * value) Sequence.t
val to_seq : t -> (key * value) sequence
val of_seq : ?init:t -> (key * value) Sequence.t -> t
val of_seq : ?init:t -> (key * value) sequence -> t
val keys : t -> key Sequence.t
val keys : t -> key sequence
val values : t -> value Sequence.t
val values : t -> value sequence
(** Some values may occur several times *)
end

View file

@ -25,6 +25,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(** {1 Persistent hash-table on top of OCaml's hashtables} *)
type 'a sequence = ('a -> unit) -> unit
module type HashedType = sig
type t
val equal : t -> t -> bool
@ -75,12 +77,12 @@ module type S = sig
val fold : ('b -> key -> 'a -> 'b) -> 'b -> 'a t -> 'b
(** Fold over bindings *)
val of_seq : ?init:'a t -> (key * 'a) Sequence.t -> 'a t
val of_seq : ?init:'a t -> (key * 'a) sequence -> 'a t
(** Add (replace) bindings from the sequence to the table *)
val of_list : ?init:'a t -> (key * 'a) list -> 'a t
val to_seq : 'a t -> (key * 'a) Sequence.t
val to_seq : 'a t -> (key * 'a) sequence
(** Sequence of the bindings of the table *)
val to_list : 'a t -> (key * 'a) list
@ -229,11 +231,11 @@ module Make(H : HashedType) : S with type key = H.t = struct
let tbl = match init with
| None -> Table.create 5
| Some t -> Table.copy (reroot t) in
Sequence.iter (fun (k,v) -> Table.replace tbl k v) seq;
ref (Table tbl)
seq (fun (k,v) -> Table.replace tbl k v);
ref (Table tbl)
let of_list ?init l =
of_seq ?init (Sequence.of_list l)
of_seq ?init (fun k -> List.iter k l)
let to_list t =
let tbl = reroot t in

View file

@ -25,6 +25,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(** {1 Persistent hash-table on top of OCaml's hashtables} *)
type 'a sequence = ('a -> unit) -> unit
module type HashedType = sig
type t
val equal : t -> t -> bool
@ -75,12 +77,12 @@ module type S = sig
val fold : ('b -> key -> 'a -> 'b) -> 'b -> 'a t -> 'b
(** Fold over bindings *)
val of_seq : ?init:'a t -> (key * 'a) Sequence.t -> 'a t
val of_seq : ?init:'a t -> (key * 'a) sequence -> 'a t
(** Add (replace) bindings from the sequence to the table *)
val of_list : ?init:'a t -> (key * 'a) list -> 'a t
val to_seq : 'a t -> (key * 'a) Sequence.t
val to_seq : 'a t -> (key * 'a) sequence
(** Sequence of the bindings of the table *)
val to_list : 'a t -> (key * 'a) list

View file

@ -77,7 +77,7 @@ let append_array a b =
a.size <- a.size + Array.length b
let append_seq a seq =
Sequence.iter (fun x -> push a x) seq
seq (fun x -> push a x)
let pop v =
(if v.size = 0 then failwith "Vector.pop on empty vector");
@ -208,22 +208,22 @@ let length v = v.size
let unsafe_get_array v = v.vec
type 'a sequence = ('a -> unit) -> unit
let of_seq ?(init=create 10) seq =
append_seq init seq;
init
let to_seq t =
Sequence.from_iter (fun k -> iter t k)
let to_seq = iter
let slice v start len =
assert (start >= 0 && len >= 0);
Sequence.from_iter
(fun k ->
assert (start+len < v.size);
for i = start to start+len do
let x = Array.unsafe_get v.vec i in
k x
done)
fun k ->
assert (start+len < v.size);
for i = start to start+len do
let x = Array.unsafe_get v.vec i in
k x
done
let from_array a =
let c = Array.length a in

View file

@ -28,6 +28,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
type 'a t
(** the type of a vector of 'a *)
type 'a sequence = ('a -> unit) -> unit
val create : int -> 'a t
(** create a vector of given initial capacity *)
@ -46,7 +48,7 @@ val append : 'a t -> 'a t -> unit
val append_array : 'a t -> 'a array -> unit
(** same as append, with an array *)
val append_seq : 'a t -> 'a Sequence.t -> unit
val append_seq : 'a t -> 'a sequence -> unit
(** Append content of sequence *)
val pop : 'a t -> 'a
@ -111,11 +113,11 @@ val unsafe_get_array : 'a t -> 'a array
[unsafe_get_array v] is longer than [size v], but elements at higher
index than [size v] are undefined (do not access!). *)
val of_seq : ?init:'a t -> 'a Sequence.t -> 'a t
val of_seq : ?init:'a t -> 'a sequence -> 'a t
val to_seq : 'a t -> 'a Sequence.t
val to_seq : 'a t -> 'a sequence
val slice : 'a t -> int -> int -> 'a Sequence.t
val slice : 'a t -> int -> int -> 'a sequence
(** [slice v start len] is the sequence of elements from [v.(start)]
to [v.(start+len)] included. *)

View file

@ -1 +0,0 @@
Behavior

View file

@ -1 +0,0 @@
Behavior

View file

@ -210,7 +210,7 @@ module List = struct
let build state x = Some (x::state, x::state)
end
module Gen = struct
module CCGen = struct
type 'a gen = unit -> 'a option
let map a state gen =
@ -227,7 +227,7 @@ module Gen = struct
end
end
module Sequence = struct
module CCSequence = struct
type 'a sequence = ('a -> unit) -> unit
exception ExitSeq

View file

@ -140,13 +140,13 @@ module List : sig
(** build a list from its inputs *)
end
module Gen : sig
module CCGen : sig
type 'a gen = unit -> 'a option
val map : ('a, 's, 'b) t -> 's -> 'a gen -> 'b gen
end
module Sequence : sig
module CCSequence : sig
type 'a sequence = ('a -> unit) -> unit
val map : ('a, 's, 'b) t -> 's -> 'a sequence -> 'b sequence

View file

View file

@ -103,7 +103,7 @@ let product s1 s2 =
{ mem; iter; cardinal; }
let to_seq set =
Sequence.from_iter (fun k -> set.iter k)
CCSequence.from_iter (fun k -> set.iter k)
let to_list set =
let l = ref [] in
@ -154,7 +154,7 @@ let builder_cmp (type k) ?(cmp=Pervasives.compare) () =
mk_builder ~add ~get
let of_seq_builder ~builder seq =
Sequence.iter builder.add seq;
CCSequence.iter builder.add seq;
builder.get ()
let of_seq_hash ?eq ?hash seq =
@ -165,7 +165,7 @@ let of_seq_cmp ?cmp seq =
let b = builder_cmp ?cmp () in
of_seq_builder b seq
let of_list l = of_seq_hash (Sequence.of_list l)
let of_list l = of_seq_hash (CCSequence.of_list l)
let map ?(builder=builder_hash ()) set ~f =
set.iter
@ -202,7 +202,7 @@ module MakeHash(X : Hashtbl.HashedType) = struct
let of_seq ?(size=5) seq =
let h = Hashtbl.create size in
Sequence.iter (fun x -> Hashtbl.add h x ()) seq;
CCSequence.iter (fun x -> Hashtbl.add h x ()) seq;
let mem x = Hashtbl.mem h x in
let iter k = Hashtbl.iter (fun x () -> k x) h in
let cardinal () = Hashtbl.length h in
@ -220,7 +220,7 @@ module MakeSet(S : Set.S) = struct
mk_generic ~cardinal ~mem ~iter
let of_seq ?(init=S.empty) seq =
let set = Sequence.fold (fun s x -> S.add x s) init seq in
let set = CCSequence.fold (fun s x -> S.add x s) init seq in
of_set set
let to_set set =

View file

@ -48,7 +48,7 @@ val singleton : ?eq:('a -> 'a -> bool) -> 'a -> 'a t
val mk_generic : ?cardinal:(unit -> int) ->
mem:('a -> bool) ->
iter:(('a -> unit) -> unit) -> 'a t
(** Generic constructor. Takes a membership function and an iteration
(** CCGeneric constructor. Takes a membership function and an iteration
function, and possibly a cardinal function (supposed to return
the number of elements) *)
@ -67,7 +67,7 @@ val intersection : 'a t -> 'a t -> 'a t
val product : 'a t -> 'b t -> ('a * 'b) t
(** Cartesian product *)
val to_seq : 'a t -> 'a Sequence.t
val to_seq : 'a t -> 'a CCSequence.t
val to_list : 'a t -> 'a list
@ -84,7 +84,7 @@ val to_list : 'a t -> 'a list
type 'a builder
val mk_builder : add:('a -> unit) -> get:(unit -> 'a t) -> 'a builder
(** Generic set builder *)
(** CCGeneric set builder *)
val builder_hash : ?size:int ->
?eq:('a -> 'a -> bool) ->
@ -93,13 +93,13 @@ val builder_hash : ?size:int ->
val builder_cmp : ?cmp:('a -> 'a -> int) -> unit -> 'a builder
val of_seq_builder : builder:'a builder -> 'a Sequence.t -> 'a t
val of_seq_builder : builder:'a builder -> 'a CCSequence.t -> 'a t
(** Uses the given builder to construct a set from a sequence of elements *)
val of_seq_hash : ?eq:('a -> 'a -> bool) -> ?hash:('a -> int) -> 'a Sequence.t -> 'a t
val of_seq_hash : ?eq:('a -> 'a -> bool) -> ?hash:('a -> int) -> 'a CCSequence.t -> 'a t
(** Construction of a set from a sequence of hashable elements *)
val of_seq_cmp : ?cmp:('a -> 'a -> int) -> 'a Sequence.t -> 'a t
val of_seq_cmp : ?cmp:('a -> 'a -> int) -> 'a CCSequence.t -> 'a t
(** Construction of a set from a sequence of comparable elements *)
val of_list : 'a list -> 'a t
@ -133,7 +133,7 @@ module MakeHash(X : Hashtbl.HashedType) : sig
type elt = X.t
(** Elements of the set are hashable *)
val of_seq : ?size:int -> elt Sequence.t -> elt t
val of_seq : ?size:int -> elt CCSequence.t -> elt t
(** Build a set from a sequence *)
end
@ -141,7 +141,7 @@ end
module MakeSet(S : Set.S) : sig
type elt = S.elt
val of_seq : ?init:S.t -> elt Sequence.t -> elt t
val of_seq : ?init:S.t -> elt CCSequence.t -> elt t
(** Build a set from a sequence *)
val of_set : S.t -> elt t

View file

@ -39,7 +39,7 @@ module Action : sig
(** Return a pure value *)
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
(** Sequence of arguments *)
(** CCSequence of arguments *)
val (>>) : 'a t -> (unit -> 'b t) -> 'b t
(** Same as {! (>>=)}, but ignores the result of left side *)

View file

View file

@ -158,10 +158,10 @@ module Make(T : CurryfiedTerm) = struct
end
(* Persistent Hashtable on curryfied terms *)
module THashtbl = PersistentHashtbl.Make(HashedCT)
module THashtbl = CCPersistentHashtbl.Make(HashedCT)
(* Persistent Hashtable on pairs of curryfied terms *)
module T2Hashtbl = PersistentHashtbl.Make(struct
module T2Hashtbl = CCPersistentHashtbl.Make(struct
type t = CT.t * CT.t
let equal (t1,t1') (t2,t2') = t1.CT.tag = t2.CT.tag && t1'.CT.tag = t2'.CT.tag
let hash (t,t') = t.CT.tag * 65599 + t'.CT.tag

View file

View file

@ -124,7 +124,7 @@ let gen l =
(*$Q
(Q.list Q.small_int) (fun l -> \
l = [] || let q = of_list l in \
gen q |> Gen.take (List.length l) |> Gen.to_list = l)
gen q |> CCGen.take (List.length l) |> CCGen.to_list = l)
*)
let seq l k =

View file

@ -76,7 +76,7 @@ type 'a gen = unit -> 'a option
type 'a sequence = ('a -> unit) -> unit
val gen : 'a t -> 'a gen
(** Generator on elements of the list *)
(** CCGenerator on elements of the list *)
val seq : 'a t -> 'a sequence
(** Sequence of elements of the list *)
(** CCSequence of elements of the list *)

View file

@ -64,9 +64,9 @@ module type S = sig
val size : 'a t -> int
(** Number of bindings *)
val to_seq : 'a t -> (key * 'a) Sequence.t
val to_seq : 'a t -> (key * 'a) CCSequence.t
val of_seq : ?size:int -> (key * 'a) Sequence.t -> 'a t
val of_seq : ?size:int -> (key * 'a) CCSequence.t -> 'a t
end
(** {2 Persistent array} *)
@ -337,10 +337,10 @@ module Tree(X : HASH) = struct
fold (fun n _ _ -> n + 1) 0 t
let to_seq t =
Sequence.from_iter (fun k -> iter (fun key value -> k (key, value)) t)
CCSequence.from_iter (fun k -> iter (fun key value -> k (key, value)) t)
let of_seq ?(size=32) seq =
Sequence.fold
CCSequence.fold
(fun t (k,v) -> replace t k v)
(empty size) seq
end
@ -493,9 +493,9 @@ module Flat(X : HASH) = struct
acc t.buckets
let to_seq t =
Sequence.from_iter
CCSequence.from_iter
(fun k -> iter (fun key value -> k (key, value)) t)
let of_seq ?(size=32) seq =
Sequence.fold (fun t (k,v) -> replace t k v) (empty size) seq
CCSequence.fold (fun t (k,v) -> replace t k v) (empty size) seq
end

View file

@ -64,9 +64,9 @@ module type S = sig
val size : 'a t -> int
(** Number of bindings *)
val to_seq : 'a t -> (key * 'a) Sequence.t
val to_seq : 'a t -> (key * 'a) CCSequence.t
val of_seq : ?size:int -> (key * 'a) Sequence.t -> 'a t
val of_seq : ?size:int -> (key * 'a) CCSequence.t -> 'a t
end
(** {2 Persistent array} *)

View file

@ -61,9 +61,9 @@ module type S =
val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
(** Fold on bindings *)
val to_seq : 'a t -> (key * 'a) Sequence.t
val to_seq : 'a t -> (key * 'a) CCSequence.t
val of_seq : 'a t -> (key * 'a) Sequence.t -> unit
val of_seq : 'a t -> (key * 'a) CCSequence.t -> unit
val stats : 'a t -> int * int * int * int * int * int
(** Cf Weak.S *)
@ -219,11 +219,11 @@ module Make(H : Hashtbl.HashedType) =
in fold acc 0
let to_seq t =
Sequence.from_iter
CCSequence.from_iter
(fun k -> iter (fun key value -> k (key, value)) t)
let of_seq t seq =
Sequence.iter (fun (k,v) -> replace t k v) seq
CCSequence.iter (fun (k,v) -> replace t k v) seq
(** Statistics on the table *)
let stats t = (Array.length t.buckets, t.size, t.size, 0, 0, 1)

View file

@ -61,9 +61,9 @@ module type S =
val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
(** Fold on bindings *)
val to_seq : 'a t -> (key * 'a) Sequence.t
val to_seq : 'a t -> (key * 'a) CCSequence.t
val of_seq : 'a t -> (key * 'a) Sequence.t -> unit
val of_seq : 'a t -> (key * 'a) CCSequence.t -> unit
val stats : 'a t -> int * int * int * int * int * int
(** Cf Weak.S *)

View file

@ -26,7 +26,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(** {2 Hypergraph Representation}
Generalized Hypergraphs. Objects are either constants, or hyperedges that
CCGeneralized Hypergraphs. Objects are either constants, or hyperedges that
connect [n] other objets together (a [n]-tuple). Each hyperedge can contain
additional data.
*)

View file

@ -26,7 +26,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(** {2 Hypergraph Representation}
Generalized Hypergraphs. Objects are either constants, or hyperedges that
CCGeneralized Hypergraphs. Objects are either constants, or hyperedges that
connect [n] other objets together (a [n]-tuple).
Hashconsing is used to ensure that structural equality implies physical

View file

@ -50,10 +50,10 @@ let fold f acc set = PHashtbl.fold (fun acc x () -> f acc x) acc set
let filter p set = PHashtbl.filter (fun x () -> p x) set
let to_seq set =
Sequence.from_iter (fun k -> iter k set)
CCSequence.from_iter (fun k -> iter k set)
let of_seq set seq =
Sequence.iter (fun x -> add set x) seq
CCSequence.iter (fun x -> add set x) seq
let union ?into (s1 : 'a t) (s2 : 'a t) =
let into = match into with
@ -67,5 +67,5 @@ let inter ?into (s1 : 'a t) (s2 : 'a t) =
| Some s -> s
| None -> empty ~eq:s1.PHashtbl.eq ~hash:s1.PHashtbl.hash (cardinal s1) in
(* add to [into] elements of [s1] that also belong to [s2] *)
of_seq into (Sequence.filter (fun x -> mem s2 x) (to_seq s1));
of_seq into (CCSequence.filter (fun x -> mem s2 x) (to_seq s1));
into

View file

@ -51,9 +51,9 @@ val fold : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b
val filter : ('a -> bool) -> 'a t -> unit
(** destructive filter (remove elements that do not satisfy the predicate) *)
val to_seq : 'a t -> 'a Sequence.t
val to_seq : 'a t -> 'a CCSequence.t
val of_seq : 'a t -> 'a Sequence.t -> unit
val of_seq : 'a t -> 'a CCSequence.t -> unit
val union : ?into:'a t -> 'a t -> 'a t -> 'a t
(** Set union. The result is stored in [into] *)

View file

@ -51,6 +51,6 @@ val iter : 'a t -> ('a -> unit) -> unit
val size : _ t -> int
val to_seq : 'a t -> 'a Sequence.t
val to_seq : 'a t -> 'a CCSequence.t
val of_seq : 'a t -> 'a Sequence.t -> unit
val of_seq : 'a t -> 'a CCSequence.t -> unit

View file

@ -41,7 +41,7 @@ type ('id, 'v, 'e) t = {
other vertices, or to Empty if the identifier is not part of the graph. *)
and ('id, 'v, 'e) node =
| Empty
| Node of 'id * 'v * ('e * 'id) Sequence.t
| Node of 'id * 'v * ('e * 'id) CCSequence.t
(** A single node of the graph, with outgoing edges *)
and ('id, 'e) path = ('id * 'e * 'id) list
(** A reverse path (from the last element of the path to the first). *)
@ -56,7 +56,7 @@ let empty =
let singleton ?(eq=(=)) ?(hash=Hashtbl.hash) v label =
let force v' =
if eq v v' then Node (v, label, Sequence.empty) else Empty in
if eq v v' then Node (v, label, CCSequence.empty) else Empty in
{ force; eq; hash; }
let make ?(eq=(=)) ?(hash=Hashtbl.hash) force =
@ -66,7 +66,7 @@ let from_fun ?(eq=(=)) ?(hash=Hashtbl.hash) f =
let force v =
match f v with
| None -> Empty
| Some (l, edges) -> Node (v, l, Sequence.of_list edges) in
| Some (l, edges) -> Node (v, l, CCSequence.of_list edges) in
{ eq; hash; force; }
(** {2 Polymorphic map} *)
@ -110,7 +110,7 @@ module Mutable = struct
let map = mk_map ~eq ~hash in
let force v =
try let node = map.map_get v in
Node (v, node.mut_v, Sequence.of_list node.mut_outgoing)
Node (v, node.mut_v, CCSequence.of_list node.mut_outgoing)
with Not_found -> Empty in
let graph = { eq; hash; force; } in
map, graph
@ -129,10 +129,10 @@ end
let from_enum ?(eq=(=)) ?(hash=Hashtbl.hash) ~vertices ~edges =
let g, lazy_g = Mutable.create ~eq ~hash () in
Sequence.iter
CCSequence.iter
(fun (v,label_v) -> Mutable.add_vertex g v label_v;)
vertices;
Sequence.iter
CCSequence.iter
(fun (v1, e, v2) -> Mutable.add_edge g v1 e v2)
edges;
lazy_g
@ -174,11 +174,11 @@ module Full = struct
| [] -> false
let bfs_full graph vertices =
Sequence.from_iter (fun k ->
CCSequence.from_iter (fun k ->
let explored = mk_map ~eq:graph.eq ~hash:graph.hash in
let id = ref 0 in
let q = Queue.create () in (* queue of nodes to explore *)
Sequence.iter (fun v -> Queue.push (FullEnter (v,[])) q) vertices;
CCSequence.iter (fun v -> Queue.push (FullEnter (v,[])) q) vertices;
while not (Queue.is_empty q) do
match Queue.pop q with
| FullEnter (v', path) ->
@ -188,7 +188,7 @@ module Full = struct
| Node (_, label, edges) ->
explored.map_add v' ();
(* explore neighbors *)
Sequence.iter
CCSequence.iter
(fun (e,v'') ->
let path' = (v'',e,v') :: path in
Queue.push (FullFollowEdge path') q)
@ -219,11 +219,11 @@ module Full = struct
checking whether the node is in the path (should be faster) *)
let dfs_full graph vertices =
Sequence.from_iter (fun k ->
CCSequence.from_iter (fun k ->
let explored = mk_map ~eq:graph.eq ~hash:graph.hash in
let id = ref 0 in
let s = Stack.create () in (* stack of nodes to explore *)
Sequence.iter (fun v -> Stack.push (FullEnter (v,[])) s) vertices;
CCSequence.iter (fun v -> Stack.push (FullEnter (v,[])) s) vertices;
while not (Stack.is_empty s) do
match Stack.pop s with
| FullExit v' -> k (ExitVertex v')
@ -237,7 +237,7 @@ module Full = struct
(* prepare to exit later *)
Stack.push (FullExit v') s;
(* explore neighbors *)
Sequence.iter
CCSequence.iter
(fun (e,v'') ->
Stack.push (FullFollowEdge ((v'', e, v') :: path)) s)
edges;
@ -262,18 +262,18 @@ module Full = struct
end
let bfs graph v =
Sequence.fmap
CCSequence.fmap
(function
| Full.EnterVertex (v, l, i, _) -> Some (v, l, i)
| _ -> None)
(Full.bfs_full graph (Sequence.singleton v))
(Full.bfs_full graph (CCSequence.singleton v))
let dfs graph v =
Sequence.fmap
CCSequence.fmap
(function
| Full.EnterVertex (v, l, i, _) -> Some (v, l, i)
| _ -> None)
(Full.dfs_full graph (Sequence.singleton v))
(Full.dfs_full graph (CCSequence.singleton v))
(** {3 Mutable heap} *)
module Heap = struct
@ -342,7 +342,7 @@ let a_star graph
?(distance=(fun v1 e v2 -> 1.))
~goal
start =
Sequence.from_iter (fun k ->
CCSequence.from_iter (fun k ->
(* map node -> 'came_from' cell *)
let nodes = mk_map ~eq:graph.eq ~hash:graph.hash in
(* priority queue for nodes to explore *)
@ -376,7 +376,7 @@ let a_star graph
| Empty -> ()
| Node (_, label, edges) ->
(* explore neighbors *)
Sequence.iter
CCSequence.iter
(fun (e,v'') ->
let cost = dist +. distance v' e v'' +. heuristic v'' in
let cell' =
@ -413,7 +413,7 @@ let dijkstra graph ?on_explore ?(ignore=fun v -> false)
a_star graph ?on_explore ~ignore ~distance ~heuristic:(fun _ -> 0.)
~goal:(fun v -> graph.eq v v2) v1
in
match Sequence.to_list (Sequence.take 1 paths) with
match CCSequence.to_list (CCSequence.take 1 paths) with
| [] -> raise Not_found
| [x] -> x
| _ -> assert false
@ -421,14 +421,14 @@ let dijkstra graph ?on_explore ?(ignore=fun v -> false)
(** Is the subgraph explorable from the given vertex, a Directed
Acyclic Graph? *)
let is_dag graph v =
Sequence.for_all
CCSequence.for_all
(function
| Full.MeetEdge (_, _, _, Full.EdgeBackward) -> false
| _ -> true)
(Full.dfs_full graph (Sequence.singleton v))
(Full.dfs_full graph (CCSequence.singleton v))
let is_dag_full graph vs =
Sequence.for_all
CCSequence.for_all
(function
| Full.MeetEdge (_, _, _, Full.EdgeBackward) -> false
| _ -> true)
@ -443,8 +443,8 @@ let find_cycle graph v =
let cycle = ref [] in
try
let path_stack = Stack.create () in
let seq = Full.dfs_full graph (Sequence.singleton v) in
Sequence.iter
let seq = Full.dfs_full graph (CCSequence.singleton v) in
CCSequence.iter
(function
| Full.EnterVertex (_, _, _, path) ->
Stack.push path path_stack
@ -478,7 +478,7 @@ let union ?(combine=fun x y -> x) g1 g2 =
| ((Node _) as n), Empty -> n
| Empty, ((Node _) as n) -> n
| Node (_, l1, e1), Node (_, l2, e2) ->
Node (v, combine l1 l2, Sequence.append e1 e2)
Node (v, combine l1 l2, CCSequence.append e1 e2)
in { eq=g1.eq; hash=g1.hash; force; }
let map ~vertices ~edges g =
@ -486,7 +486,7 @@ let map ~vertices ~edges g =
match g.force v with
| Empty -> Empty
| Node (_, l, edges_enum) ->
let edges_enum' = Sequence.map (fun (e,v') -> (edges e), v') edges_enum in
let edges_enum' = CCSequence.map (fun (e,v') -> (edges e), v') edges_enum in
Node (v, vertices l, edges_enum')
in { eq=g.eq; hash=g.hash; force; }
@ -497,9 +497,9 @@ let flatMap f g =
match g.force v with
| Empty -> Empty
| Node (_, l, edges_enum) ->
let edges_enum' = Sequence.flatMap
let edges_enum' = CCSequence.flatMap
(fun (e, v') ->
Sequence.map (fun v'' -> e, v'') (f v'))
CCSequence.map (fun v'' -> e, v'') (f v'))
edges_enum in
Node (v, l, edges_enum')
in { eq=g.eq; hash=g.hash; force; }
@ -510,7 +510,7 @@ let filter ?(vertices=(fun v l -> true)) ?(edges=fun v1 e v2 -> true) g =
| Empty -> Empty
| Node (_, l, edges_enum) when vertices v l ->
(* filter out edges *)
let edges_enum' = Sequence.filter (fun (e,v') -> edges v e v') edges_enum in
let edges_enum' = CCSequence.filter (fun (e,v') -> edges v e v') edges_enum in
Node (v, l, edges_enum')
| Node _ -> Empty (* filter out this vertex *)
in { eq=g.eq; hash=g.hash; force; }
@ -522,8 +522,8 @@ let product g1 g2 =
| _, Empty -> Empty
| Node (_, l1, edges1), Node (_, l2, edges2) ->
(* product of edges *)
let edges = Sequence.product edges1 edges2 in
let edges = Sequence.map (fun ((e1,v1'),(e2,v2')) -> ((e1,e2),(v1',v2'))) edges in
let edges = CCSequence.product edges1 edges2 in
let edges = CCSequence.map (fun ((e1,v1'),(e2,v2')) -> ((e1,e2),(v1',v2'))) edges in
Node ((v1,v2), (l1,l2), edges)
and eq (v1,v2) (v1',v2') =
g1.eq v1 v1' && g2.eq v2 v2'
@ -574,17 +574,17 @@ module Dot = struct
(* print preamble *)
Format.fprintf formatter "@[<v2>digraph %s {@;" name;
(* traverse *)
Sequence.iter
CCSequence.iter
(function
| Full.EnterVertex (v, attrs, _, _) ->
Format.fprintf formatter " @[<h>%a [%a];@]@." pp_vertex v
(Sequence.pp_seq ~sep:"," print_attribute) (Sequence.of_list attrs)
(CCSequence.pp_seq ~sep:"," print_attribute) (CCSequence.of_list attrs)
| Full.ExitVertex _ -> ()
| Full.MeetEdge (v2, attrs, v1, _) ->
Format.fprintf formatter " @[<h>%a -> %a [%a];@]@."
pp_vertex v1 pp_vertex v2
(Sequence.pp_seq ~sep:"," print_attribute)
(Sequence.of_list attrs))
(CCSequence.pp_seq ~sep:"," print_attribute)
(CCSequence.of_list attrs))
events;
(* close *)
Format.fprintf formatter "}@]@;@?";
@ -608,17 +608,17 @@ let divisors_graph =
if i > 2
then
let l = divisors [] 2 i in
let edges = Sequence.map (fun i -> (), i) (Sequence.of_list l) in
let edges = CCSequence.map (fun i -> (), i) (CCSequence.of_list l) in
Node (i, i, edges)
else
Node (i, i, Sequence.empty)
Node (i, i, CCSequence.empty)
in make force
let collatz_graph =
let force i =
if i mod 2 = 0
then Node (i, i, Sequence.singleton ((), i / 2))
else Node (i, i, Sequence.singleton ((), i * 3 + 1))
then Node (i, i, CCSequence.singleton ((), i / 2))
else Node (i, i, CCSequence.singleton ((), i * 3 + 1))
in make force
let collatz_graph_bis =
@ -628,10 +628,10 @@ let collatz_graph_bis =
; false, i * 2 ] @
if i mod 3 = 1 then [false, (i-1)/3] else []
in
Node (i, i, Sequence.of_list l)
Node (i, i, CCSequence.of_list l)
in make force
let heap_graph =
let force i =
Node (i, i, Sequence.of_list [(), 2*i; (), 2*i+1])
Node (i, i, CCSequence.of_list [(), 2*i; (), 2*i+1])
in make force

View file

@ -44,7 +44,7 @@ type ('id, 'v, 'e) t = {
other vertices, or to Empty if the identifier is not part of the graph. *)
and ('id, 'v, 'e) node =
| Empty
| Node of 'id * 'v * ('e * 'id) Sequence.t
| Node of 'id * 'v * ('e * 'id) CCSequence.t
(** A single node of the graph, with outgoing edges *)
and ('id, 'e) path = ('id * 'e * 'id) list
(** A reverse path (from the last element of the path to the first). *)
@ -70,8 +70,8 @@ val make : ?eq:('id -> 'id -> bool) -> ?hash:('id -> int) ->
(** Build a graph from the [force] function *)
val from_enum : ?eq:('id -> 'id -> bool) -> ?hash:('id -> int) ->
vertices:('id * 'v) Sequence.t ->
edges:('id * 'e * 'id) Sequence.t ->
vertices:('id * 'v) CCSequence.t ->
edges:('id * 'e * 'id) CCSequence.t ->
('id, 'v, 'e) t
(** Concrete (eager) representation of a Graph *)
@ -117,21 +117,21 @@ module Full : sig
| EdgeBackward (* toward the current trail *)
| EdgeTransverse (* toward a totally explored part of the graph *)
val bfs_full : ('id, 'v, 'e) t -> 'id Sequence.t ->
('id, 'v, 'e) traverse_event Sequence.t
val bfs_full : ('id, 'v, 'e) t -> 'id CCSequence.t ->
('id, 'v, 'e) traverse_event CCSequence.t
(** Lazy traversal in breadth first from a finite set of vertices *)
val dfs_full : ('id, 'v, 'e) t -> 'id Sequence.t ->
('id, 'v, 'e) traverse_event Sequence.t
val dfs_full : ('id, 'v, 'e) t -> 'id CCSequence.t ->
('id, 'v, 'e) traverse_event CCSequence.t
(** Lazy traversal in depth first from a finite set of vertices *)
end
(** The traversal functions assign a unique ID to every traversed node *)
val bfs : ('id, 'v, 'e) t -> 'id -> ('id * 'v * int) Sequence.t
val bfs : ('id, 'v, 'e) t -> 'id -> ('id * 'v * int) CCSequence.t
(** Lazy traversal in breadth first *)
val dfs : ('id, 'v, 'e) t -> 'id -> ('id * 'v * int) Sequence.t
val dfs : ('id, 'v, 'e) t -> 'id -> ('id * 'v * int) CCSequence.t
(** Lazy traversal in depth first *)
module Heap : sig
@ -149,7 +149,7 @@ val a_star : ('id, 'v, 'e) t ->
?distance:('id -> 'e -> 'id -> float) ->
goal:('id -> bool) ->
'id ->
(float * ('id, 'e) path) Sequence.t
(float * ('id, 'e) path) CCSequence.t
(** Shortest path from the first node to nodes that satisfy [goal], according
to the given (positive!) distance function. The distance is also returned.
[ignore] allows one to ignore some vertices during exploration.
@ -174,7 +174,7 @@ val is_dag : ('id, _, _) t -> 'id -> bool
(** Is the subgraph explorable from the given vertex, a Directed
Acyclic Graph? *)
val is_dag_full : ('id, _, _) t -> 'id Sequence.t -> bool
val is_dag_full : ('id, _, _) t -> 'id CCSequence.t -> bool
(** Is the Graph reachable from the given vertices, a DAG? See {! is_dag} *)
val find_cycle : ('id, _, 'e) t -> 'id -> ('id, 'e) path
@ -196,7 +196,7 @@ val map : vertices:('v -> 'v2) -> edges:('e -> 'e2) ->
('id, 'v, 'e) t -> ('id, 'v2, 'e2) t
(** Map vertice and edge labels *)
val flatMap : ('id -> 'id Sequence.t) ->
val flatMap : ('id -> 'id CCSequence.t) ->
('id, 'v, 'e) t ->
('id, 'v, 'e) t
(** Replace each vertex by some vertices. By mapping [v'] to [f v'=v1,...,vn],
@ -231,12 +231,12 @@ module Dot : sig
val pp_enum : ?eq:('id -> 'id -> bool) -> ?hash:('id -> int) ->
name:string -> Format.formatter ->
('id,attribute list,attribute list) Full.traverse_event Sequence.t ->
('id,attribute list,attribute list) Full.traverse_event CCSequence.t ->
unit
val pp : name:string -> ('id, attribute list, attribute list) t ->
Format.formatter ->
'id Sequence.t -> unit
'id CCSequence.t -> unit
(** Pretty print the given graph (starting from the given set of vertices)
to the channel in DOT format *)
end

View file

@ -217,11 +217,11 @@ let filter pred t =
(** Add the given pairs to the hashtable *)
let of_seq t seq =
Sequence.iter (fun (k,v) -> add t k v) seq
CCSequence.iter (fun (k,v) -> add t k v) seq
(** Sequence of pairs *)
(** CCSequence of pairs *)
let to_seq t =
Sequence.from_iter
CCSequence.from_iter
(fun kont -> iter (fun k v -> kont (k,v)) t)
(** Statistics on the table *)

View file

@ -90,11 +90,11 @@ val filter : ('a -> 'b -> bool) -> ('a, 'b) t -> unit
val fold : ('c -> 'a -> 'b -> 'c) -> 'c -> ('a, 'b) t -> 'c
(** Fold on bindings *)
val of_seq : ('a, 'b) t -> ('a * 'b) Sequence.t -> unit
val of_seq : ('a, 'b) t -> ('a * 'b) CCSequence.t -> unit
(** Add the given pairs to the hashtable *)
val to_seq : ('a, 'b) t -> ('a * 'b) Sequence.t
(** Sequence of pairs *)
val to_seq : ('a, 'b) t -> ('a * 'b) CCSequence.t
(** CCSequence of pairs *)
val stats : (_, _) t -> int * int * int * int * int * int
(** Cf Weak.S *)

View file

@ -83,25 +83,25 @@ let add t v1 e v2 =
()
let add_seq t seq =
Sequence.iter (fun (v1,e,v2) -> add t v1 e v2) seq
CCSequence.iter (fun (v1,e,v2) -> add t v1 e v2) seq
let next t v =
Sequence.of_list (PHashtbl.find t v).n_next
CCSequence.of_list (PHashtbl.find t v).n_next
let prev t v =
Sequence.of_list (PHashtbl.find t v).n_prev
CCSequence.of_list (PHashtbl.find t v).n_prev
let between t v1 v2 =
let edges = Sequence.of_list (PHashtbl.find t v1).n_next in
let edges = Sequence.filter (fun (e, v2') -> (PHashtbl.get_eq t) v2 v2') edges in
Sequence.map fst edges
let edges = CCSequence.of_list (PHashtbl.find t v1).n_next in
let edges = CCSequence.filter (fun (e, v2') -> (PHashtbl.get_eq t) v2 v2') edges in
CCSequence.map fst edges
(** Call [k] on every vertex *)
let iter_vertices t k =
PHashtbl.iter (fun v _ -> k v) t
let vertices t =
Sequence.from_iter (iter_vertices t)
CCSequence.from_iter (iter_vertices t)
(** Call [k] on every edge *)
let iter t k =
@ -110,23 +110,23 @@ let iter t k =
t
let to_seq t =
Sequence.from_iter (iter t)
CCSequence.from_iter (iter t)
(** {2 Global operations} *)
(** Roots, ie vertices with no incoming edges *)
let roots g =
let vertices = vertices g in
Sequence.filter (fun v -> Sequence.is_empty (prev g v)) vertices
CCSequence.filter (fun v -> CCSequence.is_empty (prev g v)) vertices
(** Leaves, ie vertices with no outgoing edges *)
let leaves g =
let vertices = vertices g in
Sequence.filter (fun v -> Sequence.is_empty (next g v)) vertices
CCSequence.filter (fun v -> CCSequence.is_empty (next g v)) vertices
(** Pick a vertex, or raise Not_found *)
let choose g =
match Sequence.to_list (Sequence.take 1 (vertices g)) with
match CCSequence.to_list (CCSequence.take 1 (vertices g)) with
| [x] -> x
| [] -> raise Not_found
| _ -> assert false
@ -155,14 +155,14 @@ let bfs graph first k =
(* yield current node *)
k v;
(* explore children *)
Sequence.iter
CCSequence.iter
(fun (e, v') -> if not (Hashset.mem explored v')
then (Hashset.add explored v'; Queue.push v' q))
(next graph v)
done
let bfs_seq graph first =
Sequence.from_iter (fun k -> bfs graph first k)
CCSequence.from_iter (fun k -> bfs graph first k)
(** DFS, with callbacks called on each encountered node and edge *)
let dfs_full graph ?(labels=mk_v_table graph)
@ -183,7 +183,7 @@ first
(* enter the node *)
enter trail';
(* explore edges *)
Sequence.iter
CCSequence.iter
(fun (e, v') ->
try let n' = PHashtbl.find labels v' in
if n' < n && List.exists (fun (_,n'') -> n' = n'') trail'
@ -216,7 +216,7 @@ let is_dag g =
else try
let labels = mk_v_table g in
(* do a DFS from each root; any back edge indicates a cycle *)
Sequence.iter
CCSequence.iter
(fun v ->
dfs_full g ~labels ~back_edge:(fun _ -> raise Exit) v)
(vertices g);
@ -259,7 +259,7 @@ let min_path_full (type v) (type e) graph
else begin
Hashset.add explored v;
(* explore successors *)
Sequence.iter
CCSequence.iter
(fun (e, v') ->
if Hashset.mem explored v' || ignore v' then ()
else
@ -307,7 +307,7 @@ type attribute = [
(** Pretty print the graph in DOT, on given formatter. Using a sequence
allows to easily select which edges are important,
or to combine several graphs with [Sequence.append]. *)
or to combine several graphs with [CCSequence.append]. *)
let pp ~name ?vertices
~(print_edge : 'v -> 'e -> 'v -> attribute list)
~(print_vertex : 'v -> attribute list) formatter (graph : ('v, 'e) t) =
@ -341,20 +341,20 @@ let pp ~name ?vertices
(* print preamble *)
Format.fprintf formatter "@[<v2>digraph %s {@;" name;
(* print edges *)
Sequence.iter
CCSequence.iter
(fun (v1, e, v2) ->
let attributes = print_edge v1 e v2 in
Format.fprintf formatter " @[<h>%a -> %a [%a];@]@."
pp_vertex v1 pp_vertex v2
(Sequence.pp_seq ~sep:"," print_attribute)
(Sequence.of_list attributes))
(CCSequence.pp_seq ~sep:"," print_attribute)
(CCSequence.of_list attributes))
(to_seq graph);
(* print vertices *)
PHashtbl.iter
(fun v _ ->
let attributes = print_vertex v in
Format.fprintf formatter " @[<h>%a [%a];@]@." pp_vertex v
(Sequence.pp_seq ~sep:"," print_attribute) (Sequence.of_list attributes))
(CCSequence.pp_seq ~sep:"," print_attribute) (CCSequence.of_list attributes))
vertices;
(* close *)
Format.fprintf formatter "}@]@;";

View file

@ -51,31 +51,31 @@ val length : (_, _) t -> int
val add : ('v,'e) t -> 'v -> 'e -> 'v -> unit
(** Add an edge between two vertices *)
val add_seq : ('v,'e) t -> ('v * 'e * 'v) Sequence.t -> unit
val add_seq : ('v,'e) t -> ('v * 'e * 'v) CCSequence.t -> unit
(** Add the vertices to the graph *)
val next : ('v, 'e) t -> 'v -> ('e * 'v) Sequence.t
val next : ('v, 'e) t -> 'v -> ('e * 'v) CCSequence.t
(** Outgoing edges *)
val prev : ('v, 'e) t -> 'v -> ('e * 'v) Sequence.t
val prev : ('v, 'e) t -> 'v -> ('e * 'v) CCSequence.t
(** Incoming edges *)
val between : ('v, 'e) t -> 'v -> 'v -> 'e Sequence.t
val between : ('v, 'e) t -> 'v -> 'v -> 'e CCSequence.t
val iter_vertices : ('v, 'e) t -> ('v -> unit) -> unit
val vertices : ('v, 'e) t -> 'v Sequence.t
val vertices : ('v, 'e) t -> 'v CCSequence.t
(** Iterate on vertices *)
val iter : ('v, 'e) t -> ('v * 'e * 'v -> unit) -> unit
val to_seq : ('v, 'e) t -> ('v * 'e * 'v) Sequence.t
val to_seq : ('v, 'e) t -> ('v * 'e * 'v) CCSequence.t
(** Dump the graph as a sequence of vertices *)
(** {2 Global operations} *)
val roots : ('v, 'e) t -> 'v Sequence.t
val roots : ('v, 'e) t -> 'v CCSequence.t
(** Roots, ie vertices with no incoming edges *)
val leaves : ('v, 'e) t -> 'v Sequence.t
val leaves : ('v, 'e) t -> 'v CCSequence.t
(** Leaves, ie vertices with no outgoing edges *)
val choose : ('v, 'e) t -> 'v
@ -92,8 +92,8 @@ val rev : ('v, 'e) t -> unit
val bfs : ('v, 'e) t -> 'v -> ('v -> unit) -> unit
(** Breadth-first search, from given 'v *)
val bfs_seq : ('v, 'e) t -> 'v -> 'v Sequence.t
(** Sequence of vertices traversed during breadth-first search *)
val bfs_seq : ('v, 'e) t -> 'v -> 'v CCSequence.t
(** CCSequence of vertices traversed during breadth-first search *)
val dfs_full : ('v, 'e) t ->
?labels:('v, int) PHashtbl.t ->

View file

View file

@ -173,10 +173,10 @@ module Arbitrary : sig
(** Monadic bind *)
val retry : 'a option t -> 'a t
(** Generate until a Some value is returned *)
(** CCGenerate until a Some value is returned *)
val generate : ?n:int -> ?rand:Random.State.t -> 'a t -> 'a list
(** Generate [n] random values of the given type *)
(** CCGenerate [n] random values of the given type *)
end
(** {2 Pretty printing} *)

View file

@ -189,4 +189,4 @@ let gen l =
(** Add content of the iterator to the list *)
let of_gen l gen =
Gen.iter (fun (k,v) -> add l k v) gen
CCGen.iter (fun (k,v) -> add l k v) gen

View file

@ -53,6 +53,6 @@ val remove : ('a, 'b) t -> 'a -> unit
val length : (_, _) t -> int
(** Number of elements *)
val gen : ('a, 'b) t -> ('a * 'b) Gen.t
val gen : ('a, 'b) t -> ('a * 'b) CCGen.t
val of_gen : ('a, 'b) t -> ('a * 'b) Gen.t -> unit
val of_gen : ('a, 'b) t -> ('a * 'b) CCGen.t -> unit

View file

@ -123,11 +123,11 @@ let to_seq set =
iter k set
let of_seq set seq =
Sequence.fold add set seq
CCSequence.fold add set seq
let to_list set =
Sequence.to_rev_list (to_seq set)
CCSequence.to_rev_list (to_seq set)
let of_list set l =
of_seq set (Sequence.of_list l)
of_seq set (CCSequence.of_list l)

View file

@ -59,9 +59,9 @@ val iter : ('a -> unit) -> 'a t -> unit
val size : _ t -> int
(** Number of elements *)
val to_seq : 'a t -> 'a Sequence.t
val to_seq : 'a t -> 'a CCSequence.t
val of_seq : 'a t -> 'a Sequence.t -> 'a t
val of_seq : 'a t -> 'a CCSequence.t -> 'a t
val to_list : 'a t -> 'a list

View file

@ -192,11 +192,11 @@ let choose t =
| Node (k, v, _, _) -> k, v
let to_seq t =
Sequence.from_iter
CCSequence.from_iter
(fun kont -> iter t (fun k v -> kont (k, v)))
let of_seq t seq =
Sequence.fold (fun t (k, v) -> add t k v) t seq
CCSequence.fold (fun t (k, v) -> add t k v) t seq
(** {2 Functorial interface} *)
@ -238,9 +238,9 @@ module type S = sig
val choose : 'a t -> (key * 'a)
(** Some binding, or raises Not_found *)
val to_seq : 'a t -> (key * 'a) Sequence.t
val to_seq : 'a t -> (key * 'a) CCSequence.t
val of_seq : 'a t -> (key * 'a) Sequence.t -> 'a t
val of_seq : 'a t -> (key * 'a) CCSequence.t -> 'a t
end
module type ORDERED = sig
@ -404,9 +404,9 @@ module Make(X : ORDERED) = struct
| Node (k, v, _, _) -> k, v
let to_seq t =
Sequence.from_iter
CCSequence.from_iter
(fun kont -> iter t (fun k v -> kont (k, v)))
let of_seq t seq =
Sequence.fold (fun t (k, v) -> add t k v) t seq
CCSequence.fold (fun t (k, v) -> add t k v) t seq
end

View file

@ -69,9 +69,9 @@ val size : (_, _) t -> int
val choose : ('a, 'b) t -> ('a * 'b)
(** Some binding, or raises Not_found *)
val to_seq : ('a, 'b) t -> ('a * 'b) Sequence.t
val to_seq : ('a, 'b) t -> ('a * 'b) CCSequence.t
val of_seq : ('a, 'b) t -> ('a * 'b) Sequence.t -> ('a, 'b) t
val of_seq : ('a, 'b) t -> ('a * 'b) CCSequence.t -> ('a, 'b) t
(** {2 Functorial interface} *)
@ -113,9 +113,9 @@ module type S = sig
val choose : 'a t -> (key * 'a)
(** Some binding, or raises Not_found *)
val to_seq : 'a t -> (key * 'a) Sequence.t
val to_seq : 'a t -> (key * 'a) CCSequence.t
val of_seq : 'a t -> (key * 'a) Sequence.t -> 'a t
val of_seq : 'a t -> (key * 'a) CCSequence.t -> 'a t
end
module type ORDERED = sig

Some files were not shown because too many files have changed in this diff Show more