/usr/lib/ocaml/batteries/batRefList.mli is in libbatteries-ocaml-dev 2.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | (*
* RefList - List reference
* Copyright (C) 2003 Nicolas Cannasse
* 2008 David Teller, LIFO, Universite d'Orleans
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version,
* with the special exception on linking described in file LICENSE.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*)
(** Reference on lists.
RefList is a extended set of functions that manipulate list
references.
@author Nicolas Cannasse
@author David Teller (Boilerplate code)
*)
exception Empty_list
type 'a t (**The type of an empty ref list*)
val empty : unit -> 'a t
(** Returns a new empty ref list *)
val is_empty : 'a t -> bool
(** Return [true] if a ref list is empty *)
val clear : 'a t -> unit
(** Removes all elements *)
val length : 'a t -> int
(** Returns the number of elements - O(n) *)
val copy : dst:'a t -> src:'a t -> unit
(** Makes a copy of a ref list - O(1) *)
val copy_list : dst:'a t -> src:'a list -> unit
(** Makes a copy of a list - O(1) *)
val copy_enum : dst:'a t -> src:'a BatEnum.t -> unit
(** Makes a copy of a enum.
@param dst A reflist, whose contents will be forgotten. *)
val of_list : 'a list -> 'a t
(** Creates a ref list from a list - O(1) *)
val to_list : 'a t -> 'a list
(** Returns the current elements as a list - O(1) *)
val of_enum : 'a BatEnum.t -> 'a t
(** Creates a ref list from an enumeration *)
val enum : 'a t -> 'a BatEnum.t
(** Returns an enumeration of current elements in the ref list *)
val of_backwards : 'a BatEnum.t -> 'a t
(** Creates a ref list from an enumeration, going from last to first *)
val backwards : 'a t -> 'a BatEnum.t
(** Returns an enumeration of current elements in the ref list, going from last to first *)
val add : 'a t -> 'a -> unit
(** Adds an element at the end - O(n) *)
val push : 'a t -> 'a -> unit
(** Adds an element at the head - O(1) *)
val add_sort : cmp:('a -> 'a -> int) -> 'a t -> 'a -> unit
(** Adds an element in a sorted list, using the given comparator. *)
val first : 'a t -> 'a
(** Returns the first element or
raises [Empty_list] if the ref list is empty *)
val last : 'a t -> 'a
(** Returns the last element - O(n) or
raises [Empty_list] if the ref list is empty *)
val pop : 'a t -> 'a
(** Removes and returns the first element or
raises [Empty_list] if the ref list is empty *)
val npop : 'a t -> int -> 'a list
(** Removes and returns the n first elements or
raises [Empty_list] if the ref list does not
contain enough elements *)
val hd : 'a t -> 'a
(** same as [first] *)
val tl : 'a t -> 'a t
(** Returns a ref list containing the same elements
but without the first one or
raises [Empty_list] if the ref list is empty *)
val rev : 'a t -> unit
(** Reverses the ref list - O(n) *)
(** {6 Functional Operations} *)
val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
(** [List.fold_left f a (ref [b0; b1; ...; bn])] is
[f (... (f (f a b0) b1) ...) bn]. *)
val fold_right : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'b
(** [List.fold_right f (ref [a0; a1; ...; an]) b] is
[f a0 (f a1 (... (f an b) ...))]. Tail-recursive. *)
val iter : ('a -> unit) -> 'a t -> unit
(** Apply the given function to all elements of the
ref list, in respect with the order of the list *)
val find : ('a -> bool) -> 'a t -> 'a
(** Find the first element matching
the specified predicate
raise [Not_found] if no element is found *)
val rfind : ('a -> bool) -> 'a t -> 'a
(** Find the first element in the reversed ref list matching
the specified predicate
raise [Not_found] if no element is found *)
val find_exc : ('a -> bool) -> exn -> 'a t -> 'a
(** Same as find but takes an exception to be raised when
no element is found as additional parameter *)
val exists : ('a -> bool) -> 'a t -> bool
(** Return [true] if an element matches the specified
predicate *)
val for_all : ('a -> bool) -> 'a t -> bool
(** Return [true] if all elements match the specified
predicate *)
val map : ('a -> 'b) -> 'a t -> 'b t
(** Apply a function to all elements
and return the ref list constructed with
the function returned values *)
val transform : ('a -> 'a) -> 'a t -> unit
(** transform all elements in the ref list
using a function. *)
val map_list : ('a -> 'b) -> 'a t -> 'b list
(** Apply a function to all elements
and return the list constructed with
the function returned values *)
val sort : cmp:('a -> 'a -> int) -> 'a t -> unit
(** Sort elements using the specified comparator *)
val filter : ('a -> bool) -> 'a t -> unit
(** Remove all elements that do not match the
specified predicate *)
val remove : 'a t -> 'a -> unit
(** Remove an element from the ref list
raise [Not_found] if the element is not found *)
val remove_if : ('a -> bool) -> 'a t -> unit
(** Remove the first element matching the
specified predicate
raise [Not_found] if no element has been removed *)
val remove_all : 'a t -> 'a -> unit
(** Remove all elements equal to the specified
element from the ref list *)
(** {6 Boilerplate code}*)
(** Functions that operate on the element at index [i] in a list (with
indices starting from 0).
While it is sometimes necessary to perform these
operations on lists (hence their inclusion here), the
functions were moved to an inner module to prevent
their overuse: all functions work in O(n) time. You
might prefer to use [Array] or [DynArray] for constant
time indexed element access.
*)
module Index : sig
val index_of : 'a t -> 'a -> int
(** Return the index (position : 0 starting) of an element in
a ref list, using ( = ) for testing element equality
raise [Not_found] if no element was found *)
val index : ('a -> bool) -> 'a t -> int
(** Return the index (position : 0 starting) of an element in
a ref list, using the specified comparator
raise [Not_found] if no element was found *)
val at_index : 'a t -> int -> 'a
(** Return the element of ref list at the specified index
raise [Invalid_index] if the index is outside [0 ; length-1] *)
val set : 'a t -> int -> 'a -> unit
(** Change the element at the specified index
raise [Invalid_index] if the index is outside [0 ; length-1] *)
val remove_at : 'a t -> int -> unit
(** Remove the element at the specified index
raise [Invalid_index] if the index is outside [0 ; length-1] *)
end
|