- OCaml 100%
nox-rope #
A byte sequence that can be appended to, trimmed and sliced without copying.
A protocol state machine written in a functional style keeps its send buffer
inside its state: a TCP retransmit queue, or the output buffer of SSH or TLS.
With a plain string or Buffer.t, every append or acknowledgement copies
the bytes. nox-rope is a persistent rope whose leaves are views
(string, offset, length) into immutable strings or into external memory
(Cstruct.t). Append, dropping a prefix and taking a sub-range cost
O(log n) and copy no bytes; the bytes are copied only when a caller asks for a
string, and can be handed to a Bytesrw writer or a scatter-write sink leaf
by leaf. The rope is adapted from the one in robur-coop's utcp, itself taken
from the Netsem HOL4 specification of TCP.
Install #
$ opam install nox-rope
If opam cannot find the package, it may not yet be released in the public
opam-repository. Add the overlay repository, then install it:
$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install nox-rope
Usage #
let () =
let r = Rope.(append (of_string "hello, ") "world") in
let r = Rope.shift r 7 in
assert (Rope.to_string r = "world")
Licence #
ISC. See LICENSE.md.