From 4bc6c8a0088db4884d5ba3cdf1f5d7800888b725 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Fri, 16 May 2014 20:58:28 +0200 Subject: [PATCH] split into package core (no pack, 'CC' prefix, stable) and misc where oneshot ideas go --- .merlin | 6 +- Makefile | 7 +- _oasis | 48 +++++++---- containers.mldylib | 4 - containers_lwt.mldylib | 4 - BV.ml => core/CCBV.ml | 0 BV.mli => core/CCBV.mli | 0 deque.ml => core/CCDeque.ml | 6 +- deque.mli => core/CCDeque.mli | 5 +- fQueue.ml => core/CCFQueue.ml | 7 +- fQueue.mli => core/CCFQueue.mli | 6 +- gen.ml => core/CCGen.ml | 0 gen.mli => core/CCGen.mli | 0 KMP.ml => core/CCKMP.ml | 0 KMP.mli => core/CCKMP.mli | 0 leftistheap.ml => core/CCLeftistheap.ml | 9 +- leftistheap.mli => core/CCLeftistheap.mli | 6 +- multiMap.ml => core/CCMultiMap.ml | 25 +++--- multiMap.mli => core/CCMultiMap.mli | 12 +-- multiSet.ml => core/CCMultiSet.ml | 0 multiSet.mli => core/CCMultiSet.mli | 0 .../CCPersistentHashtbl.ml | 12 +-- .../CCPersistentHashtbl.mli | 6 +- show.ml => core/CCPrint.ml | 0 show.mli => core/CCPrint.mli | 0 sequence.ml => core/CCSequence.ml | 0 sequence.mli => core/CCSequence.mli | 0 vector.ml => core/CCVector.ml | 20 ++--- vector.mli => core/CCVector.mli | 10 ++- lwt_containers.mllib | 1 - lwt_containers.odocl | 1 - CSM.ml => misc/CSM.ml | 4 +- CSM.mli => misc/CSM.mli | 4 +- RAL.ml => misc/RAL.ml | 0 RAL.mli => misc/RAL.mli | 0 absSet.ml => misc/absSet.ml | 10 +-- absSet.mli => misc/absSet.mli | 16 ++-- actionMan.ml => misc/actionMan.ml | 0 actionMan.mli => misc/actionMan.mli | 2 +- automaton.ml => misc/automaton.ml | 0 automaton.mli => misc/automaton.mli | 0 bencode.ml => misc/bencode.ml | 0 bencode.mli => misc/bencode.mli | 0 bencodeOnDisk.ml => misc/bencodeOnDisk.ml | 0 bencodeOnDisk.mli => misc/bencodeOnDisk.mli | 0 bencodeStream.ml => misc/bencodeStream.ml | 0 bencodeStream.mli => misc/bencodeStream.mli | 0 .../bencode_write_par.sh | 0 bidir.ml => misc/bidir.ml | 0 bidir.mli => misc/bidir.mli | 0 bij.ml => misc/bij.ml | 0 bij.mli => misc/bij.mli | 0 cC.ml => misc/cC.ml | 4 +- cC.mli => misc/cC.mli | 0 cache.ml => misc/cache.ml | 0 cache.mli => misc/cache.mli | 0 cause.ml => misc/cause.ml | 0 cause.mli => misc/cause.mli | 0 circList.ml => misc/circList.ml | 2 +- circList.mli => misc/circList.mli | 4 +- conv.ml => misc/conv.ml | 0 conv.mli => misc/conv.mli | 0 fHashtbl.ml => misc/fHashtbl.ml | 12 +-- fHashtbl.mli => misc/fHashtbl.mli | 4 +- flatHashtbl.ml => misc/flatHashtbl.ml | 8 +- flatHashtbl.mli => misc/flatHashtbl.mli | 4 +- hGraph.ml => misc/hGraph.ml | 2 +- hGraph.mli => misc/hGraph.mli | 2 +- hashset.ml => misc/hashset.ml | 6 +- hashset.mli => misc/hashset.mli | 4 +- heap.ml => misc/heap.ml | 0 heap.mli => misc/heap.mli | 4 +- iteratee.ml => misc/iteratee.ml | 0 iteratee.mli => misc/iteratee.mli | 0 json.ml => misc/json.ml | 0 json.mli => misc/json.mli | 0 lazyGraph.ml => misc/lazyGraph.ml | 82 +++++++++---------- lazyGraph.mli => misc/lazyGraph.mli | 28 +++---- levenshtein.ml => misc/levenshtein.ml | 0 levenshtein.mli => misc/levenshtein.mli | 0 pHashtbl.ml => misc/pHashtbl.ml | 6 +- pHashtbl.mli => misc/pHashtbl.mli | 6 +- persistentGraph.ml => misc/persistentGraph.ml | 42 +++++----- .../persistentGraph.mli | 20 ++--- piCalculus.ml => misc/piCalculus.ml | 0 piCalculus.mli => misc/piCalculus.mli | 0 puf.ml => misc/puf.ml | 0 puf.mli => misc/puf.mli | 0 qCheck.ml => misc/qCheck.ml | 0 qCheck.mli => misc/qCheck.mli | 4 +- ratTerm.ml => misc/ratTerm.ml | 0 ratTerm.mli => misc/ratTerm.mli | 0 sexp.ml => misc/sexp.ml | 0 sexp.mli => misc/sexp.mli | 0 skipList.ml => misc/skipList.ml | 2 +- skipList.mli => misc/skipList.mli | 4 +- smallSet.ml => misc/smallSet.ml | 6 +- smallSet.mli => misc/smallSet.mli | 4 +- splayMap.ml => misc/splayMap.ml | 12 +-- splayMap.mli => misc/splayMap.mli | 8 +- splayTree.ml => misc/splayTree.ml | 0 splayTree.mli => misc/splayTree.mli | 0 tTree.ml => misc/tTree.ml | 0 tTree.mli => misc/tTree.mli | 0 tell.ml => misc/tell.ml | 0 tell.mli => misc/tell.mli | 0 ty.ml => misc/ty.ml | 0 ty.mli => misc/ty.mli | 0 unionFind.ml => misc/unionFind.ml | 0 unionFind.mli => misc/unionFind.mli | 0 univ.ml => misc/univ.ml | 0 univ.mli => misc/univ.mli | 0 utils.ml => misc/utils.ml | 0 tests/bench_conv.ml | 4 +- tests/benchs.ml | 10 +-- 115 files changed, 278 insertions(+), 247 deletions(-) delete mode 100644 containers.mldylib delete mode 100644 containers_lwt.mldylib rename BV.ml => core/CCBV.ml (100%) rename BV.mli => core/CCBV.mli (100%) rename deque.ml => core/CCDeque.ml (97%) rename deque.mli => core/CCDeque.mli (94%) rename fQueue.ml => core/CCFQueue.ml (95%) rename fQueue.mli => core/CCFQueue.mli (95%) rename gen.ml => core/CCGen.ml (100%) rename gen.mli => core/CCGen.mli (100%) rename KMP.ml => core/CCKMP.ml (100%) rename KMP.mli => core/CCKMP.mli (100%) rename leftistheap.ml => core/CCLeftistheap.ml (96%) rename leftistheap.mli => core/CCLeftistheap.mli (95%) rename multiMap.ml => core/CCMultiMap.ml (91%) rename multiMap.mli => core/CCMultiMap.mli (92%) rename multiSet.ml => core/CCMultiSet.ml (100%) rename multiSet.mli => core/CCMultiSet.mli (100%) rename persistentHashtbl.ml => core/CCPersistentHashtbl.ml (96%) rename persistentHashtbl.mli => core/CCPersistentHashtbl.mli (95%) rename show.ml => core/CCPrint.ml (100%) rename show.mli => core/CCPrint.mli (100%) rename sequence.ml => core/CCSequence.ml (100%) rename sequence.mli => core/CCSequence.mli (100%) rename vector.ml => core/CCVector.ml (95%) rename vector.mli => core/CCVector.mli (94%) delete mode 100644 lwt_containers.mllib delete mode 100644 lwt_containers.odocl rename CSM.ml => misc/CSM.ml (99%) rename CSM.mli => misc/CSM.mli (99%) rename RAL.ml => misc/RAL.ml (100%) rename RAL.mli => misc/RAL.mli (100%) rename absSet.ml => misc/absSet.ml (96%) rename absSet.mli => misc/absSet.mli (92%) rename actionMan.ml => misc/actionMan.ml (100%) rename actionMan.mli => misc/actionMan.mli (98%) rename automaton.ml => misc/automaton.ml (100%) rename automaton.mli => misc/automaton.mli (100%) rename bencode.ml => misc/bencode.ml (100%) rename bencode.mli => misc/bencode.mli (100%) rename bencodeOnDisk.ml => misc/bencodeOnDisk.ml (100%) rename bencodeOnDisk.mli => misc/bencodeOnDisk.mli (100%) rename bencodeStream.ml => misc/bencodeStream.ml (100%) rename bencodeStream.mli => misc/bencodeStream.mli (100%) rename bencode_write_par.sh => misc/bencode_write_par.sh (100%) rename bidir.ml => misc/bidir.ml (100%) rename bidir.mli => misc/bidir.mli (100%) rename bij.ml => misc/bij.ml (100%) rename bij.mli => misc/bij.mli (100%) rename cC.ml => misc/cC.ml (99%) rename cC.mli => misc/cC.mli (100%) rename cache.ml => misc/cache.ml (100%) rename cache.mli => misc/cache.mli (100%) rename cause.ml => misc/cause.ml (100%) rename cause.mli => misc/cause.mli (100%) rename circList.ml => misc/circList.ml (98%) rename circList.mli => misc/circList.mli (97%) rename conv.ml => misc/conv.ml (100%) rename conv.mli => misc/conv.mli (100%) rename fHashtbl.ml => misc/fHashtbl.ml (98%) rename fHashtbl.mli => misc/fHashtbl.mli (96%) rename flatHashtbl.ml => misc/flatHashtbl.ml (97%) rename flatHashtbl.mli => misc/flatHashtbl.mli (96%) rename hGraph.ml => misc/hGraph.ml (99%) rename hGraph.mli => misc/hGraph.mli (98%) rename hashset.ml => misc/hashset.ml (93%) rename hashset.mli => misc/hashset.mli (96%) rename heap.ml => misc/heap.ml (100%) rename heap.mli => misc/heap.mli (96%) rename iteratee.ml => misc/iteratee.ml (100%) rename iteratee.mli => misc/iteratee.mli (100%) rename json.ml => misc/json.ml (100%) rename json.mli => misc/json.mli (100%) rename lazyGraph.ml => misc/lazyGraph.ml (90%) rename lazyGraph.mli => misc/lazyGraph.mli (92%) rename levenshtein.ml => misc/levenshtein.ml (100%) rename levenshtein.mli => misc/levenshtein.mli (100%) rename pHashtbl.ml => misc/pHashtbl.ml (98%) rename pHashtbl.mli => misc/pHashtbl.mli (96%) rename persistentGraph.ml => misc/persistentGraph.ml (91%) rename persistentGraph.mli => misc/persistentGraph.mli (90%) rename piCalculus.ml => misc/piCalculus.ml (100%) rename piCalculus.mli => misc/piCalculus.mli (100%) rename puf.ml => misc/puf.ml (100%) rename puf.mli => misc/puf.mli (100%) rename qCheck.ml => misc/qCheck.ml (100%) rename qCheck.mli => misc/qCheck.mli (98%) rename ratTerm.ml => misc/ratTerm.ml (100%) rename ratTerm.mli => misc/ratTerm.mli (100%) rename sexp.ml => misc/sexp.ml (100%) rename sexp.mli => misc/sexp.mli (100%) rename skipList.ml => misc/skipList.ml (99%) rename skipList.mli => misc/skipList.mli (95%) rename smallSet.ml => misc/smallSet.ml (97%) rename smallSet.mli => misc/smallSet.mli (96%) rename splayMap.ml => misc/splayMap.ml (97%) rename splayMap.mli => misc/splayMap.mli (94%) rename splayTree.ml => misc/splayTree.ml (100%) rename splayTree.mli => misc/splayTree.mli (100%) rename tTree.ml => misc/tTree.ml (100%) rename tTree.mli => misc/tTree.mli (100%) rename tell.ml => misc/tell.ml (100%) rename tell.mli => misc/tell.mli (100%) rename ty.ml => misc/ty.ml (100%) rename ty.mli => misc/ty.mli (100%) rename unionFind.ml => misc/unionFind.ml (100%) rename unionFind.mli => misc/unionFind.mli (100%) rename univ.ml => misc/univ.ml (100%) rename univ.mli => misc/univ.mli (100%) rename utils.ml => misc/utils.ml (100%) diff --git a/.merlin b/.merlin index fda86d2d..32ccdcde 100644 --- a/.merlin +++ b/.merlin @@ -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 diff --git a/Makefile b/Makefile index 0682b144..90956761 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/_oasis b/_oasis index 5b77c17c..53e94cf9 100644 --- a/_oasis +++ b/_oasis @@ -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/ diff --git a/containers.mldylib b/containers.mldylib deleted file mode 100644 index 24364220..00000000 --- a/containers.mldylib +++ /dev/null @@ -1,4 +0,0 @@ -# OASIS_START -# DO NOT EDIT (digest: 5382aaf8b3d2fdeb6717f9805b0dd511) -Containers -# OASIS_STOP diff --git a/containers_lwt.mldylib b/containers_lwt.mldylib deleted file mode 100644 index 2cafc3b9..00000000 --- a/containers_lwt.mldylib +++ /dev/null @@ -1,4 +0,0 @@ -# OASIS_START -# DO NOT EDIT (digest: bc144ef7b5b54947fab9662a822f9179) -Containers_lwt -# OASIS_STOP diff --git a/BV.ml b/core/CCBV.ml similarity index 100% rename from BV.ml rename to core/CCBV.ml diff --git a/BV.mli b/core/CCBV.mli similarity index 100% rename from BV.mli rename to core/CCBV.mli diff --git a/deque.ml b/core/CCDeque.ml similarity index 97% rename from deque.ml rename to core/CCDeque.ml index 4003515d..cc83f425 100644 --- a/deque.ml +++ b/core/CCDeque.ml @@ -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 = diff --git a/deque.mli b/core/CCDeque.mli similarity index 94% rename from deque.mli rename to core/CCDeque.mli index 0ce7128d..046e7148 100644 --- a/deque.mli +++ b/core/CCDeque.mli @@ -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 *) diff --git a/fQueue.ml b/core/CCFQueue.ml similarity index 95% rename from fQueue.ml rename to core/CCFQueue.ml index 85bb177a..1e76711b 100644 --- a/fQueue.ml +++ b/core/CCFQueue.ml @@ -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 diff --git a/fQueue.mli b/core/CCFQueue.mli similarity index 95% rename from fQueue.mli rename to core/CCFQueue.mli index 6ed53d4f..84fbd068 100644 --- a/fQueue.mli +++ b/core/CCFQueue.mli @@ -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 diff --git a/gen.ml b/core/CCGen.ml similarity index 100% rename from gen.ml rename to core/CCGen.ml diff --git a/gen.mli b/core/CCGen.mli similarity index 100% rename from gen.mli rename to core/CCGen.mli diff --git a/KMP.ml b/core/CCKMP.ml similarity index 100% rename from KMP.ml rename to core/CCKMP.ml diff --git a/KMP.mli b/core/CCKMP.mli similarity index 100% rename from KMP.mli rename to core/CCKMP.mli diff --git a/leftistheap.ml b/core/CCLeftistheap.ml similarity index 96% rename from leftistheap.ml rename to core/CCLeftistheap.ml index 046079ba..5c6f9def 100644 --- a/leftistheap.ml +++ b/core/CCLeftistheap.ml @@ -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 diff --git a/leftistheap.mli b/core/CCLeftistheap.mli similarity index 95% rename from leftistheap.mli rename to core/CCLeftistheap.mli index a047e0bc..701df006 100644 --- a/leftistheap.mli +++ b/core/CCLeftistheap.mli @@ -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 diff --git a/multiMap.ml b/core/CCMultiMap.ml similarity index 91% rename from multiMap.ml rename to core/CCMultiMap.ml index d0f49cd0..3eedb5f7 100644 --- a/multiMap.ml +++ b/core/CCMultiMap.ml @@ -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 diff --git a/multiMap.mli b/core/CCMultiMap.mli similarity index 92% rename from multiMap.mli rename to core/CCMultiMap.mli index 5da8020f..8d6e9e71 100644 --- a/multiMap.mli +++ b/core/CCMultiMap.mli @@ -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 diff --git a/multiSet.ml b/core/CCMultiSet.ml similarity index 100% rename from multiSet.ml rename to core/CCMultiSet.ml diff --git a/multiSet.mli b/core/CCMultiSet.mli similarity index 100% rename from multiSet.mli rename to core/CCMultiSet.mli diff --git a/persistentHashtbl.ml b/core/CCPersistentHashtbl.ml similarity index 96% rename from persistentHashtbl.ml rename to core/CCPersistentHashtbl.ml index 51952ce5..2f613783 100644 --- a/persistentHashtbl.ml +++ b/core/CCPersistentHashtbl.ml @@ -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 diff --git a/persistentHashtbl.mli b/core/CCPersistentHashtbl.mli similarity index 95% rename from persistentHashtbl.mli rename to core/CCPersistentHashtbl.mli index 77bc1049..6de2760b 100644 --- a/persistentHashtbl.mli +++ b/core/CCPersistentHashtbl.mli @@ -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 diff --git a/show.ml b/core/CCPrint.ml similarity index 100% rename from show.ml rename to core/CCPrint.ml diff --git a/show.mli b/core/CCPrint.mli similarity index 100% rename from show.mli rename to core/CCPrint.mli diff --git a/sequence.ml b/core/CCSequence.ml similarity index 100% rename from sequence.ml rename to core/CCSequence.ml diff --git a/sequence.mli b/core/CCSequence.mli similarity index 100% rename from sequence.mli rename to core/CCSequence.mli diff --git a/vector.ml b/core/CCVector.ml similarity index 95% rename from vector.ml rename to core/CCVector.ml index 8d9060a2..283f293a 100644 --- a/vector.ml +++ b/core/CCVector.ml @@ -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 diff --git a/vector.mli b/core/CCVector.mli similarity index 94% rename from vector.mli rename to core/CCVector.mli index 4205e5b1..6e973da7 100644 --- a/vector.mli +++ b/core/CCVector.mli @@ -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. *) diff --git a/lwt_containers.mllib b/lwt_containers.mllib deleted file mode 100644 index c0cedf8a..00000000 --- a/lwt_containers.mllib +++ /dev/null @@ -1 +0,0 @@ -Behavior diff --git a/lwt_containers.odocl b/lwt_containers.odocl deleted file mode 100644 index c0cedf8a..00000000 --- a/lwt_containers.odocl +++ /dev/null @@ -1 +0,0 @@ -Behavior diff --git a/CSM.ml b/misc/CSM.ml similarity index 99% rename from CSM.ml rename to misc/CSM.ml index 4c1066b1..158f5b3a 100644 --- a/CSM.ml +++ b/misc/CSM.ml @@ -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 diff --git a/CSM.mli b/misc/CSM.mli similarity index 99% rename from CSM.mli rename to misc/CSM.mli index 9ac70d80..abd59af1 100644 --- a/CSM.mli +++ b/misc/CSM.mli @@ -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 diff --git a/RAL.ml b/misc/RAL.ml similarity index 100% rename from RAL.ml rename to misc/RAL.ml diff --git a/RAL.mli b/misc/RAL.mli similarity index 100% rename from RAL.mli rename to misc/RAL.mli diff --git a/absSet.ml b/misc/absSet.ml similarity index 96% rename from absSet.ml rename to misc/absSet.ml index 9ee90fbf..c8cbb06c 100644 --- a/absSet.ml +++ b/misc/absSet.ml @@ -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 = diff --git a/absSet.mli b/misc/absSet.mli similarity index 92% rename from absSet.mli rename to misc/absSet.mli index 1ce06212..4bcec095 100644 --- a/absSet.mli +++ b/misc/absSet.mli @@ -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 diff --git a/actionMan.ml b/misc/actionMan.ml similarity index 100% rename from actionMan.ml rename to misc/actionMan.ml diff --git a/actionMan.mli b/misc/actionMan.mli similarity index 98% rename from actionMan.mli rename to misc/actionMan.mli index 96da4766..bcced976 100644 --- a/actionMan.mli +++ b/misc/actionMan.mli @@ -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 *) diff --git a/automaton.ml b/misc/automaton.ml similarity index 100% rename from automaton.ml rename to misc/automaton.ml diff --git a/automaton.mli b/misc/automaton.mli similarity index 100% rename from automaton.mli rename to misc/automaton.mli diff --git a/bencode.ml b/misc/bencode.ml similarity index 100% rename from bencode.ml rename to misc/bencode.ml diff --git a/bencode.mli b/misc/bencode.mli similarity index 100% rename from bencode.mli rename to misc/bencode.mli diff --git a/bencodeOnDisk.ml b/misc/bencodeOnDisk.ml similarity index 100% rename from bencodeOnDisk.ml rename to misc/bencodeOnDisk.ml diff --git a/bencodeOnDisk.mli b/misc/bencodeOnDisk.mli similarity index 100% rename from bencodeOnDisk.mli rename to misc/bencodeOnDisk.mli diff --git a/bencodeStream.ml b/misc/bencodeStream.ml similarity index 100% rename from bencodeStream.ml rename to misc/bencodeStream.ml diff --git a/bencodeStream.mli b/misc/bencodeStream.mli similarity index 100% rename from bencodeStream.mli rename to misc/bencodeStream.mli diff --git a/bencode_write_par.sh b/misc/bencode_write_par.sh similarity index 100% rename from bencode_write_par.sh rename to misc/bencode_write_par.sh diff --git a/bidir.ml b/misc/bidir.ml similarity index 100% rename from bidir.ml rename to misc/bidir.ml diff --git a/bidir.mli b/misc/bidir.mli similarity index 100% rename from bidir.mli rename to misc/bidir.mli diff --git a/bij.ml b/misc/bij.ml similarity index 100% rename from bij.ml rename to misc/bij.ml diff --git a/bij.mli b/misc/bij.mli similarity index 100% rename from bij.mli rename to misc/bij.mli diff --git a/cC.ml b/misc/cC.ml similarity index 99% rename from cC.ml rename to misc/cC.ml index f7b6e005..c1273eef 100644 --- a/cC.ml +++ b/misc/cC.ml @@ -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 diff --git a/cC.mli b/misc/cC.mli similarity index 100% rename from cC.mli rename to misc/cC.mli diff --git a/cache.ml b/misc/cache.ml similarity index 100% rename from cache.ml rename to misc/cache.ml diff --git a/cache.mli b/misc/cache.mli similarity index 100% rename from cache.mli rename to misc/cache.mli diff --git a/cause.ml b/misc/cause.ml similarity index 100% rename from cause.ml rename to misc/cause.ml diff --git a/cause.mli b/misc/cause.mli similarity index 100% rename from cause.mli rename to misc/cause.mli diff --git a/circList.ml b/misc/circList.ml similarity index 98% rename from circList.ml rename to misc/circList.ml index 0b0670be..9c795a98 100644 --- a/circList.ml +++ b/misc/circList.ml @@ -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 = diff --git a/circList.mli b/misc/circList.mli similarity index 97% rename from circList.mli rename to misc/circList.mli index 9638e616..5c982a5b 100644 --- a/circList.mli +++ b/misc/circList.mli @@ -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 *) diff --git a/conv.ml b/misc/conv.ml similarity index 100% rename from conv.ml rename to misc/conv.ml diff --git a/conv.mli b/misc/conv.mli similarity index 100% rename from conv.mli rename to misc/conv.mli diff --git a/fHashtbl.ml b/misc/fHashtbl.ml similarity index 98% rename from fHashtbl.ml rename to misc/fHashtbl.ml index 56610856..50e4c8a7 100644 --- a/fHashtbl.ml +++ b/misc/fHashtbl.ml @@ -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 diff --git a/fHashtbl.mli b/misc/fHashtbl.mli similarity index 96% rename from fHashtbl.mli rename to misc/fHashtbl.mli index f90e4aa7..9bb7ca4f 100644 --- a/fHashtbl.mli +++ b/misc/fHashtbl.mli @@ -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} *) diff --git a/flatHashtbl.ml b/misc/flatHashtbl.ml similarity index 97% rename from flatHashtbl.ml rename to misc/flatHashtbl.ml index 04218489..b2e2ce8d 100644 --- a/flatHashtbl.ml +++ b/misc/flatHashtbl.ml @@ -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) diff --git a/flatHashtbl.mli b/misc/flatHashtbl.mli similarity index 96% rename from flatHashtbl.mli rename to misc/flatHashtbl.mli index 16c560a3..44f2c1f4 100644 --- a/flatHashtbl.mli +++ b/misc/flatHashtbl.mli @@ -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 *) diff --git a/hGraph.ml b/misc/hGraph.ml similarity index 99% rename from hGraph.ml rename to misc/hGraph.ml index 8861d823..9abfaab3 100644 --- a/hGraph.ml +++ b/misc/hGraph.ml @@ -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. *) diff --git a/hGraph.mli b/misc/hGraph.mli similarity index 98% rename from hGraph.mli rename to misc/hGraph.mli index d324dcdf..a182a93d 100644 --- a/hGraph.mli +++ b/misc/hGraph.mli @@ -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 diff --git a/hashset.ml b/misc/hashset.ml similarity index 93% rename from hashset.ml rename to misc/hashset.ml index e7dd8b8d..5ff54bfe 100644 --- a/hashset.ml +++ b/misc/hashset.ml @@ -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 diff --git a/hashset.mli b/misc/hashset.mli similarity index 96% rename from hashset.mli rename to misc/hashset.mli index 77c2845d..92af637f 100644 --- a/hashset.mli +++ b/misc/hashset.mli @@ -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] *) diff --git a/heap.ml b/misc/heap.ml similarity index 100% rename from heap.ml rename to misc/heap.ml diff --git a/heap.mli b/misc/heap.mli similarity index 96% rename from heap.mli rename to misc/heap.mli index 24db4b77..ba901f98 100644 --- a/heap.mli +++ b/misc/heap.mli @@ -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 diff --git a/iteratee.ml b/misc/iteratee.ml similarity index 100% rename from iteratee.ml rename to misc/iteratee.ml diff --git a/iteratee.mli b/misc/iteratee.mli similarity index 100% rename from iteratee.mli rename to misc/iteratee.mli diff --git a/json.ml b/misc/json.ml similarity index 100% rename from json.ml rename to misc/json.ml diff --git a/json.mli b/misc/json.mli similarity index 100% rename from json.mli rename to misc/json.mli diff --git a/lazyGraph.ml b/misc/lazyGraph.ml similarity index 90% rename from lazyGraph.ml rename to misc/lazyGraph.ml index 989ada76..02201ad4 100644 --- a/lazyGraph.ml +++ b/misc/lazyGraph.ml @@ -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 "@[digraph %s {@;" name; (* traverse *) - Sequence.iter + CCSequence.iter (function | Full.EnterVertex (v, attrs, _, _) -> Format.fprintf formatter " @[%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 " @[%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 diff --git a/lazyGraph.mli b/misc/lazyGraph.mli similarity index 92% rename from lazyGraph.mli rename to misc/lazyGraph.mli index de109d89..1b33d983 100644 --- a/lazyGraph.mli +++ b/misc/lazyGraph.mli @@ -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 diff --git a/levenshtein.ml b/misc/levenshtein.ml similarity index 100% rename from levenshtein.ml rename to misc/levenshtein.ml diff --git a/levenshtein.mli b/misc/levenshtein.mli similarity index 100% rename from levenshtein.mli rename to misc/levenshtein.mli diff --git a/pHashtbl.ml b/misc/pHashtbl.ml similarity index 98% rename from pHashtbl.ml rename to misc/pHashtbl.ml index bbb3b30b..fc138ecf 100644 --- a/pHashtbl.ml +++ b/misc/pHashtbl.ml @@ -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 *) diff --git a/pHashtbl.mli b/misc/pHashtbl.mli similarity index 96% rename from pHashtbl.mli rename to misc/pHashtbl.mli index 4fc53cb2..d5d8bd54 100644 --- a/pHashtbl.mli +++ b/misc/pHashtbl.mli @@ -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 *) diff --git a/persistentGraph.ml b/misc/persistentGraph.ml similarity index 91% rename from persistentGraph.ml rename to misc/persistentGraph.ml index 8788a220..cd23cab1 100644 --- a/persistentGraph.ml +++ b/misc/persistentGraph.ml @@ -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 "@[digraph %s {@;" name; (* print edges *) - Sequence.iter + CCSequence.iter (fun (v1, e, v2) -> let attributes = print_edge v1 e v2 in Format.fprintf formatter " @[%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 " @[%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 "}@]@;"; diff --git a/persistentGraph.mli b/misc/persistentGraph.mli similarity index 90% rename from persistentGraph.mli rename to misc/persistentGraph.mli index 6ca542bb..6c061706 100644 --- a/persistentGraph.mli +++ b/misc/persistentGraph.mli @@ -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 -> diff --git a/piCalculus.ml b/misc/piCalculus.ml similarity index 100% rename from piCalculus.ml rename to misc/piCalculus.ml diff --git a/piCalculus.mli b/misc/piCalculus.mli similarity index 100% rename from piCalculus.mli rename to misc/piCalculus.mli diff --git a/puf.ml b/misc/puf.ml similarity index 100% rename from puf.ml rename to misc/puf.ml diff --git a/puf.mli b/misc/puf.mli similarity index 100% rename from puf.mli rename to misc/puf.mli diff --git a/qCheck.ml b/misc/qCheck.ml similarity index 100% rename from qCheck.ml rename to misc/qCheck.ml diff --git a/qCheck.mli b/misc/qCheck.mli similarity index 98% rename from qCheck.mli rename to misc/qCheck.mli index 6b59f0a0..7c3c006e 100644 --- a/qCheck.mli +++ b/misc/qCheck.mli @@ -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} *) diff --git a/ratTerm.ml b/misc/ratTerm.ml similarity index 100% rename from ratTerm.ml rename to misc/ratTerm.ml diff --git a/ratTerm.mli b/misc/ratTerm.mli similarity index 100% rename from ratTerm.mli rename to misc/ratTerm.mli diff --git a/sexp.ml b/misc/sexp.ml similarity index 100% rename from sexp.ml rename to misc/sexp.ml diff --git a/sexp.mli b/misc/sexp.mli similarity index 100% rename from sexp.mli rename to misc/sexp.mli diff --git a/skipList.ml b/misc/skipList.ml similarity index 99% rename from skipList.ml rename to misc/skipList.ml index c38f5329..60db79a6 100644 --- a/skipList.ml +++ b/misc/skipList.ml @@ -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 diff --git a/skipList.mli b/misc/skipList.mli similarity index 95% rename from skipList.mli rename to misc/skipList.mli index 7437c975..42b357c9 100644 --- a/skipList.mli +++ b/misc/skipList.mli @@ -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 diff --git a/smallSet.ml b/misc/smallSet.ml similarity index 97% rename from smallSet.ml rename to misc/smallSet.ml index 6df3ae0f..24b5ae69 100644 --- a/smallSet.ml +++ b/misc/smallSet.ml @@ -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) diff --git a/smallSet.mli b/misc/smallSet.mli similarity index 96% rename from smallSet.mli rename to misc/smallSet.mli index 79a9239b..1582b5e8 100644 --- a/smallSet.mli +++ b/misc/smallSet.mli @@ -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 diff --git a/splayMap.ml b/misc/splayMap.ml similarity index 97% rename from splayMap.ml rename to misc/splayMap.ml index 457baf65..5e6465f9 100644 --- a/splayMap.ml +++ b/misc/splayMap.ml @@ -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 diff --git a/splayMap.mli b/misc/splayMap.mli similarity index 94% rename from splayMap.mli rename to misc/splayMap.mli index 90f5d181..8d591977 100644 --- a/splayMap.mli +++ b/misc/splayMap.mli @@ -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 diff --git a/splayTree.ml b/misc/splayTree.ml similarity index 100% rename from splayTree.ml rename to misc/splayTree.ml diff --git a/splayTree.mli b/misc/splayTree.mli similarity index 100% rename from splayTree.mli rename to misc/splayTree.mli diff --git a/tTree.ml b/misc/tTree.ml similarity index 100% rename from tTree.ml rename to misc/tTree.ml diff --git a/tTree.mli b/misc/tTree.mli similarity index 100% rename from tTree.mli rename to misc/tTree.mli diff --git a/tell.ml b/misc/tell.ml similarity index 100% rename from tell.ml rename to misc/tell.ml diff --git a/tell.mli b/misc/tell.mli similarity index 100% rename from tell.mli rename to misc/tell.mli diff --git a/ty.ml b/misc/ty.ml similarity index 100% rename from ty.ml rename to misc/ty.ml diff --git a/ty.mli b/misc/ty.mli similarity index 100% rename from ty.mli rename to misc/ty.mli diff --git a/unionFind.ml b/misc/unionFind.ml similarity index 100% rename from unionFind.ml rename to misc/unionFind.ml diff --git a/unionFind.mli b/misc/unionFind.mli similarity index 100% rename from unionFind.mli rename to misc/unionFind.mli diff --git a/univ.ml b/misc/univ.ml similarity index 100% rename from univ.ml rename to misc/univ.ml diff --git a/univ.mli b/misc/univ.mli similarity index 100% rename from univ.mli rename to misc/univ.mli diff --git a/utils.ml b/misc/utils.ml similarity index 100% rename from utils.ml rename to misc/utils.ml diff --git a/tests/bench_conv.ml b/tests/bench_conv.ml index 9c84daba..6f7d39bd 100644 --- a/tests/bench_conv.ml +++ b/tests/bench_conv.ml @@ -78,11 +78,11 @@ let () = Printf.printf "list of 5 elements...\n"; bench_list [1,2; 3,4; 5,6; 7,8; 9,10]; - let l = Gen.(1 -- 100 |> map (fun x->x,x) |> to_rev_list) in + let l = CCGen.(1 -- 100 |> map (fun x->x,x) |> to_rev_list) in Printf.printf "list of %d elements...\n" (List.length l); bench_list l; - let l = Gen.(repeat Point.p |> take 10 |> to_rev_list) in + let l = CCGen.(repeat Point.p |> take 10 |> to_rev_list) in Printf.printf "list of %d points...\n" (List.length l); bench_point_list l; diff --git a/tests/benchs.ml b/tests/benchs.ml index e48e160f..51f96ccf 100644 --- a/tests/benchs.ml +++ b/tests/benchs.ml @@ -20,7 +20,7 @@ module IFHashtbl = FHashtbl.Tree(struct let hash i = i end) -module IPersistentHashtbl = PersistentHashtbl.Make(struct +module IPersistentHashtbl = CCPersistentHashtbl.Make(struct type t = int let equal i j = i = j let hash i = i @@ -290,8 +290,8 @@ let bench_maps() = let bench_enum () = let n = 1_000_000 in - let seq () = Sequence.fold (+) 0 (Sequence.int_range ~start:0 ~stop:n) in - let enum () = Gen.fold (+) 0 (Gen.int_range 0 n) in + let seq () = CCSequence.fold (+) 0 (CCSequence.int_range ~start:0 ~stop:n) in + let enum () = CCGen.fold (+) 0 (CCGen.int_range 0 n) in Bench.bench [ "sequence.fold", seq; "gen.fold", enum; @@ -299,12 +299,12 @@ let bench_enum () = let n = 100_000 in let seq () = - let open Sequence in + let open CCSequence in let seq = int_range ~start:0 ~stop:n in let seq = flatMap (fun x -> int_range ~start:x ~stop:(x+10)) seq in fold (+) 0 seq in let enum () = - let open Gen in + let open CCGen in let seq = int_range 0 n in let seq = flatMap (fun x -> int_range x (x+10)) seq in fold (+) 0 seq in