From 4058fc799e9809d21f53670ea8a642fbb5eb057c Mon Sep 17 00:00:00 2001 From: nilsbecker Date: Sat, 24 Jun 2017 11:59:59 +0200 Subject: [PATCH 1/4] typos and clarification in doc strings for sort_indices, sort_ranks and lookup_exn --- src/core/CCArray.mli | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/core/CCArray.mli b/src/core/CCArray.mli index 4ecaade7..f8f7a380 100644 --- a/src/core/CCArray.mli +++ b/src/core/CCArray.mli @@ -71,20 +71,22 @@ val sorted : ('a -> 'a -> int) -> 'a t -> 'a array val sort_indices : ('a -> 'a -> int) -> 'a t -> int array (** [sort_indices cmp a] returns a new array [b], with the same length as [a], - such that [b.(i)] is the index of the [i]-th element of [a] in [sort cmp a]. - In other words, [map (fun i -> a.(i)) (sort_indices a) = sorted cmp a]. + such that [b.(i)] is the index at which the [i]-th element of [sorted cmp a] + appears in [a]. + + In other words, [map (fun i -> a.(i)) (sort_indices cmp a) = sorted cmp a]. [a] is not modified. @since 1.0 *) val sort_ranking : ('a -> 'a -> int) -> 'a t -> int array (** [sort_ranking cmp a] returns a new array [b], with the same length as [a], - such that [b.(i)] is the position in [sorted cmp a] of the [i]-th - element of [a]. - [a] is not modified. + such that [b.(i)] is the index at which the [i]-the element of [a] appears + in [sorted cmp a]. [a] is not modified. - In other words, [map (fun i -> (sorted cmp a).(i)) (sort_ranking cmp a) = a]. + In other words, [map (fun i -> (sorted cmp a).(i)) (sort_ranking cmp a) = a]. + [sort_ranking] gives the inverse permutation of {!sort_indices}. - Without duplicates, we also have + In the absence of duplicate elements in [a], we also have [lookup_exn a.(i) (sorted a) = (sorted_ranking a).(i)] @since 1.0 *) @@ -118,7 +120,7 @@ val lookup : ?cmp:'a ord -> 'a -> 'a t -> int option [Some i] ([i] the index of the key) otherwise *) val lookup_exn : ?cmp:'a ord -> 'a -> 'a t -> int -(** Same as {!lookup_exn}, but +(** Same as {!lookup}, but @raise Not_found if the key is not present *) val bsearch : ?cmp:('a -> 'a -> int) -> 'a -> 'a t -> From a2b2eaec2ef2afe4475da2fa90e2a17bc3601050 Mon Sep 17 00:00:00 2001 From: nilsbecker Date: Sat, 24 Jun 2017 13:45:49 +0200 Subject: [PATCH 2/4] small correction --- src/core/CCArray.mli | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/core/CCArray.mli b/src/core/CCArray.mli index f8f7a380..72620658 100644 --- a/src/core/CCArray.mli +++ b/src/core/CCArray.mli @@ -72,10 +72,11 @@ val sorted : ('a -> 'a -> int) -> 'a t -> 'a array val sort_indices : ('a -> 'a -> int) -> 'a t -> int array (** [sort_indices cmp a] returns a new array [b], with the same length as [a], such that [b.(i)] is the index at which the [i]-th element of [sorted cmp a] - appears in [a]. + appears in [a]. [a] is not modified. In other words, [map (fun i -> a.(i)) (sort_indices cmp a) = sorted cmp a]. - [a] is not modified. + [sort_indices] yields the inverse permutation of {!sort_ranking}. + @since 1.0 *) val sort_ranking : ('a -> 'a -> int) -> 'a t -> int array @@ -84,7 +85,7 @@ val sort_ranking : ('a -> 'a -> int) -> 'a t -> int array in [sorted cmp a]. [a] is not modified. In other words, [map (fun i -> (sorted cmp a).(i)) (sort_ranking cmp a) = a]. - [sort_ranking] gives the inverse permutation of {!sort_indices}. + [sort_ranking] yields the inverse permutation of {!sort_indices}. In the absence of duplicate elements in [a], we also have [lookup_exn a.(i) (sorted a) = (sorted_ranking a).(i)] From 92958cc116491938963a060a254fc21cf94bfe3c Mon Sep 17 00:00:00 2001 From: nilsbecker Date: Sat, 24 Jun 2017 13:48:20 +0200 Subject: [PATCH 3/4] duplicated the changes in array_slice.mli --- src/core/CCArray_slice.mli | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/core/CCArray_slice.mli b/src/core/CCArray_slice.mli index 28dd37d4..ff93c946 100644 --- a/src/core/CCArray_slice.mli +++ b/src/core/CCArray_slice.mli @@ -83,23 +83,26 @@ val reverse_in_place : 'a t -> unit val sorted : ('a -> 'a -> int) -> 'a t -> 'a array (** [sorted cmp a] makes a copy of [a] and sorts it with [cmp]. @since 1.0 *) - + val sort_indices : ('a -> 'a -> int) -> 'a t -> int array (** [sort_indices cmp a] returns a new array [b], with the same length as [a], - such that [b.(i)] is the index of the [i]-th element of [a] in [sort cmp a]. - In other words, [map (fun i -> a.(i)) (sort_indices a) = sorted cmp a]. - [a] is not modified. + such that [b.(i)] is the index at which the [i]-th element of [sorted cmp a] + appears in [a]. [a] is not modified. + + In other words, [map (fun i -> a.(i)) (sort_indices cmp a) = sorted cmp a]. + [sort_indices] yields the inverse permutation of {!sort_ranking}. + @since 1.0 *) val sort_ranking : ('a -> 'a -> int) -> 'a t -> int array (** [sort_ranking cmp a] returns a new array [b], with the same length as [a], - such that [b.(i)] is the position in [sorted cmp a] of the [i]-th - element of [a]. - [a] is not modified. - - In other words, [map (fun i -> (sorted cmp a).(i)) (sort_ranking cmp a) = a]. - - Without duplicates, we also have + such that [b.(i)] is the index at which the [i]-the element of [a] appears + in [sorted cmp a]. [a] is not modified. + + In other words, [map (fun i -> (sorted cmp a).(i)) (sort_ranking cmp a) = a]. + [sort_ranking] yields the inverse permutation of {!sort_indices}. + + In the absence of duplicate elements in [a], we also have [lookup_exn a.(i) (sorted a) = (sorted_ranking a).(i)] @since 1.0 *) @@ -122,7 +125,7 @@ val lookup : ?cmp:'a ord -> 'a -> 'a t -> int option [Some i] ([i] the index of the key) otherwise *) val lookup_exn : ?cmp:'a ord -> 'a -> 'a t -> int -(** Same as {!lookup_exn}, but +(** Same as {!lookup}, but @raise Not_found if the key is not present *) val bsearch : ?cmp:('a -> 'a -> int) -> 'a -> 'a t -> From 78591cf6219d67e91301b8fbbc339804e202f361 Mon Sep 17 00:00:00 2001 From: nilsbecker Date: Sat, 24 Jun 2017 18:16:21 +0200 Subject: [PATCH 4/4] removed trailing spaces --- src/core/CCArray_slice.mli | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/CCArray_slice.mli b/src/core/CCArray_slice.mli index ff93c946..4450ddae 100644 --- a/src/core/CCArray_slice.mli +++ b/src/core/CCArray_slice.mli @@ -83,7 +83,7 @@ val reverse_in_place : 'a t -> unit val sorted : ('a -> 'a -> int) -> 'a t -> 'a array (** [sorted cmp a] makes a copy of [a] and sorts it with [cmp]. @since 1.0 *) - + val sort_indices : ('a -> 'a -> int) -> 'a t -> int array (** [sort_indices cmp a] returns a new array [b], with the same length as [a], such that [b.(i)] is the index at which the [i]-th element of [sorted cmp a]