ropes

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
empty rope is represented by nil   Source Edit

プロシージャ

proc len(a: Rope): int {...}{.gcsafe, extern: "nro$1", raises: [], tags: [].}
the rope's length   Source Edit
proc rope(s: string = ""): Rope {...}{.gcsafe, extern: "nro$1Str", raises: [], tags: [].}
Converts a string to a rope.   ソース 編集
proc rope(i: BiggestInt): Rope {...}{.gcsafe, extern: "nro$1BiggestInt", raises: [], tags: [].}
Converts an int to a rope.   ソース 編集
proc rope(f: BiggestFloat): Rope {...}{.gcsafe, extern: "nro$1BiggestFloat", raises: [],
                               tags: [].}
Converts a float to a rope.   ソース 編集
proc enableCache() {...}{.gcsafe, extern: "nro$1", raises: [], tags: [].}
Enables the caching of leaves. This reduces the memory footprint at the cost of runtime efficiency.   ソース 編集
proc disableCache() {...}{.gcsafe, extern: "nro$1", raises: [], tags: [].}
the cache is discarded and disabled. The GC will reuse its used memory.   ソース 編集
proc `&`(a, b: Rope): Rope {...}{.gcsafe, extern: "nroConcRopeRope", raises: [], tags: [].}
the concatenation operator for ropes.   ソース 編集
proc `&`(a: Rope; b: string): Rope {...}{.gcsafe, extern: "nroConcRopeStr", raises: [], tags: [].}
the concatenation operator for ropes.   ソース 編集
proc `&`(a: string; b: Rope): Rope {...}{.gcsafe, extern: "nroConcStrRope", raises: [], tags: [].}
the concatenation operator for ropes.   ソース 編集
proc `&`(a: openArray[Rope]): Rope {...}{.gcsafe, extern: "nroConcOpenArray", raises: [],
                                 tags: [].}
the concatenation operator for an openarray of ropes.   ソース 編集
proc add(a: var Rope; b: Rope) {...}{.gcsafe, extern: "nro$1Rope", raises: [], tags: [].}
adds b to the rope a.   ソース 編集
proc add(a: var Rope; b: string) {...}{.gcsafe, extern: "nro$1Str", raises: [], tags: [].}
adds b to the rope a.   ソース 編集
proc `[]`(r: Rope; i: int): char {...}{.gcsafe, extern: "nroCharAt", raises: [], tags: [].}
returns the character at position i in the rope r. This is quite expensive! Worst-case: O(n). If i >= r.len, \0 is returned.   Source Edit
proc write(f: File; r: Rope) {...}{.gcsafe, extern: "nro$1", raises: [IOError],
                          tags: [WriteIOEffect].}
writes a rope to a file.   ソース 編集
proc write(s: Stream; r: Rope) {...}{.gcsafe, extern: "nroWriteStream",
                            raises: [Defect, IOError, OSError],
                            tags: [WriteIOEffect].}
writes a rope to a stream.   ソース 編集
proc `$`(r: Rope): string {...}{.gcsafe, extern: "nroToString", raises: [], tags: [].}
converts a rope back to a string.   ソース 編集
proc `%`(frmt: string; args: openArray[Rope]): Rope {...}{.gcsafe, extern: "nroFormat",
    raises: [ValueError], tags: [].}
% substitution operator for ropes. Does not support the $identifier nor ${identifier} notations.   ソース 編集
proc addf(c: var Rope; frmt: string; args: openArray[Rope]) {...}{.gcsafe, extern: "nro$1",
    raises: [ValueError], tags: [].}
shortcut for add(c, frmt % args).   ソース 編集
proc equalsFile(r: Rope; f: File): bool {...}{.gcsafe, extern: "nro$1File", raises: [IOError],
                                    tags: [ReadIOEffect].}
returns true if the contents of the file f equal r.   ソース 編集
proc equalsFile(r: Rope; filename: string): bool {...}{.gcsafe, extern: "nro$1Str",
    raises: [IOError], tags: [ReadIOEffect].}
returns true if the contents of the file f equal r. If f does not exist, false is returned.   ソース 編集

イテレータ

iterator leaves(r: Rope): string {...}{.raises: [], tags: [].}
iterates over any leaf string in the rope r.   ソース 編集
iterator items(r: Rope): char {...}{.raises: [], tags: [].}
iterates over any character in the rope r.   ソース 編集