|
rpm-build |
0f2925 |
(*
|
|
rpm-build |
0f2925 |
* RefList - List reference
|
|
rpm-build |
0f2925 |
* Copyright (C) 2003 Nicolas Cannasse
|
|
rpm-build |
0f2925 |
*
|
|
rpm-build |
0f2925 |
* This library is free software; you can redistribute it and/or
|
|
rpm-build |
0f2925 |
* modify it under the terms of the GNU Lesser General Public
|
|
rpm-build |
0f2925 |
* License as published by the Free Software Foundation; either
|
|
rpm-build |
0f2925 |
* version 2.1 of the License, or (at your option) any later version,
|
|
rpm-build |
0f2925 |
* with the special exception on linking described in file LICENSE.
|
|
rpm-build |
0f2925 |
*
|
|
rpm-build |
0f2925 |
* This library is distributed in the hope that it will be useful,
|
|
rpm-build |
0f2925 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
rpm-build |
0f2925 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
rpm-build |
0f2925 |
* Lesser General Public License for more details.
|
|
rpm-build |
0f2925 |
*
|
|
rpm-build |
0f2925 |
* You should have received a copy of the GNU Lesser General Public
|
|
rpm-build |
0f2925 |
* License along with this library; if not, write to the Free Software
|
|
rpm-build |
0f2925 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
rpm-build |
0f2925 |
*)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
(** Reference on lists.
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
RefList is a extended set of functions that manipulate list
|
|
rpm-build |
0f2925 |
references.
|
|
rpm-build |
0f2925 |
*)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
exception Empty_list
|
|
rpm-build |
0f2925 |
exception Invalid_index of int
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
type 'a t
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val empty : unit -> 'a t
|
|
rpm-build |
0f2925 |
(** Returns a new empty ref list *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val is_empty : 'a t -> bool
|
|
rpm-build |
0f2925 |
(** Return [true] if a ref list is empty *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val clear : 'a t -> unit
|
|
rpm-build |
0f2925 |
(** Removes all elements *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val length : 'a t -> int
|
|
rpm-build |
0f2925 |
(** Returns the number of elements - O(n) *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val copy : dst:'a t -> src:'a t -> unit
|
|
rpm-build |
0f2925 |
(** Makes a copy of a ref list - O(1) *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val copy_list : dst:'a t -> src:'a list -> unit
|
|
rpm-build |
0f2925 |
(** Makes a copy of a list - O(1) *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val copy_enum : dst:'a t -> src:'a Enum.t -> unit
|
|
rpm-build |
0f2925 |
(** Makes a copy of a enum *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val of_list : 'a list -> 'a t
|
|
rpm-build |
0f2925 |
(** Creates a ref list from a list - O(1) *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val to_list : 'a t -> 'a list
|
|
rpm-build |
0f2925 |
(** Returns the current elements as a list - O(1) *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val of_enum : 'a Enum.t -> 'a t
|
|
rpm-build |
0f2925 |
(** Creates a ref list from an enumeration *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val enum : 'a t -> 'a Enum.t
|
|
rpm-build |
0f2925 |
(** Returns an enumeration of current elements in the ref list *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val add : 'a t -> 'a -> unit
|
|
rpm-build |
0f2925 |
(** Adds an element at the end - O(n) *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val push : 'a t -> 'a -> unit
|
|
rpm-build |
0f2925 |
(** Adds an element at the head - O(1) *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val add_sort : ?cmp:('a -> 'a -> int) -> 'a t -> 'a -> unit
|
|
rpm-build |
0f2925 |
(** Adds an element in a sorted list, using optional comparator
|
|
rpm-build |
0f2925 |
or 'compare' as default. *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val first : 'a t -> 'a
|
|
rpm-build |
0f2925 |
(** Returns the first element or
|
|
rpm-build |
0f2925 |
raises [Empty_list] if the ref list is empty *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val last : 'a t -> 'a
|
|
rpm-build |
0f2925 |
(** Returns the last element - O(n) or
|
|
rpm-build |
0f2925 |
raises Empty_list if the ref list is empty *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val pop : 'a t -> 'a
|
|
rpm-build |
0f2925 |
(** Removes and returns the first element or
|
|
rpm-build |
0f2925 |
raises [Empty_list] if the ref list is empty *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val npop : 'a t -> int -> 'a list
|
|
rpm-build |
0f2925 |
(** Removes and returns the n first elements or
|
|
rpm-build |
0f2925 |
raises [Empty_list] if the ref list does not
|
|
rpm-build |
0f2925 |
contain enough elements *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val hd : 'a t -> 'a
|
|
rpm-build |
0f2925 |
(** same as [first] *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val tl : 'a t -> 'a t
|
|
rpm-build |
0f2925 |
(** Returns a ref list containing the same elements
|
|
rpm-build |
0f2925 |
but without the first one or
|
|
rpm-build |
0f2925 |
raises [Empty_list] if the ref list is empty *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val rev : 'a t -> unit
|
|
rpm-build |
0f2925 |
(** Reverses the ref list - O(n) *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
(** {6 Functional Operations} *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val iter : ('a -> unit) -> 'a t -> unit
|
|
rpm-build |
0f2925 |
(** Apply the given function to all elements of the
|
|
rpm-build |
0f2925 |
ref list, in respect with the order of the list *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val find : ('a -> bool) -> 'a t -> 'a
|
|
rpm-build |
0f2925 |
(** Find the first element matching
|
|
rpm-build |
0f2925 |
the specified predicate
|
|
rpm-build |
0f2925 |
raise [Not_found] if no element is found *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val rfind : ('a -> bool) -> 'a t -> 'a
|
|
rpm-build |
0f2925 |
(** Find the first element in the reversed ref list matching
|
|
rpm-build |
0f2925 |
the specified predicate
|
|
rpm-build |
0f2925 |
raise [Not_found] if no element is found *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val find_exc : ('a -> bool) -> exn -> 'a t -> 'a
|
|
rpm-build |
0f2925 |
(** Same as find but takes an exception to be raised when
|
|
rpm-build |
0f2925 |
no element is found as additional parameter *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val exists : ('a -> bool) -> 'a t -> bool
|
|
rpm-build |
0f2925 |
(** Return [true] if an element matches the specified
|
|
rpm-build |
0f2925 |
predicate *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val for_all : ('a -> bool) -> 'a t -> bool
|
|
rpm-build |
0f2925 |
(** Return [true] if all elements match the specified
|
|
rpm-build |
0f2925 |
predicate *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val map : ('a -> 'b) -> 'a t -> 'b t
|
|
rpm-build |
0f2925 |
(** Apply a function to all elements
|
|
rpm-build |
0f2925 |
and return the ref list constructed with
|
|
rpm-build |
0f2925 |
the function returned values *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val transform : ('a -> 'a) -> 'a t -> unit
|
|
rpm-build |
0f2925 |
(** transform all elements in the ref list
|
|
rpm-build |
0f2925 |
using a function. *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val map_list : ('a -> 'b) -> 'a t -> 'b list
|
|
rpm-build |
0f2925 |
(** Apply a function to all elements
|
|
rpm-build |
0f2925 |
and return the list constructed with
|
|
rpm-build |
0f2925 |
the function returned values *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val sort : ?cmp:('a -> 'a -> int) -> 'a t -> unit
|
|
rpm-build |
0f2925 |
(** Sort elements using the specified comparator
|
|
rpm-build |
0f2925 |
or compare as default comparator *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val filter : ('a -> bool) -> 'a t -> unit
|
|
rpm-build |
0f2925 |
(** Remove all elements that do not match the
|
|
rpm-build |
0f2925 |
specified predicate *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val remove : 'a t -> 'a -> unit
|
|
rpm-build |
0f2925 |
(** Remove an element from the ref list
|
|
rpm-build |
0f2925 |
raise [Not_found] if the element is not found *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val remove_if : ('a -> bool) -> 'a t -> unit
|
|
rpm-build |
0f2925 |
(** Remove the first element matching the
|
|
rpm-build |
0f2925 |
specified predicate
|
|
rpm-build |
0f2925 |
raise [Not_found] if no element has been removed *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val remove_all : 'a t -> 'a -> unit
|
|
rpm-build |
0f2925 |
(** Remove all elements equal to the specified
|
|
rpm-build |
0f2925 |
element from the ref list *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
(** Functions that operate on the [i]th element of a list.
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
While it is sometimes necessary to perform these
|
|
rpm-build |
0f2925 |
operations on lists (hence their inclusion here), the
|
|
rpm-build |
0f2925 |
functions were moved to an inner module to prevent
|
|
rpm-build |
0f2925 |
their overuse: all functions work in O(n) time. You
|
|
rpm-build |
0f2925 |
might prefer to use [Array] or [DynArray] for constant
|
|
rpm-build |
0f2925 |
time indexed element access.
|
|
rpm-build |
0f2925 |
*)
|
|
rpm-build |
0f2925 |
module Index : sig
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val index_of : 'a t -> 'a -> int
|
|
rpm-build |
0f2925 |
(** Return the index (position : 0 starting) of an element in
|
|
rpm-build |
0f2925 |
a ref list, using ( = ) for testing element equality
|
|
rpm-build |
0f2925 |
raise [Not_found] if no element was found *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val index : ('a -> bool) -> 'a t -> int
|
|
rpm-build |
0f2925 |
(** Return the index (position : 0 starting) of an element in
|
|
rpm-build |
0f2925 |
a ref list, using the specified comparator
|
|
rpm-build |
0f2925 |
raise [Not_found] if no element was found *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val at_index : 'a t -> int -> 'a
|
|
rpm-build |
0f2925 |
(** Return the element of ref list at the specified index
|
|
rpm-build |
0f2925 |
raise [Invalid_index] if the index is outside [0 ; length-1] *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val set : 'a t -> int -> 'a -> unit
|
|
rpm-build |
0f2925 |
(** Change the element at the specified index
|
|
rpm-build |
0f2925 |
raise [Invalid_index] if the index is outside [0 ; length-1] *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
val remove_at : 'a t -> int -> unit
|
|
rpm-build |
0f2925 |
(** Remove the element at the specified index
|
|
rpm-build |
0f2925 |
raise [Invalid_index] if the index is outside [0 ; length-1] *)
|
|
rpm-build |
0f2925 |
|
|
rpm-build |
0f2925 |
end
|