From: Nicolas C. <war...@fr...> - 2003-02-26 02:01:49
|
Hi ext-list, Here's my mutable list interface. Implementation is available and mostly use the standard List library function. Mutable lists with in place modifications are very usable each time you were previously using "list ref" I'm not putting any documentation with the interface, since every not obvious function can be considered as to be removed or changed. It also provide a set of functions based on item index in the list ( i'm using this, but i'm not really sure it should be in the ExtLib MList... or perhaps in an inner module ) I'm waiting for your comments. Nicolas Cannasse ------------------------------------------------------------------- exception Invalid_index of int exception No_such_element module MList : sig type 'a t val empty : unit -> 'a t val isempty : 'a t -> bool val copy : 'a t -> 'a t -> unit val copy_list : 'a t -> 'a list -> unit val from_list : 'a list -> 'a t val to_list : 'a t -> 'a list val add : 'a t -> 'a -> unit val push : 'a t -> 'a -> unit val pop : 'a t -> 'a (* raise No_such_element *) val last : 'a t -> 'a (* raise No_such_element *) val first : 'a t -> 'a (* raise No_such_element *) val npop : 'a t -> int -> 'a list (* raise No_such_element *) val clear : 'a t -> unit val length : 'a t -> int val add_sort : ('a -> 'a -> int) -> 'a t -> 'a -> unit val hd : 'a t -> 'a (* raise No_such_element *) val tl : 'a t -> 'a list (* raise No_such_element *) val iter : ('a -> unit) -> 'a t -> unit val find : ('a -> bool) -> 'a t -> 'a val find_ex : ('a -> bool) -> 'a t -> exn -> 'a val exists : ('a -> bool) -> 'a t -> bool val map : ('a -> 'b) -> 'a t -> 'b list val sort : ('a -> 'a -> int) -> 'a t -> unit val filter : ('a -> bool) -> 'a t -> unit val shuffle : 'a t -> unit val remove : 'a t -> 'a -> unit (* only one element removed, tested with ( = ), raise Not_found *) val remove_if : ('a -> bool) -> 'a t -> unit (* indexes functions *) val index_of : 'a t -> 'a -> int (* raise Not_found *) val at_index : 'a t -> int -> 'a (* raise Invalid_index *) val index_of_with : ('a -> bool) -> 'a t -> int (* raise Not_found *) val set : 'a t -> int -> 'a -> unit (* raise Invalid_index *) val remove_at_index : 'a t -> int -> unit (* raise Invalid_index *) end |