diff --git a/CHANGELOG.md b/CHANGELOG.md index 22355ab8..87f5dcbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,28 @@ # Changelog +## 0.8 + +- add `@Emm` to authors +- refactored heavily `CCFuture` (much simpler, cleaner, basic API and thread pool) +- add `CCLock` in containers.thread +- merged `test_levenshtein` with other tests +- Add experimental rose tree in `Containers_misc.RoseTree`. +- remove a lot of stuff from `containers.misc` (see `_oasis` for details) +- `make devel` command, activating most flags, for developpers (see #27) +- use benchmark 1.4, with the upstreamed tree system +- test `ccvector.iteri` +- add `CCFormat` into core/ +- infix map operators for `CCArray` +- `fold_while` impl for `CCList` and `CCArray` +- Added `CCBigstring.length` for more consistency with the `CCString` module. +- Added name and dev fields in the OPAM file for local pinning. +- Fix `CCIO.remove*` functions. +- Added `CCIO.remove_safe`. +- only build doc if all the required flags are enabled +- `CCHashtbl.{keys,values}_list` in the functor as well. Better doc. +- `CCHashtbl.{keys,values}_list` +- more accurate type for `CCHashtbl.Make` + ## 0.7 ### breaking diff --git a/README.md b/README.md index 21d7cd5c..bb8bcd40 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,7 @@ is not necessarily up-to-date. - `AbsSet`, an abstract Set data structure, a bit like `LazyGraph`. - `Automaton`, `CSM`, state machine abstractions - `Bij`, a GADT-based bijection language used to serialize/deserialize your data structures +- `Hashset`, a polymorphic imperative set on top of `PHashtbl` - `LazyGraph`, a lazy graph structure on arbitrary (hashable+eq) types, with basic graph functions that work even on infinite graphs, and printing to DOT. - `PHashtbl`, a polymorphic hashtable (with open addressing) - `RAL`, a random-access list structure, with `O(1)` cons/hd/tl and `O(ln(n))` access to elements by their index. diff --git a/_oasis b/_oasis index 112908ed..b348e689 100644 --- a/_oasis +++ b/_oasis @@ -1,6 +1,6 @@ OASISFormat: 0.4 Name: containers -Version: 0.7 +Version: 0.8 Homepage: https://github.com/c-cube/ocaml-containers Authors: Simon Cruanes License: BSD-2-clause @@ -113,7 +113,7 @@ Library "containers_pervasives" Library "containers_misc" Path: src/misc Pack: true - Modules: AbsSet, Automaton, Bij, CSM, LazyGraph, PHashtbl, + Modules: AbsSet, Automaton, Bij, CSM, Hashset, LazyGraph, PHashtbl, PrintBox, RAL, RoseTree, SmallSet, UnionFind, Univ BuildDepends: containers, containers.data FindlibName: misc diff --git a/doc/intro.txt b/doc/intro.txt index ff7c5e99..edbad184 100644 --- a/doc/intro.txt +++ b/doc/intro.txt @@ -118,6 +118,7 @@ AbsSet Automaton Bij CSM +Hashset LazyGraph PHashtbl PrintBox diff --git a/src/bigarray/CCBigstring.mli b/src/bigarray/CCBigstring.mli index 33970486..dbd6ebc9 100644 --- a/src/bigarray/CCBigstring.mli +++ b/src/bigarray/CCBigstring.mli @@ -47,7 +47,7 @@ val size : t -> int val length : t -> int (** Alias for [size]. - @since NEXT_RELEASE *) + @since 0.8 *) val get : t -> int -> char diff --git a/src/core/CCArray.ml b/src/core/CCArray.ml index e4e10882..faeb7a4c 100644 --- a/src/core/CCArray.ml +++ b/src/core/CCArray.ml @@ -56,7 +56,7 @@ module type S = sig val fold_while : ('a -> 'b -> 'a * [`Stop | `Continue]) -> 'a -> 'b t -> 'a (** fold left on array until a stop condition via [('a, `Stop)] is indicated by the accumulator - @since NEXT_RELEASE *) + @since 0.8 *) val iter : ('a -> unit) -> 'a t -> unit diff --git a/src/core/CCArray.mli b/src/core/CCArray.mli index 1a5c26a4..403578e6 100644 --- a/src/core/CCArray.mli +++ b/src/core/CCArray.mli @@ -58,7 +58,7 @@ module type S = sig val fold_while : ('a -> 'b -> 'a * [`Stop | `Continue]) -> 'a -> 'b t -> 'a (** Fold left on array until a stop condition via [('a, `Stop)] is indicated by the accumulator - @since NEXT_RELEASE *) + @since 0.8 *) val iter : ('a -> unit) -> 'a t -> unit @@ -157,11 +157,11 @@ val (>>=) : 'a t -> ('a -> 'b t) -> 'b t val (>>|) : 'a t -> ('a -> 'b) -> 'b t (** Infix version of {!map} - @since NEXT_RELEASE *) + @since 0.8 *) val (>|=) : 'a t -> ('a -> 'b) -> 'b t (** Infix version of {!map} - @since NEXT_RELEASE *) + @since 0.8 *) val except_idx : 'a t -> int -> 'a list (** Remove given index, obtaining the list of the other elements *) diff --git a/src/core/CCFormat.mli b/src/core/CCFormat.mli index d8c06657..6a4c46f6 100644 --- a/src/core/CCFormat.mli +++ b/src/core/CCFormat.mli @@ -26,7 +26,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. (** {1 Helpers for Format} -@since NEXT_RELEASE *) +@since 0.8 *) type 'a sequence = ('a -> unit) -> unit diff --git a/src/core/CCHashtbl.ml b/src/core/CCHashtbl.ml index 580e6f29..19ade6b6 100644 --- a/src/core/CCHashtbl.ml +++ b/src/core/CCHashtbl.ml @@ -86,11 +86,11 @@ module type S = sig val keys_list : ('a, 'b) Hashtbl.t -> 'a list (** [keys t] is the list of keys in [t]. - @since NEXT_RELEASE *) + @since 0.8 *) val values_list : ('a, 'b) Hashtbl.t -> 'b list (** [values t] is the list of values in [t]. - @since NEXT_RELEASE *) + @since 0.8 *) val map_list : (key -> 'a -> 'b) -> 'a t -> 'b list (** Map on a hashtable's items, collect into a list *) diff --git a/src/core/CCHashtbl.mli b/src/core/CCHashtbl.mli index b862bcad..554196ca 100644 --- a/src/core/CCHashtbl.mli +++ b/src/core/CCHashtbl.mli @@ -46,11 +46,11 @@ val values : ('a,'b) Hashtbl.t -> 'b sequence val keys_list : ('a, 'b) Hashtbl.t -> 'a list (** [keys t] is the list of keys in [t]. - @since NEXT_RELEASE *) + @since 0.8 *) val values_list : ('a, 'b) Hashtbl.t -> 'b list (** [values t] is the list of values in [t]. - @since NEXT_RELEASE *) + @since 0.8 *) val map_list : ('a -> 'b -> 'c) -> ('a, 'b) Hashtbl.t -> 'c list (** Map on a hashtable's items, collect into a list *) @@ -83,11 +83,11 @@ module type S = sig val keys_list : ('a, 'b) Hashtbl.t -> 'a list (** [keys t] is the list of keys in [t]. - @since NEXT_RELEASE *) + @since 0.8 *) val values_list : ('a, 'b) Hashtbl.t -> 'b list (** [values t] is the list of values in [t]. - @since NEXT_RELEASE *) + @since 0.8 *) val map_list : (key -> 'a -> 'b) -> 'a t -> 'b list (** Map on a hashtable's items, collect into a list *) diff --git a/src/core/CCList.mli b/src/core/CCList.mli index 8400351a..57a2944d 100644 --- a/src/core/CCList.mli +++ b/src/core/CCList.mli @@ -51,7 +51,7 @@ val fold_right : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'b val fold_while : ('a -> 'b -> 'a * [`Stop | `Continue]) -> 'a -> 'b t -> 'a (** Fold until a stop condition via [('a, `Stop)] is indicated by the accumulator - @since NEXT_RELEASE *) + @since 0.8 *) val init : int -> (int -> 'a) -> 'a t (** Same as [Array.init] diff --git a/src/io/CCIO.mli b/src/io/CCIO.mli index a7e43112..e338ef16 100644 --- a/src/io/CCIO.mli +++ b/src/io/CCIO.mli @@ -152,15 +152,15 @@ module File : sig file system. {b Raises} [Sys_error] if there is no file at [path]. - @since NEXT_RELEASE *) + @since 0.8 *) val remove : t -> unit or_error (** Like [remove_exn] but with an error monad. - @since NEXT_RELEASE *) + @since 0.8 *) val remove_noerr : t -> unit (** Like [remove_exn] but do not raise any exception on failure. - @since NEXT_RELEASE *) + @since 0.8 *) val read_dir : ?recurse:bool -> t -> t gen (** [read_dir d] returns a sequence of files and directory contained diff --git a/src/misc/hashset.ml b/src/misc/hashset.ml new file mode 100644 index 00000000..110e4994 --- /dev/null +++ b/src/misc/hashset.ml @@ -0,0 +1,75 @@ +(* +Copyright (c) 2013, Simon Cruanes +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions and the +following disclaimer in the documentation and/or other materials provided with +the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +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. +*) + +(** {1 Mutable polymorphic hash-set} *) + +type 'a sequence = ('a -> unit) -> unit + +type 'a t = ('a, unit) PHashtbl.t + (** A set is a hashtable, with trivial values *) + +let empty ?max_load ?eq ?hash size = + PHashtbl.create ?max_load ?eq ?hash size + +let copy set = PHashtbl.copy set + +let clear set = PHashtbl.clear set + +let cardinal set = PHashtbl.length set + +let mem set x = PHashtbl.mem set x + +let add set x = PHashtbl.add set x () + +let remove set x = PHashtbl.remove set x + +let iter f set = PHashtbl.iter (fun x () -> f x) set + +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 k = iter k set + +let of_seq set seq = + seq (fun x -> add set x) + +let union ?into (s1 : 'a t) (s2 : 'a t) = + let into = match into with + | Some s -> of_seq s (to_seq s1); s + | None -> copy s1 in + of_seq into (to_seq s2); + into + +let seq_filter p seq k = + seq (fun x -> if p x then k x) + +let inter ?into (s1 : 'a t) (s2 : 'a t) = + let into = match into with + | 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 (seq_filter (fun x -> mem s2 x) (to_seq s1)); + into diff --git a/src/misc/hashset.mli b/src/misc/hashset.mli new file mode 100644 index 00000000..f421c557 --- /dev/null +++ b/src/misc/hashset.mli @@ -0,0 +1,64 @@ +(* +Copyright (c) 2013, Simon Cruanes +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. Redistributions in binary +form must reproduce the above copyright notice, this list of conditions and the +following disclaimer in the documentation and/or other materials provided with +the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +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. +*) + +(** {1 Mutable polymorphic hash-set} *) + +type 'a sequence = ('a -> unit) -> unit + +type 'a t = ('a, unit) PHashtbl.t + (** A set is a hashtable, with trivial values *) + +val empty : ?max_load:float -> ?eq:('a -> 'a -> bool) -> + ?hash:('a -> int) -> int -> 'a t + (** See {!PHashtbl.create} *) + +val copy : 'a t -> 'a t + +val clear : 'a t -> unit + +val cardinal : 'a t -> int + +val mem : 'a t -> 'a -> bool + +val add : 'a t -> 'a -> unit + +val remove : 'a t -> 'a -> unit + +val iter : ('a -> unit) -> 'a t -> unit + +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 + +val of_seq : 'a t -> 'a sequence -> unit + +val union : ?into:'a t -> 'a t -> 'a t -> 'a t + (** Set union. The result is stored in [into] *) + +val inter : ?into:'a t -> 'a t -> 'a t -> 'a t + (** Set intersection. The result is stored in [into] *) diff --git a/src/misc/roseTree.mli b/src/misc/roseTree.mli index 00773464..cbaf42bb 100644 --- a/src/misc/roseTree.mli +++ b/src/misc/roseTree.mli @@ -29,7 +29,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. A persistent, non-lazy tree where each node may have an arbitrary number of children. - @since NEXT_RELEASE *) + @since 0.8 *) (** The type of a tree node - a (value, children) pair. *) type +'a t = [`Node of 'a * 'a t list] diff --git a/src/threads/CCLock.mli b/src/threads/CCLock.mli index 33840712..cfb05eb4 100644 --- a/src/threads/CCLock.mli +++ b/src/threads/CCLock.mli @@ -27,7 +27,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. (** {1 Utils around Mutex} -@since NEXT_RELEASE *) +@since 0.8 *) type 'a t (** A value surrounded with a lock *)