package batteries
Install
Dune Dependency
Authors
Maintainers
Sources
md5=ea26b5c72e6731e59d856626049cca4d
sha512=55975b62c26f6db77433a3ac31f97af609fc6789bb62ac38b267249c78fd44ff37fe81901f1cf560857b9493a6046dd37b0d1c0234c66bd59e52843aac3ce6cb
doc/batteries.unthreaded/BatDllist/index.html
Module BatDllist
Source
A mutable, imperative, circular, doubly linked list library
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).
Note This implementation of doubly-linked lists does not support empty lists.
include BatInterfaces.Mappable with type 'a mappable = 'a t
include BatEnum.Enumerable with type 'a enumerable = 'a t
node functions
Copy the list attached to the given node and return the copy of the given node. This is an O(N) operation.
List reversal. This is an O(N) operation. The given node still points to the same element, so to_list (rev (of_list [1;2;3;4])) = [1;4;3;2]
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.
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.
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.
Remove node from the list no matter where it is. This is an O(1) operation.
Remove node from the list no matter where it is. Return next node. This is an O(1) operation.
Remove node from the list no matter where it is. Return previous node. This is an O(1) operation.
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.
Given a node, get the data associated with that node. This is an O(1) operation.
Given a node, set the data associated with that node. This is an O(1) operation.
Given a node, get the next element in the list after the node.
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.
Given a node, get the previous element in the list before the node.
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.
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.
iter f n
Apply f
to every element in the list, starting at n
. This is an O(N) operation.
Accumulate a value over the entire list. This works like List.fold_left. This is an O(N) operation.
Accumulate a value over the entire list. This works like List.fold_right, but since the list is bidirectional, it doesn't suffer the performance problems of List.fold_right. This is an O(N) operation.
find p l
returns the first element, l
or after, for which p
returns true.
Test whether a given predicate returns true for all members of the given list. O(N)
Test whether there exists an element of the given list for which the predicate returns true. O(N)
Allocate a new list, with entirely new nodes, whose values are the transforms of the values of the original list. Note that this does not modify the given list. This is an O(N) operation.
filter p l
returns a new list, with entirely new nodes, whose values are all the elements of the list l
that satisfy the predicate p
. The order of the elements in the input list is preserved.
filter_map f l
calls (f a0) (f a1) ... (f an)
where a0,a1...an
are the elements of l
. It returns a new list of elements bi
such as f ai = Some bi
(when f
returns None
, the corresponding element of l
is discarded).
list conversion
Converts a dllist to a normal list. This is an O(N) operation.
Converts from a normal list to a Dllist and returns the first node.
enums
Create an enum of the list. Note that modifying the list while the enum exists will have undefined effects. This is an O(1) operation.
Create a reverse enum of the list. The enumeration starts with the current element of the list: rev_enum (of_list [1;2;3;4])
will generate the enumeration [1;4;3;2]
.
If you want it to start with the last one, see backwards
.
Note that modifying the list while the enum exists will have undefined effects. This is an O(1) operation.
backwards t
is similar to rev_enum t
except that the enumeration starts at the node before the current one:
backwards (of_list [1;2;3;4])
will generate the enumeration [4;3;2;1]
.
Create a dllist from an enum. This consumes the enum, and allocates a whole new dllist.
Boilerplate code
Printing
val print :
?first:string ->
?last:string ->
?sep:string ->
('a BatInnerIO.output -> 'b -> unit) ->
'a BatInnerIO.output ->
'b t ->
unit