Skip to content

Commit

Permalink
Merge branch 'master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Feb 11, 2018
2 parents b6cc0fa + 6b9f39d commit ff2c9a0
Show file tree
Hide file tree
Showing 26 changed files with 601 additions and 607 deletions.
2 changes: 2 additions & 0 deletions AUTHORS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@
- Fabian Hemmer (copy)
- Maciej Woś (@lostman)
- Orbifx (Stavros Polymenis)
- Rand (@rand00)
- Dave Aitken (@actionshrimp)
13 changes: 12 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
by `include CCMonomorphic` in `Containers` module
* Shadow the physical equality operator
* Shadow polymorphic functions in `CCList`
- rename `print` to `pp` for Format printers (closes #153)
- rename `print` to `pp` for Format printers (closes #153, #181)
- remove `CCFlatHashtbl`

=== others
Expand All @@ -22,6 +22,17 @@
- Avoid uses of the polymorphic operators
- Add a `CCMonomorphic` module shipped into a `containers.monomorphic` library
- make complexity of `Array.lookup` explicit (closes #174)
- add `CCFormat.lazy_{or,force}` for printing thunks
- now that ocaml >= 4.02 is required, use `Format.pp_print_text` directly
- add `CCHeap.delete_{one,all}`
- add `CCList.tail_opt`


- remove qtest makefile and use a script instead
- add many tests
- fix bug in `CCRAL.drop` (see #184)
- `CCFormat`: fix support of unrecognized styles
- fix bug: don't reverse twice in `CCList.repeat`

== 1.5.1, 1.5.2

Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build:
jbuilder build @install

test: build
jbuilder runtest --no-buffer
jbuilder runtest --no-buffer --force

clean:
jbuilder clean
Expand All @@ -28,6 +28,12 @@ update_next_tag:
sed -i "s/NEXT_VERSION/$(VERSION)/g" $(wildcard src/**/*.ml) $(wildcard src/**/*.mli)
sed -i "s/NEXT_RELEASE/$(VERSION)/g" $(wildcard src/**/*.ml) $(wildcard src/**/*.mli)

release: update_next_tag
@echo "release version $(VERSION)..."
git tag -f $(VERSION) ; git push origin :$(VERSION) ; git push origin $(VERSION)
opam publish prepare https://github.com/c-cube/qcheck/archive/$(VERSION).tar.gz
@echo "review the release, then type 'opam publish submit qcheck.$(VERSION)/'"

watch:
while find src/ benchs/ -print0 | xargs -0 inotifywait -e delete_self -e modify ; do \
echo "============ at `date` ==========" ; \
Expand Down
5 changes: 2 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -484,16 +484,15 @@ Beforehand, check `grep deprecated -r src` to see whether some functions
can be removed.

. `make test`
. update version in `_oasis`
. update version in `containers.opam`
. `make update_next_tag` (to update `@since` comments; be careful not to change symlinks)
. check status of modules (`{b status: foo}`) and update if required;
removed deprecated functions, etc.
. update `CHANGELOG.adoc` (see its end to find the right git command)
. commit the changes
. `git checkout stable`
. `git merge master`
. `oasis setup; make test doc`
. update `opam` (the version field; remove `oasis` in deps)
. `make test doc`
. tag, and push both to github
. `opam pin add containers https://github.com/c-cube/ocaml-containers.git#<release>`
. new opam package: `opam publish prepare; opam publish submit`
Expand Down
8 changes: 5 additions & 3 deletions containers.opam
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
opam-version: "1.2"
name: "containers"
version: "2.0+alpha2"
version: "2.0"
author: "Simon Cruanes"
maintainer: "[email protected]"
build: [
["jbuilder" "build" "-p" name "-j" jobs]
]
build-doc: [ "jbuilder" "build" "@doc" ]
build-test: [ "jbuilder" "runtest" ]
build-test: [ "jbuilder" "runtest" "-p" name "-j" jobs]
depends: [
"jbuilder" {build}
"result"
Expand All @@ -18,6 +18,8 @@ depopts: [
"qtest" { test }
"qcheck" { test }
"oUnit" { test }
"sequence" { test }
"gen" { test }
"odoc" { doc }
]
conflicts: [
Expand All @@ -37,5 +39,5 @@ These changes belong to 3 categories:
- make most optional arguments relying on polymorphic operators mandatory
- improve consistency of printers

changelog: https://github.com/c-cube/ocaml-containers/blob/2.0+alpha1/CHANGELOG.adoc"
changelog: https://github.com/c-cube/ocaml-containers/blob/2.0/CHANGELOG.adoc"
]
2 changes: 1 addition & 1 deletion qtest/jbuild
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

(rule
((targets (run_qtest.ml))
(deps (make.bc))
(deps (make.bc (files_recursively_in ../src)))
;(libraries (qtest qcheck))
(action
(run ./make.bc -target ${@}))
Expand Down
4 changes: 3 additions & 1 deletion src/core/CCArray.mli
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ val random_choose : 'a t -> 'a random_gen
@raise Not_found if the array/slice is empty. *)

val to_seq : 'a t -> 'a sequence
(** Return a [sequence] of the elements of an array. *)
(** Return a [sequence] of the elements of an array.
The input array is shared with the sequence and modifications of it will result
in modification of the sequence. *)

val to_gen : 'a t -> 'a gen
(** Return a [gen] of the elements of an array. *)
Expand Down
68 changes: 26 additions & 42 deletions src/core/CCFormat.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,7 @@ let newline = Format.pp_force_newline
let substring out (s,i,len): unit =
string out (String.sub s i len)

let text out (s:string): unit =
let len = String.length s in
let i = ref 0 in
let search_ c =
try Some (String.index_from s !i c) with Not_found -> None
in
while !i < len do
let j_newline = search_ '\n' in
let j_space = search_ ' ' in
let on_newline j =
substring out (s, !i, j - !i);
newline out ();
i := j + 1
and on_space j =
substring out (s, !i, j - !i);
Format.pp_print_space out ();
i := j + 1
in
begin match j_newline, j_space with
| None, None ->
(* done *)
substring out (s, !i, len - !i);
i := len
| Some j, None -> on_newline j
| None, Some j -> on_space j
| Some j1, Some j2 ->
if j1<j2 then on_newline j1 else on_space j2
end
done
let text = Format.pp_print_text

(*$= & ~printer:(fun s->CCFormat.sprintf "%S" s)
"a\nb\nc" (sprintf_no_color "@[<v>%a@]%!" text "a b c")
Expand Down Expand Up @@ -161,6 +133,11 @@ let some pp out = function
| None -> ()
| Some x -> pp out x

let lazy_force pp out (lazy x) = pp out x

let lazy_or ?(default=return "<lazy>") pp out x =
if Lazy.is_val x then pp out (Lazy.force x) else default out ()

(** {2 IO} *)

let output fmt pp x = pp fmt x
Expand Down Expand Up @@ -266,6 +243,8 @@ let ansi_l_to_str_ = function
Buffer.add_string buf "m";
Buffer.contents buf

exception No_such_style

(* parse a tag *)
let style_of_tag_ s = match String.trim s with
| "reset" -> [`Reset]
Expand All @@ -286,7 +265,7 @@ let style_of_tag_ s = match String.trim s with
| "Magenta" -> [`FG `Magenta; `Bold]
| "Cyan" -> [`FG `Cyan; `Bold]
| "White" -> [`FG `White; `Bold]
| s -> failwith ("unknown style: " ^ s)
| _ -> raise No_such_style

let color_enabled = ref false

Expand All @@ -296,20 +275,21 @@ let mark_open_tag st ~or_else s =
let style = style_of_tag_ s in
Stack.push style st;
if !color_enabled then ansi_l_to_str_ style else ""
with Not_found -> or_else s
with No_such_style -> or_else s

let mark_close_tag st ~or_else s =
try
let _ = style_of_tag_ s in (* check if it's indeed about color *)
let style =
try
ignore (Stack.pop st); (* pop current style (if well-scoped...) *)
Stack.top st (* look at previous style *)
with Stack.Empty ->
[`Reset]
in
if !color_enabled then ansi_l_to_str_ style else ""
with Not_found -> or_else s
(* check if it's indeed about color *)
match style_of_tag_ s with
| _ ->
let style =
try
ignore (Stack.pop st); (* pop current style (if well-scoped...) *)
Stack.top st (* look at previous style *)
with Stack.Empty ->
[`Reset]
in
if !color_enabled then ansi_l_to_str_ style else ""
| exception No_such_style -> or_else s

(* add color handling to formatter [ppf] *)
let set_color_tag_handling ppf =
Expand Down Expand Up @@ -411,6 +391,10 @@ let ksprintf ~f fmt =
(fun _ -> Format.pp_print_flush out (); f (Buffer.contents buf))
out fmt

(*$= & ~printer:CCFormat.(to_string (opt string))
(Some "hello world") \
(ksprintf "hello %a" CCFormat.string "world" ~f:(fun s -> Some s))
*)

module Dump = struct
type 'a t = 'a printer
Expand Down
14 changes: 9 additions & 5 deletions src/core/CCFormat.mli
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ val some : 'a printer -> 'a option printer
@since 1.0
*)

val lazy_force : 'a printer -> 'a lazy_t printer
(** [lazy_force pp out x] forces [x] and prints the result with [pp]
@since 2.0 *)

val lazy_or : ?default:unit printer -> 'a printer -> 'a lazy_t printer
(** [lazy_or ?default pp out x] prints [default] if [x] is not
evaluated yet, or uses [pp] otherwise
@since 2.0 *)

(** {2 ANSI codes}
Use ANSI escape codes https://en.wikipedia.org/wiki/ANSI_escape_code
Expand Down Expand Up @@ -271,11 +280,6 @@ val ksprintf :
and then calls [f] on the resulting string.
@since 0.14 *)

(*$= & ~printer:CCFormat.(to_string (opt string))
(Some "hello world") \
(ksprintf "hello %a" CCFormat.string "world" ~f:(fun s -> Some s))
*)

val to_file : string -> ('a, t, unit, unit) format4 -> 'a
(** Print to the given file. *)

Expand Down
2 changes: 2 additions & 0 deletions src/core/CCHashtbl.mli
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module Poly : sig

val keys_list : ('a, 'b) Hashtbl.t -> 'a list
(** [keys_list t] is the list of keys in [t].
If the key is in the Hashtable multiple times, all occurrences will be returned.
@since 0.8 *)

val values_list : ('a, 'b) Hashtbl.t -> 'b list
Expand Down Expand Up @@ -150,6 +151,7 @@ module type S = sig

val keys_list : _ t -> key list
(** [keys_list t] is the list of keys in [t].
If the key is in the Hashtable multiple times, all occurrences will be returned.
@since 0.8 *)

val values_list : 'a t -> 'a list
Expand Down
8 changes: 4 additions & 4 deletions src/core/CCHeap.mli
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ module type S = sig
@since 0.16 *)

val of_list : elt list -> t
(** [of_list l] is [add_list empty l]. *)
(** [of_list l] is [add_list empty l]. Complexity: [O(n log n)]. *)

val add_seq : t -> elt sequence -> t (** @since 0.16 *)
(** Similar to {!add_list}. *)

val of_seq : elt sequence -> t
(** Build a heap from a given [sequence]. *)
(** Build a heap from a given [sequence]. Complexity: [O(n log n)]. *)

val to_seq : t -> elt sequence
(** Return a [sequence] of the elements of the heap. *)
Expand All @@ -115,15 +115,15 @@ module type S = sig
val add_klist : t -> elt klist -> t (** @since 0.16 *)

val of_klist : elt klist -> t
(** Build a heap from a given [klist]. *)
(** Build a heap from a given [klist]. Complexity: [O(n log n)]. *)

val to_klist : t -> elt klist
(** Return a [klist] of the elements of the heap. *)

val add_gen : t -> elt gen -> t (** @since 0.16 *)

val of_gen : elt gen -> t
(** Build a heap from a given [gen]. *)
(** Build a heap from a given [gen]. Complexity: [O(n log n)]. *)

val to_gen : t -> elt gen
(** Return a [gen] of the elements of the heap. *)
Expand Down
17 changes: 15 additions & 2 deletions src/core/CCList.ml
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,9 @@ let sorted_insert ~cmp ?(uniq=false) x l =
aux cmp uniq x [] l

(*$Q
Q.(pair small_int (list small_int)) (fun (x,l) -> \
let l = List.sort Pervasives.compare l in \
is_sorted ~cmp:CCInt.compare (sorted_insert ~cmp:CCInt.compare x l))
Q.(pair small_int (list small_int)) (fun (x,l) -> \
let l = List.sort Pervasives.compare l in \
is_sorted ~cmp:CCInt.compare (sorted_insert ~cmp:CCInt.compare ~uniq:true x l))
Expand Down Expand Up @@ -1253,11 +1256,21 @@ let replicate i x =
else aux (x::acc) (i-1)
in aux [] i


(*$T
repeat 2 [1;2;3] = [1;2;3;1;2;3]
*)

(*$Q
Q.(pair small_int (small_list int)) (fun (n,l) -> \
if n>0 then repeat n l = flat_map (fun _ -> l) (1--n) \
else Q.assume_fail())
*)

let repeat i l =
let l' = List.rev l in
let rec aux acc i =
if i = 0 then List.rev acc
else aux (List.rev_append l' acc) (i-1)
else aux (List.rev_append l acc) (i-1)
in aux [] i

module Assoc = struct
Expand Down
Loading

0 comments on commit ff2c9a0

Please sign in to comment.