module Dllist:A mutable, imperative, circular, doubly linked list librarysig
..end
This module implements a doubly linked list in a mutable or imperitive
style (changes to the list are visible to all copies of the list).
type 'a
node_t
exception Empty
val create : 'a -> 'a node_t
val copy : 'a node_t -> 'a node_t
val length : 'a node_t -> int
val rev : 'a node_t -> unit
val add : 'a node_t -> 'a -> unit
add n a
Creates a new node containing data a
and inserts it into
the list after node n
. This is an O(1) operation.val append : 'a node_t -> 'a -> 'a node_t
append n a
Creates a new node containing data a
and inserts it into
the list after node n
. Returns new node. This is an O(1) operation.val prepend : 'a node_t -> 'a -> 'a node_t
prepend n a
Creates a new node containing data a
and inserts it into
the list before node n
. Returns new node. This is an O(1) operation.val promote : 'a node_t -> unit
promote n
Swaps n
with next n
. This is an O(1) operation.val demote : 'a node_t -> unit
demote n
Swaps n
with prev n
. This is an O(1) operation.val remove : 'a node_t -> unit
val drop : 'a node_t -> 'a node_t
val rev_drop : 'a node_t -> 'a node_t
val splice : 'a node_t -> 'a node_t -> unit
splice n1 n2
Connects n1
and n2
so that
next n1 == n2 && prev n2 == n1
. This can be used to connect two discrete
lists, or, if used on two nodes within the same list, it can be used to
separate the nodes between n1
and n2
from the rest of the list. In this
case, those nodes become a discrete list by themselves. This is an O(1)
operation.val get : 'a node_t -> 'a
val set : 'a node_t -> 'a -> unit
val next : 'a node_t -> 'a node_t
The list is circular, so the last node of the list returns the first node of the list as it's next node.
This is an O(1) operation.
val prev : 'a node_t -> 'a node_t
The list is circular, so the first node of the list returns the last element of the list as it's previous node.
This is an O(1) operation.
val skip : 'a node_t -> int -> 'a node_t
skip n i
Return the node that is i
nodes after node n
in the list.
If i
is negative then return the node that is i
nodes before node n
in the list. This is an O(N) operation.val iter : ('a -> unit) -> 'a node_t -> unit
iter f n
Apply f
to every element in the list, starting at n
. This
is an O(N) operation.val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b node_t -> 'a
val fold_right : ('a -> 'b -> 'b) -> 'a node_t -> 'b -> 'b
val map : ('a -> 'b) -> 'a node_t -> 'b node_t
val to_list : 'a node_t -> 'a list
val of_list : 'a list -> 'a node_t
Empty
if given list is empty. This is an O(N) operation.val enum : 'a node_t -> 'a Enum.t
val rev_enum : 'a node_t -> 'a Enum.t
val of_enum : 'a Enum.t -> 'a node_t
Empty
if given enum is empty. This is an O(N) operation.