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 tests
S examples S examples
B _build B _build/core
B _build/misc
B _build/tests B _build/tests
B _build/examples B _build/examples
PKG oUnit PKG oUnit

View file

@ -51,7 +51,10 @@ push_doc: doc
scp -r containers.docdir/* cedeela.fr:~/simon/root/software/containers/ scp -r containers.docdir/* cedeela.fr:~/simon/root/software/containers/
DONTTEST=myocamlbuild.ml setup.ml 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: qtest-clean:
@rm -rf qtest/ @rm -rf qtest/
@ -59,7 +62,7 @@ qtest-clean:
qtest: qtest-clean build qtest: qtest-clean build
@mkdir -p qtest @mkdir -p qtest
@qtest extract -o qtest/qtest_all.ml $(QTESTABLE) 2> /dev/null @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 @echo
./qtest_all.native ./qtest_all.native

38
_oasis
View file

@ -15,6 +15,11 @@ Description:
abstractions, serialization systems, testing systems and various abstractions, serialization systems, testing systems and various
experiments. experiments.
Flag "misc"
Description: Build the misc library, containing everything from
the rotating kitchen sink to automatic banana distributors
Default: false
Flag "cgi" Flag "cgi"
Description: Build modules related to FastCGI, depending on CamlGI Description: Build modules related to FastCGI, depending on CamlGI
Default: false Default: false
@ -25,24 +30,33 @@ Flag "lwt"
Flag "thread" Flag "thread"
Description: Build modules that depend on threads Description: Build modules that depend on threads
Default: true Default: false
Flag "bench" Flag "bench"
Description: Build and run benchmarks Description: Build and run benchmarks
Default: false Default: false
Library "containers" 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 Pack: true
Modules: Cache, Deque, Gen, FHashtbl, FQueue, FlatHashtbl, Hashset, Modules: Cache, FHashtbl, FlatHashtbl, Hashset,
Heap, LazyGraph, PersistentGraph, PersistentHashtbl, Heap, LazyGraph, PersistentGraph,
PHashtbl, Sequence, SkipList, SplayTree, SplayMap, Univ, PHashtbl, SkipList, SplayTree, SplayMap, Univ,
Vector, Bij, PiCalculus, Bencode, Sexp, RAL, MultiSet, Bij, PiCalculus, Bencode, Sexp, RAL,
UnionFind, SmallSet, Leftistheap, AbsSet, CSM, MultiMap, UnionFind, SmallSet, AbsSet, CSM,
ActionMan, BV, QCheck, BencodeOnDisk, Show, TTree, ActionMan, QCheck, BencodeOnDisk, TTree,
HGraph, Automaton, Conv, Levenshtein, Bidir, Iteratee, HGraph, Automaton, Conv, Levenshtein, Bidir, Iteratee,
Ty, Tell, BencodeStream, RatTerm, Cause, KMP, CircList Ty, Tell, BencodeStream, RatTerm, Cause
BuildDepends: unix BuildDepends: unix,containers
FindlibName: misc
FindlibParent: containers
Library "containers_thread" Library "containers_thread"
Path: threads/ Path: threads/
@ -55,7 +69,7 @@ Library "containers_thread"
XMETARequires: containers,threads,lwt XMETARequires: containers,threads,lwt
Library "containers_lwt" Library "containers_lwt"
Path: lwt/ Path: .
Modules: Behavior, Lwt_automaton Modules: Behavior, Lwt_automaton
Pack: true Pack: true
FindlibName: lwt FindlibName: lwt
@ -89,7 +103,7 @@ Executable benchs
CompiledObject: native CompiledObject: native
Build$: flag(bench) Build$: flag(bench)
MainIs: benchs.ml MainIs: benchs.ml
BuildDepends: containers,bench BuildDepends: containers,containers.misc,bench
Executable bench_conv Executable bench_conv
Path: tests/ 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; iter (fun _ -> incr r) d;
!r !r
type 'a sequence = ('a -> unit) -> unit
let of_seq ?(deque=create ()) seq = let of_seq ?(deque=create ()) seq =
Sequence.iter (fun x -> push_back deque x) seq; seq (fun x -> push_back deque x);
deque 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 *) (* naive implem of copy, for now *)
let copy d = let copy d =

View file

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

View file

@ -80,6 +80,11 @@ let fold f acc q =
let iter f q = fold (fun () x -> f x) () 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 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 iter : ('a -> unit) -> 'a t -> unit
val to_seq : 'a t -> 'a Sequence.t type 'a sequence = ('a -> unit) -> unit
val to_seq : 'a t -> 'a sequence
val of_seq : 'a Sequence.t -> 'a t 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 *) (** Polymorphic implementation, following Okasaki *)
type 'a sequence = ('a -> unit) -> unit
type 'a t = { type 'a t = {
tree : 'a tree; tree : 'a tree;
leq : 'a -> 'a -> bool; leq : 'a -> 'a -> bool;
@ -117,7 +119,8 @@ let size heap =
!r !r
let of_seq heap seq = 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 = let to_seq = iter
Sequence.from_iter (fun k -> iter heap k)

View file

@ -27,6 +27,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(** Polymorphic implementation, following Okasaki *) (** Polymorphic implementation, following Okasaki *)
type 'a sequence = ('a -> unit) -> unit
type 'a t type 'a t
(** Heap containing values of type 'a *) (** Heap containing values of type 'a *)
@ -61,6 +63,6 @@ val iter : 'a t -> ('a -> unit) -> unit
val size : _ t -> int val size : _ t -> int
(** Number of elements (linear) *) (** 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. 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 module type S = sig
type key type key
@ -86,13 +88,13 @@ module type S = sig
val submap : t -> t -> bool val submap : t -> t -> bool
(** [submap m1 m2] is true iff all bindings of [m1] are also in [m2] *) (** [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 *) (** Some values may occur several times *)
end end
@ -212,15 +214,14 @@ module Make(K : OrderedType)(V : OrderedType) = struct
false) false)
m1 m1
let to_seq m = let to_seq m k = iter m (fun x y -> k (x,y))
Sequence.from_iter (fun k -> iter m (fun x y -> k (x,y)))
let of_seq ?(init=empty) seq = 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 = let keys m k = M.iter (fun x _ -> k x) m
Sequence.from_iter (fun k -> M.iter (fun x _ -> k x) m)
let values m = let values m k = iter m (fun _ v -> k v)
Sequence.from_iter (fun k -> iter m (fun _ v -> k v))
end 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. 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 module type S = sig
type key type key
@ -86,13 +88,13 @@ module type S = sig
val submap : t -> t -> bool val submap : t -> t -> bool
(** [submap m1 m2] is true iff all bindings of [m1] are also in [m2] *) (** [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 *) (** Some values may occur several times *)
end 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} *) (** {1 Persistent hash-table on top of OCaml's hashtables} *)
type 'a sequence = ('a -> unit) -> unit
module type HashedType = sig module type HashedType = sig
type t type t
val equal : t -> t -> bool val equal : t -> t -> bool
@ -75,12 +77,12 @@ module type S = sig
val fold : ('b -> key -> 'a -> 'b) -> 'b -> 'a t -> 'b val fold : ('b -> key -> 'a -> 'b) -> 'b -> 'a t -> 'b
(** Fold over bindings *) (** 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 *) (** Add (replace) bindings from the sequence to the table *)
val of_list : ?init:'a t -> (key * 'a) list -> 'a t 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 *) (** Sequence of the bindings of the table *)
val to_list : 'a t -> (key * 'a) list 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 let tbl = match init with
| None -> Table.create 5 | None -> Table.create 5
| Some t -> Table.copy (reroot t) in | Some t -> Table.copy (reroot t) in
Sequence.iter (fun (k,v) -> Table.replace tbl k v) seq; seq (fun (k,v) -> Table.replace tbl k v);
ref (Table tbl) ref (Table tbl)
let of_list ?init l = 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 to_list t =
let tbl = reroot t in 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} *) (** {1 Persistent hash-table on top of OCaml's hashtables} *)
type 'a sequence = ('a -> unit) -> unit
module type HashedType = sig module type HashedType = sig
type t type t
val equal : t -> t -> bool val equal : t -> t -> bool
@ -75,12 +77,12 @@ module type S = sig
val fold : ('b -> key -> 'a -> 'b) -> 'b -> 'a t -> 'b val fold : ('b -> key -> 'a -> 'b) -> 'b -> 'a t -> 'b
(** Fold over bindings *) (** 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 *) (** Add (replace) bindings from the sequence to the table *)
val of_list : ?init:'a t -> (key * 'a) list -> 'a t 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 *) (** Sequence of the bindings of the table *)
val to_list : 'a t -> (key * 'a) list 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 a.size <- a.size + Array.length b
let append_seq a seq = let append_seq a seq =
Sequence.iter (fun x -> push a x) seq seq (fun x -> push a x)
let pop v = let pop v =
(if v.size = 0 then failwith "Vector.pop on empty vector"); (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 let unsafe_get_array v = v.vec
type 'a sequence = ('a -> unit) -> unit
let of_seq ?(init=create 10) seq = let of_seq ?(init=create 10) seq =
append_seq init seq; append_seq init seq;
init init
let to_seq t = let to_seq = iter
Sequence.from_iter (fun k -> iter t k)
let slice v start len = let slice v start len =
assert (start >= 0 && len >= 0); assert (start >= 0 && len >= 0);
Sequence.from_iter fun k ->
(fun k ->
assert (start+len < v.size); assert (start+len < v.size);
for i = start to start+len do for i = start to start+len do
let x = Array.unsafe_get v.vec i in let x = Array.unsafe_get v.vec i in
k x k x
done) done
let from_array a = let from_array a =
let c = Array.length a in 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 type 'a t
(** the type of a vector of 'a *) (** the type of a vector of 'a *)
type 'a sequence = ('a -> unit) -> unit
val create : int -> 'a t val create : int -> 'a t
(** create a vector of given initial capacity *) (** 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 val append_array : 'a t -> 'a array -> unit
(** same as append, with an array *) (** 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 *) (** Append content of sequence *)
val pop : 'a t -> 'a 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 [unsafe_get_array v] is longer than [size v], but elements at higher
index than [size v] are undefined (do not access!). *) 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)] (** [slice v start len] is the sequence of elements from [v.(start)]
to [v.(start+len)] included. *) 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) let build state x = Some (x::state, x::state)
end end
module Gen = struct module CCGen = struct
type 'a gen = unit -> 'a option type 'a gen = unit -> 'a option
let map a state gen = let map a state gen =
@ -227,7 +227,7 @@ module Gen = struct
end end
end end
module Sequence = struct module CCSequence = struct
type 'a sequence = ('a -> unit) -> unit type 'a sequence = ('a -> unit) -> unit
exception ExitSeq exception ExitSeq

View file

@ -140,13 +140,13 @@ module List : sig
(** build a list from its inputs *) (** build a list from its inputs *)
end end
module Gen : sig module CCGen : sig
type 'a gen = unit -> 'a option type 'a gen = unit -> 'a option
val map : ('a, 's, 'b) t -> 's -> 'a gen -> 'b gen val map : ('a, 's, 'b) t -> 's -> 'a gen -> 'b gen
end end
module Sequence : sig module CCSequence : sig
type 'a sequence = ('a -> unit) -> unit type 'a sequence = ('a -> unit) -> unit
val map : ('a, 's, 'b) t -> 's -> 'a sequence -> 'b sequence 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; } { mem; iter; cardinal; }
let to_seq set = 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 to_list set =
let l = ref [] in let l = ref [] in
@ -154,7 +154,7 @@ let builder_cmp (type k) ?(cmp=Pervasives.compare) () =
mk_builder ~add ~get mk_builder ~add ~get
let of_seq_builder ~builder seq = let of_seq_builder ~builder seq =
Sequence.iter builder.add seq; CCSequence.iter builder.add seq;
builder.get () builder.get ()
let of_seq_hash ?eq ?hash seq = let of_seq_hash ?eq ?hash seq =
@ -165,7 +165,7 @@ let of_seq_cmp ?cmp seq =
let b = builder_cmp ?cmp () in let b = builder_cmp ?cmp () in
of_seq_builder b seq 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 = let map ?(builder=builder_hash ()) set ~f =
set.iter set.iter
@ -202,7 +202,7 @@ module MakeHash(X : Hashtbl.HashedType) = struct
let of_seq ?(size=5) seq = let of_seq ?(size=5) seq =
let h = Hashtbl.create size in 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 mem x = Hashtbl.mem h x in
let iter k = Hashtbl.iter (fun x () -> k x) h in let iter k = Hashtbl.iter (fun x () -> k x) h in
let cardinal () = Hashtbl.length h in let cardinal () = Hashtbl.length h in
@ -220,7 +220,7 @@ module MakeSet(S : Set.S) = struct
mk_generic ~cardinal ~mem ~iter mk_generic ~cardinal ~mem ~iter
let of_seq ?(init=S.empty) seq = 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 of_set set
let to_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) -> val mk_generic : ?cardinal:(unit -> int) ->
mem:('a -> bool) -> mem:('a -> bool) ->
iter:(('a -> unit) -> unit) -> 'a t 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 function, and possibly a cardinal function (supposed to return
the number of elements) *) 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 val product : 'a t -> 'b t -> ('a * 'b) t
(** Cartesian product *) (** 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 val to_list : 'a t -> 'a list
@ -84,7 +84,7 @@ val to_list : 'a t -> 'a list
type 'a builder type 'a builder
val mk_builder : add:('a -> unit) -> get:(unit -> 'a t) -> '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 -> val builder_hash : ?size:int ->
?eq:('a -> 'a -> bool) -> ?eq:('a -> 'a -> bool) ->
@ -93,13 +93,13 @@ val builder_hash : ?size:int ->
val builder_cmp : ?cmp:('a -> 'a -> int) -> unit -> 'a builder 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 *) (** 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 *) (** 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 *) (** Construction of a set from a sequence of comparable elements *)
val of_list : 'a list -> 'a t val of_list : 'a list -> 'a t
@ -133,7 +133,7 @@ module MakeHash(X : Hashtbl.HashedType) : sig
type elt = X.t type elt = X.t
(** Elements of the set are hashable *) (** 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 *) (** Build a set from a sequence *)
end end
@ -141,7 +141,7 @@ end
module MakeSet(S : Set.S) : sig module MakeSet(S : Set.S) : sig
type elt = S.elt 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 *) (** Build a set from a sequence *)
val of_set : S.t -> elt t val of_set : S.t -> elt t

View file

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

View file

View file

@ -158,10 +158,10 @@ module Make(T : CurryfiedTerm) = struct
end end
(* Persistent Hashtable on curryfied terms *) (* Persistent Hashtable on curryfied terms *)
module THashtbl = PersistentHashtbl.Make(HashedCT) module THashtbl = CCPersistentHashtbl.Make(HashedCT)
(* Persistent Hashtable on pairs of curryfied terms *) (* Persistent Hashtable on pairs of curryfied terms *)
module T2Hashtbl = PersistentHashtbl.Make(struct module T2Hashtbl = CCPersistentHashtbl.Make(struct
type t = CT.t * CT.t 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 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 let hash (t,t') = t.CT.tag * 65599 + t'.CT.tag

View file

View file

@ -124,7 +124,7 @@ let gen l =
(*$Q (*$Q
(Q.list Q.small_int) (fun l -> \ (Q.list Q.small_int) (fun l -> \
l = [] || let q = of_list l in \ 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 = let seq l k =

View file

@ -76,7 +76,7 @@ type 'a gen = unit -> 'a option
type 'a sequence = ('a -> unit) -> unit type 'a sequence = ('a -> unit) -> unit
val gen : 'a t -> 'a gen val gen : 'a t -> 'a gen
(** Generator on elements of the list *) (** CCGenerator on elements of the list *)
val seq : 'a t -> 'a sequence 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 val size : 'a t -> int
(** Number of bindings *) (** 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 end
(** {2 Persistent array} *) (** {2 Persistent array} *)
@ -337,10 +337,10 @@ module Tree(X : HASH) = struct
fold (fun n _ _ -> n + 1) 0 t fold (fun n _ _ -> n + 1) 0 t
let to_seq 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 = let of_seq ?(size=32) seq =
Sequence.fold CCSequence.fold
(fun t (k,v) -> replace t k v) (fun t (k,v) -> replace t k v)
(empty size) seq (empty size) seq
end end
@ -493,9 +493,9 @@ module Flat(X : HASH) = struct
acc t.buckets acc t.buckets
let to_seq t = let to_seq t =
Sequence.from_iter CCSequence.from_iter
(fun k -> iter (fun key value -> k (key, value)) t) (fun k -> iter (fun key value -> k (key, value)) t)
let of_seq ?(size=32) seq = 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 end

View file

@ -64,9 +64,9 @@ module type S = sig
val size : 'a t -> int val size : 'a t -> int
(** Number of bindings *) (** 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 end
(** {2 Persistent array} *) (** {2 Persistent array} *)

View file

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

View file

@ -26,7 +26,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(** {2 Hypergraph Representation} (** {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 connect [n] other objets together (a [n]-tuple). Each hyperedge can contain
additional data. additional data.
*) *)

View file

@ -26,7 +26,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(** {2 Hypergraph Representation} (** {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). connect [n] other objets together (a [n]-tuple).
Hashconsing is used to ensure that structural equality implies physical 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 filter p set = PHashtbl.filter (fun x () -> p x) set
let to_seq 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 = 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 union ?into (s1 : 'a t) (s2 : 'a t) =
let into = match into with let into = match into with
@ -67,5 +67,5 @@ let inter ?into (s1 : 'a t) (s2 : 'a t) =
| Some s -> s | Some s -> s
| None -> empty ~eq:s1.PHashtbl.eq ~hash:s1.PHashtbl.hash (cardinal s1) in | None -> empty ~eq:s1.PHashtbl.eq ~hash:s1.PHashtbl.hash (cardinal s1) in
(* add to [into] elements of [s1] that also belong to [s2] *) (* 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 into

View file

@ -51,9 +51,9 @@ val fold : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b
val filter : ('a -> bool) -> 'a t -> unit val filter : ('a -> bool) -> 'a t -> unit
(** destructive filter (remove elements that do not satisfy the predicate) *) (** 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 val union : ?into:'a t -> 'a t -> 'a t -> 'a t
(** Set union. The result is stored in [into] *) (** 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 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. *) other vertices, or to Empty if the identifier is not part of the graph. *)
and ('id, 'v, 'e) node = and ('id, 'v, 'e) node =
| Empty | 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 *) (** A single node of the graph, with outgoing edges *)
and ('id, 'e) path = ('id * 'e * 'id) list and ('id, 'e) path = ('id * 'e * 'id) list
(** A reverse path (from the last element of the path to the first). *) (** 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 singleton ?(eq=(=)) ?(hash=Hashtbl.hash) v label =
let force v' = 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; } { force; eq; hash; }
let make ?(eq=(=)) ?(hash=Hashtbl.hash) force = let make ?(eq=(=)) ?(hash=Hashtbl.hash) force =
@ -66,7 +66,7 @@ let from_fun ?(eq=(=)) ?(hash=Hashtbl.hash) f =
let force v = let force v =
match f v with match f v with
| None -> Empty | 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; } { eq; hash; force; }
(** {2 Polymorphic map} *) (** {2 Polymorphic map} *)
@ -110,7 +110,7 @@ module Mutable = struct
let map = mk_map ~eq ~hash in let map = mk_map ~eq ~hash in
let force v = let force v =
try let node = map.map_get v in 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 with Not_found -> Empty in
let graph = { eq; hash; force; } in let graph = { eq; hash; force; } in
map, graph map, graph
@ -129,10 +129,10 @@ end
let from_enum ?(eq=(=)) ?(hash=Hashtbl.hash) ~vertices ~edges = let from_enum ?(eq=(=)) ?(hash=Hashtbl.hash) ~vertices ~edges =
let g, lazy_g = Mutable.create ~eq ~hash () in let g, lazy_g = Mutable.create ~eq ~hash () in
Sequence.iter CCSequence.iter
(fun (v,label_v) -> Mutable.add_vertex g v label_v;) (fun (v,label_v) -> Mutable.add_vertex g v label_v;)
vertices; vertices;
Sequence.iter CCSequence.iter
(fun (v1, e, v2) -> Mutable.add_edge g v1 e v2) (fun (v1, e, v2) -> Mutable.add_edge g v1 e v2)
edges; edges;
lazy_g lazy_g
@ -174,11 +174,11 @@ module Full = struct
| [] -> false | [] -> false
let bfs_full graph vertices = 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 explored = mk_map ~eq:graph.eq ~hash:graph.hash in
let id = ref 0 in let id = ref 0 in
let q = Queue.create () in (* queue of nodes to explore *) 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 while not (Queue.is_empty q) do
match Queue.pop q with match Queue.pop q with
| FullEnter (v', path) -> | FullEnter (v', path) ->
@ -188,7 +188,7 @@ module Full = struct
| Node (_, label, edges) -> | Node (_, label, edges) ->
explored.map_add v' (); explored.map_add v' ();
(* explore neighbors *) (* explore neighbors *)
Sequence.iter CCSequence.iter
(fun (e,v'') -> (fun (e,v'') ->
let path' = (v'',e,v') :: path in let path' = (v'',e,v') :: path in
Queue.push (FullFollowEdge path') q) Queue.push (FullFollowEdge path') q)
@ -219,11 +219,11 @@ module Full = struct
checking whether the node is in the path (should be faster) *) checking whether the node is in the path (should be faster) *)
let dfs_full graph vertices = 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 explored = mk_map ~eq:graph.eq ~hash:graph.hash in
let id = ref 0 in let id = ref 0 in
let s = Stack.create () in (* stack of nodes to explore *) 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 while not (Stack.is_empty s) do
match Stack.pop s with match Stack.pop s with
| FullExit v' -> k (ExitVertex v') | FullExit v' -> k (ExitVertex v')
@ -237,7 +237,7 @@ module Full = struct
(* prepare to exit later *) (* prepare to exit later *)
Stack.push (FullExit v') s; Stack.push (FullExit v') s;
(* explore neighbors *) (* explore neighbors *)
Sequence.iter CCSequence.iter
(fun (e,v'') -> (fun (e,v'') ->
Stack.push (FullFollowEdge ((v'', e, v') :: path)) s) Stack.push (FullFollowEdge ((v'', e, v') :: path)) s)
edges; edges;
@ -262,18 +262,18 @@ module Full = struct
end end
let bfs graph v = let bfs graph v =
Sequence.fmap CCSequence.fmap
(function (function
| Full.EnterVertex (v, l, i, _) -> Some (v, l, i) | Full.EnterVertex (v, l, i, _) -> Some (v, l, i)
| _ -> None) | _ -> None)
(Full.bfs_full graph (Sequence.singleton v)) (Full.bfs_full graph (CCSequence.singleton v))
let dfs graph v = let dfs graph v =
Sequence.fmap CCSequence.fmap
(function (function
| Full.EnterVertex (v, l, i, _) -> Some (v, l, i) | Full.EnterVertex (v, l, i, _) -> Some (v, l, i)
| _ -> None) | _ -> None)
(Full.dfs_full graph (Sequence.singleton v)) (Full.dfs_full graph (CCSequence.singleton v))
(** {3 Mutable heap} *) (** {3 Mutable heap} *)
module Heap = struct module Heap = struct
@ -342,7 +342,7 @@ let a_star graph
?(distance=(fun v1 e v2 -> 1.)) ?(distance=(fun v1 e v2 -> 1.))
~goal ~goal
start = start =
Sequence.from_iter (fun k -> CCSequence.from_iter (fun k ->
(* map node -> 'came_from' cell *) (* map node -> 'came_from' cell *)
let nodes = mk_map ~eq:graph.eq ~hash:graph.hash in let nodes = mk_map ~eq:graph.eq ~hash:graph.hash in
(* priority queue for nodes to explore *) (* priority queue for nodes to explore *)
@ -376,7 +376,7 @@ let a_star graph
| Empty -> () | Empty -> ()
| Node (_, label, edges) -> | Node (_, label, edges) ->
(* explore neighbors *) (* explore neighbors *)
Sequence.iter CCSequence.iter
(fun (e,v'') -> (fun (e,v'') ->
let cost = dist +. distance v' e v'' +. heuristic v'' in let cost = dist +. distance v' e v'' +. heuristic v'' in
let cell' = 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.) a_star graph ?on_explore ~ignore ~distance ~heuristic:(fun _ -> 0.)
~goal:(fun v -> graph.eq v v2) v1 ~goal:(fun v -> graph.eq v v2) v1
in in
match Sequence.to_list (Sequence.take 1 paths) with match CCSequence.to_list (CCSequence.take 1 paths) with
| [] -> raise Not_found | [] -> raise Not_found
| [x] -> x | [x] -> x
| _ -> assert false | _ -> 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 (** Is the subgraph explorable from the given vertex, a Directed
Acyclic Graph? *) Acyclic Graph? *)
let is_dag graph v = let is_dag graph v =
Sequence.for_all CCSequence.for_all
(function (function
| Full.MeetEdge (_, _, _, Full.EdgeBackward) -> false | Full.MeetEdge (_, _, _, Full.EdgeBackward) -> false
| _ -> true) | _ -> true)
(Full.dfs_full graph (Sequence.singleton v)) (Full.dfs_full graph (CCSequence.singleton v))
let is_dag_full graph vs = let is_dag_full graph vs =
Sequence.for_all CCSequence.for_all
(function (function
| Full.MeetEdge (_, _, _, Full.EdgeBackward) -> false | Full.MeetEdge (_, _, _, Full.EdgeBackward) -> false
| _ -> true) | _ -> true)
@ -443,8 +443,8 @@ let find_cycle graph v =
let cycle = ref [] in let cycle = ref [] in
try try
let path_stack = Stack.create () in let path_stack = Stack.create () in
let seq = Full.dfs_full graph (Sequence.singleton v) in let seq = Full.dfs_full graph (CCSequence.singleton v) in
Sequence.iter CCSequence.iter
(function (function
| Full.EnterVertex (_, _, _, path) -> | Full.EnterVertex (_, _, _, path) ->
Stack.push path path_stack Stack.push path path_stack
@ -478,7 +478,7 @@ let union ?(combine=fun x y -> x) g1 g2 =
| ((Node _) as n), Empty -> n | ((Node _) as n), Empty -> n
| Empty, ((Node _) as n) -> n | Empty, ((Node _) as n) -> n
| Node (_, l1, e1), Node (_, l2, e2) -> | 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; } in { eq=g1.eq; hash=g1.hash; force; }
let map ~vertices ~edges g = let map ~vertices ~edges g =
@ -486,7 +486,7 @@ let map ~vertices ~edges g =
match g.force v with match g.force v with
| Empty -> Empty | Empty -> Empty
| Node (_, l, edges_enum) -> | 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') Node (v, vertices l, edges_enum')
in { eq=g.eq; hash=g.hash; force; } in { eq=g.eq; hash=g.hash; force; }
@ -497,9 +497,9 @@ let flatMap f g =
match g.force v with match g.force v with
| Empty -> Empty | Empty -> Empty
| Node (_, l, edges_enum) -> | Node (_, l, edges_enum) ->
let edges_enum' = Sequence.flatMap let edges_enum' = CCSequence.flatMap
(fun (e, v') -> (fun (e, v') ->
Sequence.map (fun v'' -> e, v'') (f v')) CCSequence.map (fun v'' -> e, v'') (f v'))
edges_enum in edges_enum in
Node (v, l, edges_enum') Node (v, l, edges_enum')
in { eq=g.eq; hash=g.hash; force; } 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 | Empty -> Empty
| Node (_, l, edges_enum) when vertices v l -> | Node (_, l, edges_enum) when vertices v l ->
(* filter out edges *) (* 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 (v, l, edges_enum')
| Node _ -> Empty (* filter out this vertex *) | Node _ -> Empty (* filter out this vertex *)
in { eq=g.eq; hash=g.hash; force; } in { eq=g.eq; hash=g.hash; force; }
@ -522,8 +522,8 @@ let product g1 g2 =
| _, Empty -> Empty | _, Empty -> Empty
| Node (_, l1, edges1), Node (_, l2, edges2) -> | Node (_, l1, edges1), Node (_, l2, edges2) ->
(* product of edges *) (* product of edges *)
let edges = Sequence.product edges1 edges2 in let edges = CCSequence.product edges1 edges2 in
let edges = Sequence.map (fun ((e1,v1'),(e2,v2')) -> ((e1,e2),(v1',v2'))) edges in let edges = CCSequence.map (fun ((e1,v1'),(e2,v2')) -> ((e1,e2),(v1',v2'))) edges in
Node ((v1,v2), (l1,l2), edges) Node ((v1,v2), (l1,l2), edges)
and eq (v1,v2) (v1',v2') = and eq (v1,v2) (v1',v2') =
g1.eq v1 v1' && g2.eq v2 v2' g1.eq v1 v1' && g2.eq v2 v2'
@ -574,17 +574,17 @@ module Dot = struct
(* print preamble *) (* print preamble *)
Format.fprintf formatter "@[<v2>digraph %s {@;" name; Format.fprintf formatter "@[<v2>digraph %s {@;" name;
(* traverse *) (* traverse *)
Sequence.iter CCSequence.iter
(function (function
| Full.EnterVertex (v, attrs, _, _) -> | Full.EnterVertex (v, attrs, _, _) ->
Format.fprintf formatter " @[<h>%a [%a];@]@." pp_vertex v 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.ExitVertex _ -> ()
| Full.MeetEdge (v2, attrs, v1, _) -> | Full.MeetEdge (v2, attrs, v1, _) ->
Format.fprintf formatter " @[<h>%a -> %a [%a];@]@." Format.fprintf formatter " @[<h>%a -> %a [%a];@]@."
pp_vertex v1 pp_vertex v2 pp_vertex v1 pp_vertex v2
(Sequence.pp_seq ~sep:"," print_attribute) (CCSequence.pp_seq ~sep:"," print_attribute)
(Sequence.of_list attrs)) (CCSequence.of_list attrs))
events; events;
(* close *) (* close *)
Format.fprintf formatter "}@]@;@?"; Format.fprintf formatter "}@]@;@?";
@ -608,17 +608,17 @@ let divisors_graph =
if i > 2 if i > 2
then then
let l = divisors [] 2 i in 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) Node (i, i, edges)
else else
Node (i, i, Sequence.empty) Node (i, i, CCSequence.empty)
in make force in make force
let collatz_graph = let collatz_graph =
let force i = let force i =
if i mod 2 = 0 if i mod 2 = 0
then Node (i, i, Sequence.singleton ((), i / 2)) then Node (i, i, CCSequence.singleton ((), i / 2))
else Node (i, i, Sequence.singleton ((), i * 3 + 1)) else Node (i, i, CCSequence.singleton ((), i * 3 + 1))
in make force in make force
let collatz_graph_bis = let collatz_graph_bis =
@ -628,10 +628,10 @@ let collatz_graph_bis =
; false, i * 2 ] @ ; false, i * 2 ] @
if i mod 3 = 1 then [false, (i-1)/3] else [] if i mod 3 = 1 then [false, (i-1)/3] else []
in in
Node (i, i, Sequence.of_list l) Node (i, i, CCSequence.of_list l)
in make force in make force
let heap_graph = let heap_graph =
let force i = 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 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. *) other vertices, or to Empty if the identifier is not part of the graph. *)
and ('id, 'v, 'e) node = and ('id, 'v, 'e) node =
| Empty | 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 *) (** A single node of the graph, with outgoing edges *)
and ('id, 'e) path = ('id * 'e * 'id) list and ('id, 'e) path = ('id * 'e * 'id) list
(** A reverse path (from the last element of the path to the first). *) (** 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 *) (** Build a graph from the [force] function *)
val from_enum : ?eq:('id -> 'id -> bool) -> ?hash:('id -> int) -> val from_enum : ?eq:('id -> 'id -> bool) -> ?hash:('id -> int) ->
vertices:('id * 'v) Sequence.t -> vertices:('id * 'v) CCSequence.t ->
edges:('id * 'e * 'id) Sequence.t -> edges:('id * 'e * 'id) CCSequence.t ->
('id, 'v, 'e) t ('id, 'v, 'e) t
(** Concrete (eager) representation of a Graph *) (** Concrete (eager) representation of a Graph *)
@ -117,21 +117,21 @@ module Full : sig
| EdgeBackward (* toward the current trail *) | EdgeBackward (* toward the current trail *)
| EdgeTransverse (* toward a totally explored part of the graph *) | EdgeTransverse (* toward a totally explored part of the graph *)
val bfs_full : ('id, 'v, 'e) t -> 'id Sequence.t -> val bfs_full : ('id, 'v, 'e) t -> 'id CCSequence.t ->
('id, 'v, 'e) traverse_event Sequence.t ('id, 'v, 'e) traverse_event CCSequence.t
(** Lazy traversal in breadth first from a finite set of vertices *) (** Lazy traversal in breadth first from a finite set of vertices *)
val dfs_full : ('id, 'v, 'e) t -> 'id Sequence.t -> val dfs_full : ('id, 'v, 'e) t -> 'id CCSequence.t ->
('id, 'v, 'e) traverse_event Sequence.t ('id, 'v, 'e) traverse_event CCSequence.t
(** Lazy traversal in depth first from a finite set of vertices *) (** Lazy traversal in depth first from a finite set of vertices *)
end end
(** The traversal functions assign a unique ID to every traversed node *) (** 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 *) (** 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 *) (** Lazy traversal in depth first *)
module Heap : sig module Heap : sig
@ -149,7 +149,7 @@ val a_star : ('id, 'v, 'e) t ->
?distance:('id -> 'e -> 'id -> float) -> ?distance:('id -> 'e -> 'id -> float) ->
goal:('id -> bool) -> goal:('id -> bool) ->
'id -> '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 (** Shortest path from the first node to nodes that satisfy [goal], according
to the given (positive!) distance function. The distance is also returned. to the given (positive!) distance function. The distance is also returned.
[ignore] allows one to ignore some vertices during exploration. [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 (** Is the subgraph explorable from the given vertex, a Directed
Acyclic Graph? *) 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} *) (** Is the Graph reachable from the given vertices, a DAG? See {! is_dag} *)
val find_cycle : ('id, _, 'e) t -> 'id -> ('id, 'e) path 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 ('id, 'v, 'e) t -> ('id, 'v2, 'e2) t
(** Map vertice and edge labels *) (** 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 ->
('id, 'v, 'e) t ('id, 'v, 'e) t
(** Replace each vertex by some vertices. By mapping [v'] to [f v'=v1,...,vn], (** 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) -> val pp_enum : ?eq:('id -> 'id -> bool) -> ?hash:('id -> int) ->
name:string -> Format.formatter -> 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 unit
val pp : name:string -> ('id, attribute list, attribute list) t -> val pp : name:string -> ('id, attribute list, attribute list) t ->
Format.formatter -> Format.formatter ->
'id Sequence.t -> unit 'id CCSequence.t -> unit
(** Pretty print the given graph (starting from the given set of vertices) (** Pretty print the given graph (starting from the given set of vertices)
to the channel in DOT format *) to the channel in DOT format *)
end end

View file

@ -217,11 +217,11 @@ let filter pred t =
(** Add the given pairs to the hashtable *) (** Add the given pairs to the hashtable *)
let of_seq t seq = 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 = let to_seq t =
Sequence.from_iter CCSequence.from_iter
(fun kont -> iter (fun k v -> kont (k,v)) t) (fun kont -> iter (fun k v -> kont (k,v)) t)
(** Statistics on the table *) (** 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 val fold : ('c -> 'a -> 'b -> 'c) -> 'c -> ('a, 'b) t -> 'c
(** Fold on bindings *) (** 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 *) (** Add the given pairs to the hashtable *)
val to_seq : ('a, 'b) t -> ('a * 'b) Sequence.t val to_seq : ('a, 'b) t -> ('a * 'b) CCSequence.t
(** Sequence of pairs *) (** CCSequence of pairs *)
val stats : (_, _) t -> int * int * int * int * int * int val stats : (_, _) t -> int * int * int * int * int * int
(** Cf Weak.S *) (** Cf Weak.S *)

View file

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

View file

@ -51,31 +51,31 @@ val length : (_, _) t -> int
val add : ('v,'e) t -> 'v -> 'e -> 'v -> unit val add : ('v,'e) t -> 'v -> 'e -> 'v -> unit
(** Add an edge between two vertices *) (** 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 *) (** 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 *) (** Outgoing edges *)
val prev : ('v, 'e) t -> 'v -> ('e * 'v) Sequence.t val prev : ('v, 'e) t -> 'v -> ('e * 'v) CCSequence.t
(** Incoming edges *) (** 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 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 *) (** Iterate on vertices *)
val iter : ('v, 'e) t -> ('v * 'e * 'v -> unit) -> unit 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 *) (** Dump the graph as a sequence of vertices *)
(** {2 Global operations} *) (** {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 *) (** 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 *) (** Leaves, ie vertices with no outgoing edges *)
val choose : ('v, 'e) t -> 'v 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 val bfs : ('v, 'e) t -> 'v -> ('v -> unit) -> unit
(** Breadth-first search, from given 'v *) (** Breadth-first search, from given 'v *)
val bfs_seq : ('v, 'e) t -> 'v -> 'v Sequence.t val bfs_seq : ('v, 'e) t -> 'v -> 'v CCSequence.t
(** Sequence of vertices traversed during breadth-first search *) (** CCSequence of vertices traversed during breadth-first search *)
val dfs_full : ('v, 'e) t -> val dfs_full : ('v, 'e) t ->
?labels:('v, int) PHashtbl.t -> ?labels:('v, int) PHashtbl.t ->

View file

View file

@ -173,10 +173,10 @@ module Arbitrary : sig
(** Monadic bind *) (** Monadic bind *)
val retry : 'a option t -> 'a t 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 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 end
(** {2 Pretty printing} *) (** {2 Pretty printing} *)

View file

@ -189,4 +189,4 @@ let gen l =
(** Add content of the iterator to the list *) (** Add content of the iterator to the list *)
let of_gen l gen = 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 val length : (_, _) t -> int
(** Number of elements *) (** 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 iter k set
let of_seq set seq = let of_seq set seq =
Sequence.fold add set seq CCSequence.fold add set seq
let to_list set = let to_list set =
Sequence.to_rev_list (to_seq set) CCSequence.to_rev_list (to_seq set)
let of_list set l = 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 val size : _ t -> int
(** Number of elements *) (** 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 val to_list : 'a t -> 'a list

View file

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

View file

@ -69,9 +69,9 @@ val size : (_, _) t -> int
val choose : ('a, 'b) t -> ('a * 'b) val choose : ('a, 'b) t -> ('a * 'b)
(** Some binding, or raises Not_found *) (** 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} *) (** {2 Functorial interface} *)
@ -113,9 +113,9 @@ module type S = sig
val choose : 'a t -> (key * 'a) val choose : 'a t -> (key * 'a)
(** Some binding, or raises Not_found *) (** 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 end
module type ORDERED = sig module type ORDERED = sig

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