BREAKING CHANGES since 1.2: size is now stored along with the bitvector. Some functions have a new signature.
The size of the bitvector used to be rounded up to the multiple of 30 or 62. In other words some functions such as iter would iterate on more bits than what was originally asked for. This is not the case anymore.
The bits are interpreted as indices into the returned bitvector, so the final bitvector bv will have length bv equal to 1 more than max of list indices.
select arr bv selects the elements of arr whose index corresponds to a true bit in bv. If bv is too short, elements of arr with too high an index cannot be selected and are therefore not selected.
\ No newline at end of file
+CCBV (containers-data.CCBV)
Module CCBV
Imperative Bitvectors
BREAKING CHANGES since 1.2: size is now stored along with the bitvector. Some functions have a new signature.
The size of the bitvector used to be rounded up to the multiple of 30 or 62. In other words some functions such as iter would iterate on more bits than what was originally asked for. This is not the case anymore.
The bits are interpreted as indices into the returned bitvector, so the final bitvector bv will have length bv equal to 1 more than max of list indices.
select arr bv selects the elements of arr whose index corresponds to a true bit in bv. If bv is too short, elements of arr with too high an index cannot be selected and are therefore not selected.
\ No newline at end of file
diff --git a/dev/containers/CCFormat/ANSI_codes/index.html b/dev/containers/CCFormat/ANSI_codes/index.html
index edade891..f2f865ad 100644
--- a/dev/containers/CCFormat/ANSI_codes/index.html
+++ b/dev/containers/CCFormat/ANSI_codes/index.html
@@ -1,3 +1,3 @@
-ANSI_codes (containers.CCFormat.ANSI_codes)
Module CCFormat.ANSI_codes
ANSI escape codes. This contains lower level functions for them.
string_of_style_list styles is an escape code for multiple styles at once. For example string_of_style_list ANSI_codes.([`FG `Red; `BG `Green; `Bold]) is a very shiny style.
\ No newline at end of file
diff --git a/dev/containers/CCFormat/index.html b/dev/containers/CCFormat/index.html
index 21543479..78735a70 100644
--- a/dev/containers/CCFormat/index.html
+++ b/dev/containers/CCFormat/index.html
@@ -1,5 +1,5 @@
-CCFormat (containers.CCFormat)
val ksprintf : (string ->'a)->('b, unit, string, 'a) Stdlib.format4->'b
val kasprintf : (string ->'a)->('b, formatter, unit, 'a) Stdlib.format4->'b
val bprintf : Stdlib.Buffer.t ->('a, formatter, unit) Stdlib.format->'a
val kprintf : (string ->'a)->('b, unit, string, 'a) Stdlib.format4->'b
val set_all_formatter_output_functions : out:(string -> int -> int -> unit)->flush:(unit -> unit)->newline:(unit -> unit)->spaces:(int -> unit)-> unit
val get_all_formatter_output_functions : unit ->(string -> int -> int -> unit) * (unit -> unit) * (unit -> unit) * (int -> unit)
val pp_set_all_formatter_output_functions : formatter->out:(string -> int -> int -> unit)->flush:(unit -> unit)->newline:(unit -> unit)->spaces:(int -> unit)-> unit
val pp_get_all_formatter_output_functions : formatter-> unit ->(string -> int -> int -> unit) * (unit -> unit) * (unit -> unit) * (int -> unit)
string_lines out s prints s with all newlines ('\n') replaced by a cut, in a vertical box. It does NOT insert breakable spaces in place of spaces, unlike text. This means an already formatted string can be displayed inside another formatter without mangling the indentation.
val ksprintf : (string ->'a)->('b, unit, string, 'a) Stdlib.format4->'b
val kasprintf : (string ->'a)->('b, formatter, unit, 'a) Stdlib.format4->'b
val bprintf : Stdlib.Buffer.t ->('a, formatter, unit) Stdlib.format->'a
val kprintf : (string ->'a)->('b, unit, string, 'a) Stdlib.format4->'b
val set_all_formatter_output_functions : out:(string -> int -> int -> unit)->flush:(unit -> unit)->newline:(unit -> unit)->spaces:(int -> unit)-> unit
val get_all_formatter_output_functions : unit ->(string -> int -> int -> unit) * (unit -> unit) * (unit -> unit) * (int -> unit)
val pp_set_all_formatter_output_functions : formatter->out:(string -> int -> int -> unit)->flush:(unit -> unit)->newline:(unit -> unit)->spaces:(int -> unit)-> unit
val pp_get_all_formatter_output_functions : formatter-> unit ->(string -> int -> int -> unit) * (unit -> unit) * (unit -> unit) * (int -> unit)
string_lines out s prints s with all newlines ('\n') replaced by a cut, in a vertical box. It does NOT insert breakable spaces in place of spaces, unlike text. This means an already formatted string can be displayed inside another formatter without mangling the indentation.
Add functions to support color tags to the given formatter.
since
0.15
val set_color_default : bool -> unit
set_color_default b enables color handling on the standard formatters (stdout, stderr) if b = true as well as on sprintf formatters; it disables the color handling if b = false.
val with_out_chan : Stdlib.out_channel ->(t->'a)->'a
with_out_chan oc f turns oc into a formatter fmt, and call f fmt. Behaves like f fmt from then on, but whether the call to f fails or returns, fmt is flushed before the call terminates.
The API of this module is stable as per semantic versioning, like the rest of containers. However the exact implementation of hashing function can change and should not be relied on (i.e. hashing a value always returns the same integer within a run of a program, not across versions of OCaml and Containers).
Always return 0. Useful for ignoring elements. Example: Hash.(pair string const0) will map pairs ("a", 1) and ("a", 2) to the same hash, but not the same as ("b", 1).
The API of this module is stable as per semantic versioning, like the rest of containers. However the exact implementation of hashing function can change and should not be relied on (i.e. hashing a value always returns the same integer within a run of a program, not across versions of OCaml and Containers).
Always return 0. Useful for ignoring elements. Example: Hash.(pair string const0) will map pairs ("a", 1) and ("a", 2) to the same hash, but not the same as ("b", 1).
val with_in : ?mode:int->?flags:Stdlib.open_flag list-> string ->(Stdlib.in_channel ->'a)->'a
Open an input file with the given optional flag list, calls the function on the input channel. When the function raises or returns, the channel is closed.
raises Sys_error
in case of error (same as open_in and close_in).
parameter flags
opening flags (default [Open_text]). Open_rdonly is used in any cases.
val read_chunks_gen : ?size:int-> Stdlib.in_channel ->string gen
Read the channel's content into chunks of size size. NOTE the generator must be used within the lifetime of the channel, see warning at the top of the file.
val read_chunks_seq : ?size:int-> Stdlib.in_channel ->string Stdlib.Seq.t
Read the channel's content into chunks of size size. NOTE the generator must be used within the lifetime of the channel, see warning at the top of the file.
since
NEXT_RELEASE
val read_line : Stdlib.in_channel ->string option
Read a line from the channel. Returns None if the input is terminated. The "\n" is removed from the line.
val read_lines_gen : Stdlib.in_channel ->string gen
Read all lines. The generator should be traversed only once. NOTE the generator must be used within the lifetime of the channel, see warning at the top of the file.
val read_lines_seq : Stdlib.in_channel ->string Stdlib.Seq.t
Read all lines. NOTE the seq must be used within the lifetime of the channel, see warning at the top of the file.
since
NEXT_RELEASE
val read_lines_l : Stdlib.in_channel ->string list
Read all lines into a list.
val read_all : ?size:int-> Stdlib.in_channel -> string
Read the whole channel into a buffer, then converted into a string.
parameter size
the internal buffer size.
since
0.7
val read_all_bytes : ?size:int-> Stdlib.in_channel -> Stdlib.Bytes.t
Read the whole channel into a mutable byte array.
parameter size
the internal buffer size.
since
0.12
Output
val with_out : ?mode:int->?flags:Stdlib.open_flag list-> string ->(Stdlib.out_channel ->'a)->'a
tee funs gen behaves like gen, but each element is given to every function f in funs at the time the element is produced. The returned generator will raise any exception that f raises
val with_in : ?mode:int->?flags:Stdlib.open_flag list-> string ->(Stdlib.in_channel ->'a)->'a
Open an input file with the given optional flag list, calls the function on the input channel. When the function raises or returns, the channel is closed.
raises Sys_error
in case of error (same as open_in and close_in).
parameter flags
opening flags (default [Open_text]). Open_rdonly is used in any cases.
val read_chunks_gen : ?size:int-> Stdlib.in_channel ->string gen
Read the channel's content into chunks of size size. NOTE the generator must be used within the lifetime of the channel, see warning at the top of the file.
val read_chunks_seq : ?size:int-> Stdlib.in_channel ->string Stdlib.Seq.t
Read the channel's content into chunks of size size. NOTE the generator must be used within the lifetime of the channel, see warning at the top of the file.
since
3.5
val read_line : Stdlib.in_channel ->string option
Read a line from the channel. Returns None if the input is terminated. The "\n" is removed from the line.
val read_lines_gen : Stdlib.in_channel ->string gen
Read all lines. The generator should be traversed only once. NOTE the generator must be used within the lifetime of the channel, see warning at the top of the file.
val read_lines_seq : Stdlib.in_channel ->string Stdlib.Seq.t
Read all lines. NOTE the seq must be used within the lifetime of the channel, see warning at the top of the file.
since
3.5
val read_lines_l : Stdlib.in_channel ->string list
Read all lines into a list.
val read_all : ?size:int-> Stdlib.in_channel -> string
Read the whole channel into a buffer, then converted into a string.
parameter size
the internal buffer size.
since
0.7
val read_all_bytes : ?size:int-> Stdlib.in_channel -> Stdlib.Bytes.t
Read the whole channel into a mutable byte array.
parameter size
the internal buffer size.
since
0.12
Output
val with_out : ?mode:int->?flags:Stdlib.open_flag list-> string ->(Stdlib.out_channel ->'a)->'a
tee funs gen behaves like gen, but each element is given to every function f in funs at the time the element is produced. The returned generator will raise any exception that f raises
\ No newline at end of file
diff --git a/dev/containers/CCList/index.html b/dev/containers/CCList/index.html
index 7f27434d..f3f6f1a0 100644
--- a/dev/containers/CCList/index.html
+++ b/dev/containers/CCList/index.html
@@ -9,4 +9,4 @@
return @@ x * x;;
val square_even : int list -> int list = <fun>
# square_even [1;2;4;3;5;2];;
-- : int list = [4; 16; 4]
all_some l returns Some l' if all elements of l are of the form Some x, or None otherwise.
since
1.3, but only
since
2.2 with labels
val all_ok : ('a, 'err) Stdlib.resultt->('at, 'err) Stdlib.result
all_ok l returns Ok l' if all elements of l are of the form Ok x, or Error e otherwise (with the first error met).
since
1.3, but only
since
2.2 with labels
val sorted_mem : cmp:('a->'a-> int)->'a->'a list-> bool
sorted_mem ~cmp x l and mem x l give the same result for any sorted list l, but potentially more efficiently.
since
NEXT_RELEASE
val sorted_merge : cmp:('a->'a-> int)->'a list->'a list->'a list
sorted_merge ~cmp l1 l2 merges elements from both sorted list using the given comparison function cmp.
val sorted_diff : cmp:('a->'a-> int)->'a list->'a list->'a list
sorted_diff ~cmp l1 l2 returns the elements in l1 that are not in l2. Both lists are assumed to be sorted with respect to cmp and duplicate elements in the input lists are treated individually; for example, sorted_diff ~cmp [1;1;1;2;2;3] [1;2;2] would be [1;1;3]. It is the left inverse of sorted_merge; that is, sorted_diff ~cmp (sorted_merge ~cmp l1 l2) l2 is always equal to l1 for sorted lists l1 and l2.
since
NEXT_RELEASE
val sort_uniq : cmp:('a->'a-> int)->'a list->'a list
sort_uniq ~cmp l sorts the list l using the given comparison function cmp and remove duplicate elements.
val sorted_merge_uniq : cmp:('a->'a-> int)->'a list->'a list->'a list
sorted_merge_uniq ~cmp l1 l2 merges the sorted lists l1 and l2 and removes duplicates.
since
0.10
val sorted_diff_uniq : cmp:('a->'a-> int)->'a list->'a list->'a list
sorted_diff_uniq ~cmp l1 l2 collects the elements in l1 that are not in l2 and then remove duplicates. Both lists are assumed to be sorted with respect to cmp and duplicate elements in the input lists are treated individually; for example, sorted_diff_uniq ~cmp [1;1;1;2;2] [1;2;2;2] would be [1]. sorted_diff_uniq ~cmp l1 l2 and uniq_succ ~eq (sorted_diff ~cmp l1 l2) always give the same result for sorted l1 and l2 and compatible cmp and eq.
since
NEXT_RELEASE
val is_sorted : cmp:('a->'a-> int)->'a list-> bool
is_sorted ~cmp l returns true iff l is sorted (according to given order).
parameter cmp
the comparison function.
since
0.17
val sorted_insert : cmp:('a->'a-> int)->?uniq:bool->'a->'a list->'a list
sorted_insert ~cmp ?uniq x l inserts x into l such that, if l was sorted, then sorted_insert x l is sorted too.
parameter uniq
if true and x is already in sorted position in l, then x is not duplicated. Default false (x will be inserted in any case).
since
0.17
val sorted_remove : cmp:('a->'a-> int)->?all:bool->'a->'a list->'a list
sorted_remove ~cmp x l removes x from a sorted list l such that the return value is sorted too. By default, it is the left inverse of sorted_insert; that is, sorted_remove ~cmp x (sorted_insert ~cmp x l) is equal to l for any sorted list l.
parameter all
if true then all occurrences of x will be removed. Otherwise, only the first x will be removed (if any). Default false (only the first will be removed).
since
NEXT_RELEASE
val uniq_succ : eq:('a->'a-> bool)->'a list->'a list
uniq_succ ~eq l removes duplicate elements that occur one next to the other. Examples: uniq_succ ~eq:(=) [1;2;1] = [1;2;1]. uniq_succ ~eq:(=) [1;1;2] = [1;2].
since
0.10
val group_succ : eq:('a->'a-> bool)->'a list->'a list list
group_succ ~eq l groups together consecutive elements that are equal according to eq.
mapi f l is like map, but the function f is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
iteri f l is like iter, but the function f is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
val iteri2 : (int ->'a->'b-> unit)->'at->'bt-> unit
iteri2 f l1 l2 applies f to the two lists l1 and l2 simultaneously. The integer passed to f indicates the index of element.
foldi f init l is like fold but it also passes in the index of each element, from 0 to length l - 1 as additional argument to the folded function f. Tail-recursive.
val foldi2 : ('c-> int ->'a->'b->'c)->'c->'at->'bt->'c
foldi2 f init l1 l2 folds on the two lists l1 and l2, with index of each element passed to the function f. Computes f(… (f init i_0 l1_0 l2_0) …) i_n l1_n l2_n .
get_at_idx i l returns Some i-th element of the given list l or None if the list l is too short. If the index is negative, it will get element starting from the end of the list l.
set_at_idx i x l replaces the i-th element with x (removes the old one), or does nothing if index is too high. If the index is negative, it will set element starting from the end of the list.
insert_at_idx i x l inserts x at i-th position, between the two existing elements. If the index is too high, append at the end of the list. If the index is negative, it will insert element starting from the end of the list.
remove_at_idx i l removes element at given index i. Does nothing if the index is too high. If the index is negative, it will remove element starting from the end of the list.
Set Operators
Those operations maintain the invariant that the list does not contain duplicates (if it already satisfies it).
uniq ~eq l removes duplicates in l w.r.t the equality predicate eq. Complexity is quadratic in the length of the list, but the order of elements is preserved. If you wish for a faster de-duplication but do not care about the order, use sort_uniq.
range_by ~step i j iterates on integers from i to j included, where the difference between successive elements is step. Use a negative step for a decreasing list.
assq_opt k alist returns Some v if the given key k is present into alist. Like Assoc.assoc_opt but use physical equality instead of structural equality to compare keys. Safe version of assq.
since
1.5, but only
since
2.0 with labels
val mem_assoc : ?eq:('a->'a-> bool)->'a->('a * _)t-> bool
mem_assoc ?eq k alist returns true iff k is a key in alist. Like Assoc.mem.
since
2.0
val remove_assoc : eq:('a->'a-> bool)->'a->('a * 'b)t->('a * 'b)t
remove_assoc ~eq k alist returns the alist without the first pair with key k, if any. Like Assoc.remove.
of_seq seq builds a list from a given Seq.t. In the result, elements appear in the same order as they did in the source Seq.t. Renamed from of_std_seq since 3.0.
all_some l returns Some l' if all elements of l are of the form Some x, or None otherwise.
since
1.3, but only
since
2.2 with labels
val all_ok : ('a, 'err) Stdlib.resultt->('at, 'err) Stdlib.result
all_ok l returns Ok l' if all elements of l are of the form Ok x, or Error e otherwise (with the first error met).
since
1.3, but only
since
2.2 with labels
val sorted_mem : cmp:('a->'a-> int)->'a->'a list-> bool
sorted_mem ~cmp x l and mem x l give the same result for any sorted list l, but potentially more efficiently.
since
3.5
val sorted_merge : cmp:('a->'a-> int)->'a list->'a list->'a list
sorted_merge ~cmp l1 l2 merges elements from both sorted list using the given comparison function cmp.
val sorted_diff : cmp:('a->'a-> int)->'a list->'a list->'a list
sorted_diff ~cmp l1 l2 returns the elements in l1 that are not in l2. Both lists are assumed to be sorted with respect to cmp and duplicate elements in the input lists are treated individually; for example, sorted_diff ~cmp [1;1;1;2;2;3] [1;2;2] would be [1;1;3]. It is the left inverse of sorted_merge; that is, sorted_diff ~cmp (sorted_merge ~cmp l1 l2) l2 is always equal to l1 for sorted lists l1 and l2.
since
3.5
val sort_uniq : cmp:('a->'a-> int)->'a list->'a list
sort_uniq ~cmp l sorts the list l using the given comparison function cmp and remove duplicate elements.
val sorted_merge_uniq : cmp:('a->'a-> int)->'a list->'a list->'a list
sorted_merge_uniq ~cmp l1 l2 merges the sorted lists l1 and l2 and removes duplicates.
since
0.10
val sorted_diff_uniq : cmp:('a->'a-> int)->'a list->'a list->'a list
sorted_diff_uniq ~cmp l1 l2 collects the elements in l1 that are not in l2 and then remove duplicates. Both lists are assumed to be sorted with respect to cmp and duplicate elements in the input lists are treated individually; for example, sorted_diff_uniq ~cmp [1;1;1;2;2] [1;2;2;2] would be [1]. sorted_diff_uniq ~cmp l1 l2 and uniq_succ ~eq (sorted_diff ~cmp l1 l2) always give the same result for sorted l1 and l2 and compatible cmp and eq.
since
3.5
val is_sorted : cmp:('a->'a-> int)->'a list-> bool
is_sorted ~cmp l returns true iff l is sorted (according to given order).
parameter cmp
the comparison function.
since
0.17
val sorted_insert : cmp:('a->'a-> int)->?uniq:bool->'a->'a list->'a list
sorted_insert ~cmp ?uniq x l inserts x into l such that, if l was sorted, then sorted_insert x l is sorted too.
parameter uniq
if true and x is already in sorted position in l, then x is not duplicated. Default false (x will be inserted in any case).
since
0.17
val sorted_remove : cmp:('a->'a-> int)->?all:bool->'a->'a list->'a list
sorted_remove ~cmp x l removes x from a sorted list l such that the return value is sorted too. By default, it is the left inverse of sorted_insert; that is, sorted_remove ~cmp x (sorted_insert ~cmp x l) is equal to l for any sorted list l.
parameter all
if true then all occurrences of x will be removed. Otherwise, only the first x will be removed (if any). Default false (only the first will be removed).
since
3.5
val uniq_succ : eq:('a->'a-> bool)->'a list->'a list
uniq_succ ~eq l removes duplicate elements that occur one next to the other. Examples: uniq_succ ~eq:(=) [1;2;1] = [1;2;1]. uniq_succ ~eq:(=) [1;1;2] = [1;2].
since
0.10
val group_succ : eq:('a->'a-> bool)->'a list->'a list list
group_succ ~eq l groups together consecutive elements that are equal according to eq.
mapi f l is like map, but the function f is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
iteri f l is like iter, but the function f is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
val iteri2 : (int ->'a->'b-> unit)->'at->'bt-> unit
iteri2 f l1 l2 applies f to the two lists l1 and l2 simultaneously. The integer passed to f indicates the index of element.
foldi f init l is like fold but it also passes in the index of each element, from 0 to length l - 1 as additional argument to the folded function f. Tail-recursive.
val foldi2 : ('c-> int ->'a->'b->'c)->'c->'at->'bt->'c
foldi2 f init l1 l2 folds on the two lists l1 and l2, with index of each element passed to the function f. Computes f(… (f init i_0 l1_0 l2_0) …) i_n l1_n l2_n .
get_at_idx i l returns Some i-th element of the given list l or None if the list l is too short. If the index is negative, it will get element starting from the end of the list l.
set_at_idx i x l replaces the i-th element with x (removes the old one), or does nothing if index is too high. If the index is negative, it will set element starting from the end of the list.
insert_at_idx i x l inserts x at i-th position, between the two existing elements. If the index is too high, append at the end of the list. If the index is negative, it will insert element starting from the end of the list.
remove_at_idx i l removes element at given index i. Does nothing if the index is too high. If the index is negative, it will remove element starting from the end of the list.
Set Operators
Those operations maintain the invariant that the list does not contain duplicates (if it already satisfies it).
uniq ~eq l removes duplicates in l w.r.t the equality predicate eq. Complexity is quadratic in the length of the list, but the order of elements is preserved. If you wish for a faster de-duplication but do not care about the order, use sort_uniq.
range_by ~step i j iterates on integers from i to j included, where the difference between successive elements is step. Use a negative step for a decreasing list.
assq_opt k alist returns Some v if the given key k is present into alist. Like Assoc.assoc_opt but use physical equality instead of structural equality to compare keys. Safe version of assq.
since
1.5, but only
since
2.0 with labels
val mem_assoc : ?eq:('a->'a-> bool)->'a->('a * _)t-> bool
mem_assoc ?eq k alist returns true iff k is a key in alist. Like Assoc.mem.
since
2.0
val remove_assoc : eq:('a->'a-> bool)->'a->('a * 'b)t->('a * 'b)t
remove_assoc ~eq k alist returns the alist without the first pair with key k, if any. Like Assoc.remove.
of_seq seq builds a list from a given Seq.t. In the result, elements appear in the same order as they did in the source Seq.t. Renamed from of_std_seq since 3.0.
pp ?pp_start ?pp_stop ?pp_sep ppf l prints the contents of a list.
\ No newline at end of file
diff --git a/dev/containers/CCListLabels/index.html b/dev/containers/CCListLabels/index.html
index 9102e295..155fbca8 100644
--- a/dev/containers/CCListLabels/index.html
+++ b/dev/containers/CCListLabels/index.html
@@ -9,4 +9,4 @@
return @@ x * x;;
val square_even : int list -> int list = <fun>
# square_even [1;2;4;3;5;2];;
-- : int list = [4; 16; 4]
all_some l returns Some l' if all elements of l are of the form Some x, or None otherwise.
since
1.3, but only
since
2.2 with labels
val all_ok : ('a, 'err) Stdlib.resultt->('at, 'err) Stdlib.result
all_ok l returns Ok l' if all elements of l are of the form Ok x, or Error e otherwise (with the first error met).
since
1.3, but only
since
2.2 with labels
val sorted_mem : cmp:('a->'a-> int)->'a->'a list-> bool
sorted_mem ~cmp x l and mem x l give the same result for any sorted list l, but potentially more efficiently.
since
NEXT_RELEASE
val sorted_merge : cmp:('a->'a-> int)->'a list->'a list->'a list
sorted_merge ~cmp l1 l2 merges elements from both sorted list using the given comparison function cmp.
val sorted_diff : cmp:('a->'a-> int)->'a list->'a list->'a list
sorted_diff ~cmp l1 l2 returns the elements in l1 that are not in l2. Both lists are assumed to be sorted with respect to cmp and duplicate elements in the input lists are treated individually; for example, sorted_diff ~cmp [1;1;1;2;2;3] [1;2;2] would be [1;1;3]. It is the left inverse of sorted_merge; that is, sorted_diff ~cmp (sorted_merge ~cmp l1 l2) l2 is always equal to l1 for sorted lists l1 and l2.
since
NEXT_RELEASE
val sort_uniq : cmp:('a->'a-> int)->'a list->'a list
sort_uniq ~cmp l sorts the list l using the given comparison function cmp and remove duplicate elements.
val sorted_merge_uniq : cmp:('a->'a-> int)->'a list->'a list->'a list
sorted_merge_uniq ~cmp l1 l2 merges the sorted lists l1 and l2 and removes duplicates.
since
0.10
val sorted_diff_uniq : cmp:('a->'a-> int)->'a list->'a list->'a list
sorted_diff_uniq ~cmp l1 l2 collects the elements in l1 that are not in l2 and then remove duplicates. Both lists are assumed to be sorted with respect to cmp and duplicate elements in the input lists are treated individually; for example, sorted_diff_uniq ~cmp [1;1;1;2;2] [1;2;2;2] would be [1]. sorted_diff_uniq ~cmp l1 l2 and uniq_succ ~eq (sorted_diff ~cmp l1 l2) always give the same result for sorted l1 and l2 and compatible cmp and eq.
since
NEXT_RELEASE
val is_sorted : cmp:('a->'a-> int)->'a list-> bool
is_sorted ~cmp l returns true iff l is sorted (according to given order).
parameter cmp
the comparison function.
since
0.17
val sorted_insert : cmp:('a->'a-> int)->?uniq:bool->'a->'a list->'a list
sorted_insert ~cmp ?uniq x l inserts x into l such that, if l was sorted, then sorted_insert x l is sorted too.
parameter uniq
if true and x is already in sorted position in l, then x is not duplicated. Default false (x will be inserted in any case).
since
0.17
val sorted_remove : cmp:('a->'a-> int)->?all:bool->'a->'a list->'a list
sorted_remove ~cmp x l removes x from a sorted list l such that the return value is sorted too. By default, it is the left inverse of sorted_insert; that is, sorted_remove ~cmp x (sorted_insert ~cmp x l) is equal to l for any sorted list l.
parameter all
if true then all occurrences of x will be removed. Otherwise, only the first x will be removed (if any). Default false (only the first will be removed).
since
NEXT_RELEASE
val uniq_succ : eq:('a->'a-> bool)->'a list->'a list
uniq_succ ~eq l removes duplicate elements that occur one next to the other. Examples: uniq_succ [1;2;1] = [1;2;1]. uniq_succ [1;1;2] = [1;2].
since
0.10
val group_succ : eq:('a->'a-> bool)->'a list->'a list list
group_succ ~eq l groups together consecutive elements that are equal according to eq.
mapi ~f l is like map, but the function f is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
iteri ~f l is like iter, but the function f is applied to the index of the element as first argument (counting from 0), and the element itself as second argument.
val iteri2 : f:(int ->'a->'b-> unit)->'at->'bt-> unit
iteri2 ~f l1 l2 applies f to the two lists l1 and l2 simultaneously. The integer passed to f indicates the index of element.
raises Invalid_argument
when lists do not have the same length.
since
2.0, but only
since
2.2 with labels
val foldi : f:('b-> int ->'a->'b)->init:'b->'at->'b
foldi ~f ~init l is like fold but it also passes in the index of each element, from 0 to length l - 1 as additional argument to the folded function f. Tail-recursive.
val foldi2 : f:('c-> int ->'a->'b->'c)->init:'c->'at->'bt->'c
foldi2 ~f ~init l1 l2 folds on the two lists l1 and l2, with index of each element passed to the function f. Computes f(… (f init i_0 l1_0 l2_0) …) i_n l1_n l2_n .
get_at_idx i l returns Some i-th element of the given list l or None if the list l is too short. If the index is negative, it will get element starting from the end of the list l.
set_at_idx i x l replaces the i-th element with x (removes the old one), or does nothing if index is too high. If the index is negative, it will set element starting from the end of the list.
insert_at_idx i x l inserts x at i-th position, between the two existing elements. If the index is too high, append at the end of the list. If the index is negative, it will insert element starting from the end of the list.
remove_at_idx i l removes element at given index i. Does nothing if the index is too high. If the index is negative, it will remove element starting from the end of the list.
Set Operators
Those operations maintain the invariant that the list does not contain duplicates (if it already satisfies it).
uniq ~eq l removes duplicates in l w.r.t the equality predicate eq. Complexity is quadratic in the length of the list, but the order of elements is preserved. If you wish for a faster de-duplication but do not care about the order, use sort_uniq.
range_by ~step i j iterates on integers from i to j included, where the difference between successive elements is step. Use a negative step for a decreasing list.
assq_opt k alist returns Some v if the given key k is present into alist. Like Assoc.assoc_opt but use physical equality instead of structural equality to compare keys. Safe version of assq.
since
1.5, but only
since
2.0 with labels
val mem_assoc : ?eq:('a->'a-> bool)->'a->('a * _)t-> bool
mem_assoc ?eq k alist returns true iff k is a key in alist. Like Assoc.mem.
since
2.0
val remove_assoc : eq:('a->'a-> bool)->'a->('a * 'b)t->('a * 'b)t
remove_assoc ~eq k alist returns the alist without the first pair with key k, if any. Like Assoc.remove.
of_seq seq builds a list from a given Seq.t. In the result, elements appear in the same order as they did in the source Seq.t. Renamed from of_std_seq since 3.0.