big rename
This commit is contained in:
parent
15a7bcc89f
commit
11b6958755
98 changed files with 2491 additions and 2341 deletions
|
|
@ -1,6 +1,6 @@
|
|||
#
|
||||
#
|
||||
# Nimrod's Runtime Library
|
||||
# Nim's Runtime Library
|
||||
# (c) Copyright 2010 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
|
|
@ -30,13 +30,15 @@ var
|
|||
cacheEnabled = false
|
||||
|
||||
type
|
||||
PRope* = ref TRope ## empty rope is represented by nil
|
||||
TRope {.acyclic, final, pure.} = object
|
||||
left, right: PRope
|
||||
Rope* = ref RopeObj ## empty rope is represented by nil
|
||||
RopeObj {.acyclic.} = object
|
||||
left, right: Rope
|
||||
length: int
|
||||
data: string # != nil if a leaf
|
||||
|
||||
proc isConc(r: PRope): bool {.inline.} = return isNil(r.data)
|
||||
{.deprecated: [PRope: Rope].}
|
||||
|
||||
proc isConc(r: Rope): bool {.inline.} = return isNil(r.data)
|
||||
|
||||
# Note that the left and right pointers are not needed for leafs.
|
||||
# Leaves have relatively high memory overhead (~30 bytes on a 32
|
||||
|
|
@ -46,25 +48,25 @@ proc isConc(r: PRope): bool {.inline.} = return isNil(r.data)
|
|||
# performance. But for the caching tree we use the leaf's left and right
|
||||
# pointers.
|
||||
|
||||
proc len*(a: PRope): int {.rtl, extern: "nro$1".} =
|
||||
proc len*(a: Rope): int {.rtl, extern: "nro$1".} =
|
||||
## the rope's length
|
||||
if a == nil: result = 0
|
||||
else: result = a.length
|
||||
|
||||
proc newRope(): PRope = new(result)
|
||||
proc newRope(data: string): PRope =
|
||||
proc newRope(): Rope = new(result)
|
||||
proc newRope(data: string): Rope =
|
||||
new(result)
|
||||
result.length = len(data)
|
||||
result.data = data
|
||||
|
||||
var
|
||||
cache {.threadvar.}: PRope # the root of the cache tree
|
||||
N {.threadvar.}: PRope # dummy rope needed for splay algorithm
|
||||
cache {.threadvar.}: Rope # the root of the cache tree
|
||||
N {.threadvar.}: Rope # dummy rope needed for splay algorithm
|
||||
|
||||
when countCacheMisses:
|
||||
var misses, hits: int
|
||||
|
||||
proc splay(s: string, tree: PRope, cmpres: var int): PRope =
|
||||
proc splay(s: string, tree: Rope, cmpres: var int): Rope =
|
||||
var c: int
|
||||
var t = tree
|
||||
N.left = nil
|
||||
|
|
@ -102,7 +104,7 @@ proc splay(s: string, tree: PRope, cmpres: var int): PRope =
|
|||
t.right = N.left
|
||||
result = t
|
||||
|
||||
proc insertInCache(s: string, tree: PRope): PRope =
|
||||
proc insertInCache(s: string, tree: Rope): Rope =
|
||||
var t = tree
|
||||
if t == nil:
|
||||
result = newRope(s)
|
||||
|
|
@ -128,7 +130,7 @@ proc insertInCache(s: string, tree: PRope): PRope =
|
|||
result.left = t
|
||||
t.right = nil
|
||||
|
||||
proc rope*(s: string): PRope {.rtl, extern: "nro$1Str".} =
|
||||
proc rope*(s: string): Rope {.rtl, extern: "nro$1Str".} =
|
||||
## Converts a string to a rope.
|
||||
if s.len == 0:
|
||||
result = nil
|
||||
|
|
@ -138,11 +140,11 @@ proc rope*(s: string): PRope {.rtl, extern: "nro$1Str".} =
|
|||
else:
|
||||
result = newRope(s)
|
||||
|
||||
proc rope*(i: BiggestInt): PRope {.rtl, extern: "nro$1BiggestInt".} =
|
||||
proc rope*(i: BiggestInt): Rope {.rtl, extern: "nro$1BiggestInt".} =
|
||||
## Converts an int to a rope.
|
||||
result = rope($i)
|
||||
|
||||
proc rope*(f: BiggestFloat): PRope {.rtl, extern: "nro$1BiggestFloat".} =
|
||||
proc rope*(f: BiggestFloat): Rope {.rtl, extern: "nro$1BiggestFloat".} =
|
||||
## Converts a float to a rope.
|
||||
result = rope($f)
|
||||
|
||||
|
|
@ -156,7 +158,7 @@ proc disableCache*() {.rtl, extern: "nro$1".} =
|
|||
cache = nil
|
||||
cacheEnabled = false
|
||||
|
||||
proc `&`*(a, b: PRope): PRope {.rtl, extern: "nroConcRopeRope".} =
|
||||
proc `&`*(a, b: Rope): Rope {.rtl, extern: "nroConcRopeRope".} =
|
||||
## the concatenation operator for ropes.
|
||||
if a == nil:
|
||||
result = b
|
||||
|
|
@ -176,27 +178,27 @@ proc `&`*(a, b: PRope): PRope {.rtl, extern: "nroConcRopeRope".} =
|
|||
result.left = a
|
||||
result.right = b
|
||||
|
||||
proc `&`*(a: PRope, b: string): PRope {.rtl, extern: "nroConcRopeStr".} =
|
||||
proc `&`*(a: Rope, b: string): Rope {.rtl, extern: "nroConcRopeStr".} =
|
||||
## the concatenation operator for ropes.
|
||||
result = a & rope(b)
|
||||
|
||||
proc `&`*(a: string, b: PRope): PRope {.rtl, extern: "nroConcStrRope".} =
|
||||
proc `&`*(a: string, b: Rope): Rope {.rtl, extern: "nroConcStrRope".} =
|
||||
## the concatenation operator for ropes.
|
||||
result = rope(a) & b
|
||||
|
||||
proc `&`*(a: openarray[PRope]): PRope {.rtl, extern: "nroConcOpenArray".} =
|
||||
proc `&`*(a: openarray[Rope]): Rope {.rtl, extern: "nroConcOpenArray".} =
|
||||
## the concatenation operator for an openarray of ropes.
|
||||
for i in countup(0, high(a)): result = result & a[i]
|
||||
|
||||
proc add*(a: var PRope, b: PRope) {.rtl, extern: "nro$1Rope".} =
|
||||
proc add*(a: var Rope, b: Rope) {.rtl, extern: "nro$1Rope".} =
|
||||
## adds `b` to the rope `a`.
|
||||
a = a & b
|
||||
|
||||
proc add*(a: var PRope, b: string) {.rtl, extern: "nro$1Str".} =
|
||||
proc add*(a: var Rope, b: string) {.rtl, extern: "nro$1Str".} =
|
||||
## adds `b` to the rope `a`.
|
||||
a = a & b
|
||||
|
||||
proc `[]`*(r: PRope, i: int): char {.rtl, extern: "nroCharAt".} =
|
||||
proc `[]`*(r: Rope, 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.
|
||||
var x = r
|
||||
|
|
@ -213,7 +215,7 @@ proc `[]`*(r: PRope, i: int): char {.rtl, extern: "nroCharAt".} =
|
|||
x = x.right
|
||||
dec(j, x.len)
|
||||
|
||||
iterator leaves*(r: PRope): string =
|
||||
iterator leaves*(r: Rope): string =
|
||||
## iterates over any leaf string in the rope `r`.
|
||||
if r != nil:
|
||||
var stack = @[r]
|
||||
|
|
@ -226,16 +228,16 @@ iterator leaves*(r: PRope): string =
|
|||
assert(it.data != nil)
|
||||
yield it.data
|
||||
|
||||
iterator items*(r: PRope): char =
|
||||
iterator items*(r: Rope): char =
|
||||
## iterates over any character in the rope `r`.
|
||||
for s in leaves(r):
|
||||
for c in items(s): yield c
|
||||
|
||||
proc write*(f: TFile, r: PRope) {.rtl, extern: "nro$1".} =
|
||||
proc write*(f: TFile, r: Rope) {.rtl, extern: "nro$1".} =
|
||||
## writes a rope to a file.
|
||||
for s in leaves(r): write(f, s)
|
||||
|
||||
proc `$`*(r: PRope): string {.rtl, extern: "nroToString".}=
|
||||
proc `$`*(r: Rope): string {.rtl, extern: "nroToString".}=
|
||||
## converts a rope back to a string.
|
||||
result = newString(r.len)
|
||||
setLen(result, 0)
|
||||
|
|
@ -245,11 +247,11 @@ when false:
|
|||
# Format string caching seems reasonable: All leaves can be shared and format
|
||||
# string parsing has to be done only once. A compiled format string is stored
|
||||
# as a rope. A negative length is used for the index into the args array.
|
||||
proc compiledArg(idx: int): PRope =
|
||||
proc compiledArg(idx: int): Rope =
|
||||
new(result)
|
||||
result.length = -idx
|
||||
|
||||
proc compileFrmt(frmt: string): PRope =
|
||||
proc compileFrmt(frmt: string): Rope =
|
||||
var i = 0
|
||||
var length = len(frmt)
|
||||
result = nil
|
||||
|
|
@ -289,7 +291,7 @@ when false:
|
|||
if i - 1 >= start:
|
||||
add(result, substr(frmt, start, i-1))
|
||||
|
||||
proc `%`*(frmt: string, args: openarray[PRope]): PRope {.
|
||||
proc `%`*(frmt: string, args: openarray[Rope]): Rope {.
|
||||
rtl, extern: "nroFormat".} =
|
||||
## `%` substitution operator for ropes. Does not support the ``$identifier``
|
||||
## nor ``${identifier}`` notations.
|
||||
|
|
@ -332,12 +334,12 @@ proc `%`*(frmt: string, args: openarray[PRope]): PRope {.
|
|||
if i - 1 >= start:
|
||||
add(result, substr(frmt, start, i - 1))
|
||||
|
||||
proc addf*(c: var PRope, frmt: string, args: openarray[PRope]) {.
|
||||
proc addf*(c: var Rope, frmt: string, args: openarray[Rope]) {.
|
||||
rtl, extern: "nro$1".} =
|
||||
## shortcut for ``add(c, frmt % args)``.
|
||||
add(c, frmt % args)
|
||||
|
||||
proc equalsFile*(r: PRope, f: TFile): bool {.rtl, extern: "nro$1File".} =
|
||||
proc equalsFile*(r: Rope, f: TFile): bool {.rtl, extern: "nro$1File".} =
|
||||
## returns true if the contents of the file `f` equal `r`.
|
||||
var bufSize = 1024 # reasonable start value
|
||||
var buf = alloc(BufSize)
|
||||
|
|
@ -352,7 +354,7 @@ proc equalsFile*(r: PRope, f: TFile): bool {.rtl, extern: "nro$1File".} =
|
|||
result = readBuffer(f, buf, 1) == 0 # really at the end of file?
|
||||
dealloc(buf)
|
||||
|
||||
proc equalsFile*(r: PRope, f: string): bool {.rtl, extern: "nro$1Str".} =
|
||||
proc equalsFile*(r: Rope, 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.
|
||||
var bin: TFile
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue