Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file doubly_linked_intf.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191(** Doubly-linked lists.
Compared to other doubly-linked lists, in this one:
1. Calls to modification functions ([insert*], [move*], ...) detect if the list is
being iterated over ([iter], [fold], ...), and if so raise an exception. For example,
a use like the following would raise:
{[
iter t ~f:(fun _ -> ... remove t e ...)
]}
2. There is a designated "front" and "back" of each list, rather than viewing each
element as an equal in a ring.
3. Elements know which list they're in. Each operation that takes an [Elt.t] also
takes a [t], first checks that the [Elt] belongs to the [t], and if not, raises.
4. Related to (3), lists cannot be split, though a sort of splicing is available as
[transfer]. In other words, no operation will cause one list to become two. This
makes this module unsuitable for maintaining the faces of a planar graph under edge
insertion and deletion, for example.
5. Another property permitted by (3) and (4) is that [length] is O(1). *)open!ImportmoduletypeS=sigmoduleElt:sigtype'atvalvalue:'at->'a(** pointer equality *)valequal:'at->'at->boolvalset:'at->'a->unitvalsexp_of_t:('a->Base.Sexp.t)->'at->Base.Sexp.tendtype'at[@@derivingcompare,sexp,sexp_grammar]includeContainer.S1withtype'at:='atincludeInvariant.S1withtype'at:='at(** {2 Creating doubly-linked lists} *)valcreate:unit->'at(** [of_list l] returns a doubly-linked list [t] with the same elements as [l] and in
the same order (i.e., the first element of [l] is the first element of [t]). It is
always the case that [l = to_list (of_list l)]. *)valof_list:'alist->'atvalof_array:'aarray->'at(** {2 Predicates} *)(** pointer equality *)valequal:'at->'at->boolvalis_first:'at->'aElt.t->boolvalis_last:'at->'aElt.t->boolvalmem_elt:'at->'aElt.t->bool(** {2 Constant-time extraction of first and last elements} *)valfirst_elt:'at->'aElt.toptionvallast_elt:'at->'aElt.toptionvalfirst:'at->'aoptionvallast:'at->'aoptionvalfirst_exn:'at->'avallast_exn:'at->'a(** {2 Constant-time retrieval of next or previous element} *)valnext:'at->'aElt.t->'aElt.toptionvalprev:'at->'aElt.t->'aElt.toption(** {2 Constant-time insertion of a new element} *)valinsert_before:'at->'aElt.t->'a->'aElt.tvalinsert_after:'at->'aElt.t->'a->'aElt.tvalinsert_first:'at->'a->'aElt.tvalinsert_last:'at->'a->'aElt.t(** {2 Constant-time move of an element from and to positions in the same list}
An exception is raised if [elt] is equal to [anchor]. *)valmove_to_front:'at->'aElt.t->unitvalmove_to_back:'at->'aElt.t->unitvalmove_after:'at->'aElt.t->anchor:'aElt.t->unitvalmove_before:'at->'aElt.t->anchor:'aElt.t->unit(** {2 Constant-time removal of an element} *)valremove:'at->'aElt.t->unitvalremove_first:'at->'aoptionvalremove_last:'at->'aoptionvaliteri:'at->f:(int->'a->unit)->unitvalfoldi:'at->init:'acc->f:(int->'acc->'a->'acc)->'acc(** [fold_elt t ~init ~f] is the same as fold, except [f] is called with the ['a
Elt.t]'s from the list instead of the contained ['a] values.
Note that like other iteration functions, it is an error to mutate [t] inside the
fold. If you'd like to call [remove] on any of the ['a Elt.t]'s, use
[filter_inplace]. *)valfold_elt:'at->init:'acc->f:('acc->'aElt.t->'acc)->'accvalfoldi_elt:'at->init:'acc->f:(int->'acc->'aElt.t->'acc)->'accvaliter_elt:'at->f:('aElt.t->unit)->unitvaliteri_elt:'at->f:(int->'aElt.t->unit)->unitvalfold_right:'at->init:'acc->f:('a->'acc->'acc)->'accvalfold_right_elt:'at->init:'acc->f:('aElt.t->'acc->'acc)->'acc(** [find_elt t ~f] finds the first element in [t] that satisfies [f], by testing each
of element of [t] in turn until [f] succeeds. *)valfind_elt:'at->f:('a->bool)->'aElt.toptionvalfindi_elt:'at->f:(int->'a->bool)->(int*'aElt.t)option(** [clear t] removes all elements from the list in constant time. *)valclear:'at->unitvalcopy:'at->'at(** [transfer ~src ~dst] has the same behavior as
[iter src ~f:(insert_last dst); clear src] except that it runs in constant time.
If [s = to_list src] and [d = to_list dst], then after [transfer ~src ~dst]:
[to_list src = []]
[to_list dst = d @ s] *)valtransfer:src:'at->dst:'at->unit(** {2 Linear-time mapping of lists (creates a new list)} *)valmap:'at->f:('a->'b)->'btvalmapi:'at->f:(int->'a->'b)->'btvalfilter:'at->f:('a->bool)->'atvalfilteri:'at->f:(int->'a->bool)->'atvalfilter_map:'at->f:('a->'boption)->'btvalfilter_mapi:'at->f:(int->'a->'boption)->'bt(** {2 Linear-time partition of lists (creates two new lists)} *)valpartition_tf:'at->f:('a->bool)->'at*'atvalpartitioni_tf:'at->f:(int->'a->bool)->'at*'atvalpartition_map:'at->f:('a->('b,'c)Either.t)->'bt*'ctvalpartition_mapi:'at->f:(int->'a->('b,'c)Either.t)->'bt*'ct(** {2 Linear-time in-place mapping of lists} *)(** [map_inplace t ~f] replaces all values [v] with [f v] *)valmap_inplace:'at->f:('a->'a)->unitvalmapi_inplace:'at->f:(int->'a->'a)->unit(** [filter_inplace t ~f] removes all elements of [t] that don't satisfy [f]. *)valfilter_inplace:'at->f:('a->bool)->unitvalfilteri_inplace:'at->f:(int->'a->bool)->unit(** If [f] returns [None], the element is removed, else the value is replaced with the
contents of the [Some] *)valfilter_map_inplace:'at->f:('a->'aoption)->unitvalfilter_mapi_inplace:'at->f:(int->'a->'aoption)->unit(** [unchecked_iter t ~f] behaves like [iter t ~f] except that [f] is allowed to modify
[t]. Adding or removing elements before the element currently being visited has no
effect on the traversal. Elements added after the element currently being visited
will be traversed. Elements deleted after the element currently being visited will
not be traversed. Deleting the element currently being visited is an error that is
not detected (presumably leading to an infinite loop). *)valunchecked_iter:'at->f:('a->unit)->unit(** A sequence of values from the doubly-linked list. It makes an intermediate copy of
the list so that the returned sequence is immune to any subsequent mutation of the
original list. *)valto_sequence:'at->'aSequence.tendmoduletypeDoubly_linked=sigmoduletypeS=SincludeSend