This module contains support for a rope data type. Ropes can represent very long strings efficiently; especially concatenation is done in O(1) instead of O(n). They are essentially concatenation trees that are only flattened when converting to a native Nim string. The empty string is represented by nil
. Ropes are immutable and subtrees can be shared without copying. Leaves can be cached for better memory efficiency at the cost of runtime efficiency.
Rope = ref RopeObj
proc len(a: Rope): int {.gcsafe, extern: "nro$1", raises: [], tags: [].}
proc rope(s: string): Rope {.gcsafe, extern: "nro$1Str", raises: [], tags: [].}
proc rope(i: BiggestInt): Rope {.gcsafe, extern: "nro$1BiggestInt", raises: [], tags: [].}
proc rope(f: BiggestFloat): Rope {.gcsafe, extern: "nro$1BiggestFloat", raises: [], tags: [].}
proc enableCache() {.gcsafe, extern: "nro$1", raises: [], tags: [].}
proc disableCache() {.gcsafe, extern: "nro$1", raises: [], tags: [].}
proc `&`(a, b: Rope): Rope {.gcsafe, extern: "nroConcRopeRope", raises: [], tags: [].}
proc `&`(a: Rope; b: string): Rope {.gcsafe, extern: "nroConcRopeStr", raises: [], tags: [].}
proc `&`(a: string; b: Rope): Rope {.gcsafe, extern: "nroConcStrRope", raises: [], tags: [].}
proc `&`(a: openArray[Rope]): Rope {.gcsafe, extern: "nroConcOpenArray", raises: [], tags: [].}
proc add(a: var Rope; b: Rope) {.gcsafe, extern: "nro$1Rope", raises: [], tags: [].}
proc add(a: var Rope; b: string) {.gcsafe, extern: "nro$1Str", raises: [], tags: [].}
proc `[]`(r: Rope; i: int): char {.gcsafe, extern: "nroCharAt", raises: [], tags: [].}
i >= r.len
, \0
is returned. proc write(f: File; r: Rope) {.gcsafe, extern: "nro$1", raises: [IOError], tags: [WriteIOEffect].}
proc `$`(r: Rope): string {.gcsafe, extern: "nroToString", raises: [], tags: [].}
proc `%`(frmt: string; args: openArray[Rope]): Rope {.gcsafe, extern: "nroFormat", raises: [ValueError], tags: [].}
$identifier
nor ${identifier}
notations. proc addf(c: var Rope; frmt: string; args: openArray[Rope]) {.gcsafe, extern: "nro$1", raises: [ValueError], tags: [].}
add(c, frmt % args)
. proc equalsFile(r: Rope; f: File): bool {.gcsafe, extern: "nro$1File", raises: [IOError], tags: [ReadIOEffect].}
proc equalsFile(r: Rope; filename: string): bool {.gcsafe, extern: "nro$1Str", raises: [IOError], tags: [ReadIOEffect].}
iterator leaves(r: Rope): string {.raises: [], tags: [].}
iterator items(r: Rope): char {.raises: [], tags: [].}
© 2006–2017 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/ropes.html