# Module 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 Nimrod 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.

# Types

    PRope* = ref TRope

  empty rope is represented by nil

# Procs

    proc len*(a: PRope): int {.rtl, extern: "nro$1".}

  the rope's length

    proc rope*(s: string): PRope {.rtl, extern: "nro$1Str".}

  Converts a string to a rope.

    proc rope*(i: BiggestInt): PRope {.rtl, extern: "nro$1BiggestInt".}

  Converts an int to a rope.

    proc rope*(f: BiggestFloat): PRope {.rtl, extern: "nro$1BiggestFloat".}

  Converts a float to a rope.

    proc enableCache*() {.rtl, extern: "nro$1".}

  Enables the caching of leaves. This reduces the memory footprint at the cost of runtime efficiency.

    proc disableCache*() {.rtl, extern: "nro$1".}

  the cache is discarded and disabled. The GC will reuse its used memory.

    proc `&`*(a, b: PRope): PRope {.rtl, extern: "nroConcRopeRope".}

  the concatenation operator for ropes.

    proc `&`*(a: PRope; b: string): PRope {.rtl, extern: "nroConcRopeStr".}

  the concatenation operator for ropes.

    proc `&`*(a: string; b: PRope): PRope {.rtl, extern: "nroConcStrRope".}

  the concatenation operator for ropes.

    proc `&`*(a: openarray[PRope]): PRope {.rtl, extern: "nroConcOpenArray".}

  the concatenation operator for an openarray of ropes.

    proc add*(a: var PRope; b: PRope) {.rtl, extern: "nro$1Rope".}

  adds b to the rope a.

    proc add*(a: var PRope; b: string) {.rtl, extern: "nro$1Str".}

  adds b to the rope a.

    proc `[]`*(r: PRope; i: int): char {.rtl, extern: "nroCharAt".}

  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.

    proc write*(f: TFile; r: PRope) {.rtl, extern: "nro$1".}

  writes a rope to a file.

    proc `$`*(r: PRope): string {.rtl, extern: "nroToString".}

  converts a rope back to a string.

    proc `%`*(frmt: string; args: openarray[PRope]): PRope {.rtl,
        extern: "nroFormat".}

  % substitution operator for ropes. Does not support the `$identifier` nor `${identifier}` notations.

    proc addf*(c: var PRope; frmt: string; args: openarray[PRope]) {.rtl,
        extern: "nro$1".}

  shortcut for `add(c, frmt % args)`.

    proc equalsFile*(r: PRope; f: TFile): bool {.rtl, extern: "nro$1File".}

  returns true if the contents of the file f equal r.

    proc equalsFile*(r: PRope; f: string): bool {.rtl, extern: "nro$1Str".}

  returns true if the contents of the file f equal r. If f does not exist, false is returned.

# Iterators

    iterator leaves*(r: PRope): string

  iterates over any leaf string in the rope r.

    iterator items*(r: PRope): char

  iterates over any character in the rope r.

Generated: 2012-09-23 21:47:54 UTC