renamed writeln to writeLine in tests
This commit is contained in:
parent
b6252af5c6
commit
69e15ac32f
39 changed files with 456 additions and 456 deletions
|
|
@ -15,7 +15,7 @@ if find(root, "world"):
|
|||
for str in items(root):
|
||||
stdout.write(str)
|
||||
else:
|
||||
stdout.writeln("BUG")
|
||||
stdout.writeLine("BUG")
|
||||
|
||||
var
|
||||
r2: PBinaryTree[int]
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ when isMainModule:
|
|||
for str in items(root):
|
||||
stdout.write(str)
|
||||
else:
|
||||
stdout.writeln("BUG")
|
||||
stdout.writeLine("BUG")
|
||||
|
||||
var
|
||||
r2: PBinaryTree[int]
|
||||
|
|
|
|||
|
|
@ -37,25 +37,25 @@ proc clean[T: SomeOrdinal|SomeNumber](o: var T) {.inline.} = discard
|
|||
proc clean[T: string|seq](o: var T) {.inline.} =
|
||||
o = nil
|
||||
|
||||
proc clean[T,D] (o: ref TItem[T,D]) {.inline.} =
|
||||
proc clean[T,D] (o: ref TItem[T,D]) {.inline.} =
|
||||
when (D is string) :
|
||||
o.value = nil
|
||||
else :
|
||||
o.val_set = false
|
||||
|
||||
proc isClean[T,D] (it: ref TItem[T,D]): bool {.inline.} =
|
||||
proc isClean[T,D] (it: ref TItem[T,D]): bool {.inline.} =
|
||||
when (D is string) :
|
||||
return it.value == nil
|
||||
else :
|
||||
return not it.val_set
|
||||
|
||||
proc isClean[T,D](n: PNode[T,D], x: int): bool {.inline.} =
|
||||
proc isClean[T,D](n: PNode[T,D], x: int): bool {.inline.} =
|
||||
when (D is string):
|
||||
return n.slots[x].value == nil
|
||||
else:
|
||||
return not n.slots[x].val_set
|
||||
|
||||
proc setItem[T,D](Akey: T, Avalue: D, ANode: PNode[T,D]): ref TItem[T,D] {.inline.} =
|
||||
proc setItem[T,D](Akey: T, Avalue: D, ANode: PNode[T,D]): ref TItem[T,D] {.inline.} =
|
||||
new(result)
|
||||
result.key = Akey
|
||||
result.value = Avalue
|
||||
|
|
@ -72,8 +72,8 @@ template binSearchImpl *(docmp: expr) {.immediate.} =
|
|||
var H = haystack.len -1
|
||||
while result <= H :
|
||||
var I {.inject.} = (result + H) shr 1
|
||||
var SW = docmp
|
||||
if SW < 0: result = I + 1
|
||||
var SW = docmp
|
||||
if SW < 0: result = I + 1
|
||||
else:
|
||||
H = I - 1
|
||||
if SW == 0 : bFound = true
|
||||
|
|
@ -85,14 +85,14 @@ proc bSearch[T,D] (haystack: PNode[T,D], needle:T): int {.inline.} =
|
|||
|
||||
proc DeleteItem[T,D] (n: PNode[T,D], x: int): PNode[T,D] {.inline.} =
|
||||
var w = n.slots[x]
|
||||
if w.node != nil :
|
||||
if w.node != nil :
|
||||
clean(w)
|
||||
return n
|
||||
dec(n.count)
|
||||
if n.count > 0 :
|
||||
for i in countup(x, n.count -1) : n.slots[i] = n.slots[i + 1]
|
||||
n.slots[n.count] = nil
|
||||
case n.count
|
||||
case n.count
|
||||
of cLen1 : setLen(n.slots, cLen1)
|
||||
of cLen2 : setLen(n.slots, cLen2)
|
||||
of cLen3 : setLen(n.slots, cLen3)
|
||||
|
|
@ -106,7 +106,7 @@ proc DeleteItem[T,D] (n: PNode[T,D], x: int): PNode[T,D] {.inline.} =
|
|||
n.slots = nil
|
||||
n.left = nil
|
||||
|
||||
proc internalDelete[T,D] (ANode: PNode[T,D], key: T, Avalue: var D): PNode[T,D] =
|
||||
proc internalDelete[T,D] (ANode: PNode[T,D], key: T, Avalue: var D): PNode[T,D] =
|
||||
var Path: array[0..20, RPath[T,D]]
|
||||
var n = ANode
|
||||
result = n
|
||||
|
|
@ -126,20 +126,20 @@ proc internalDelete[T,D] (ANode: PNode[T,D], key: T, Avalue: var D): PNode[T,D]
|
|||
n = n.slots[x].node
|
||||
else :
|
||||
n = nil
|
||||
else :
|
||||
else :
|
||||
dec(x)
|
||||
if isClean(n, x) : return
|
||||
Avalue = n.slots[x].value
|
||||
var n2 = DeleteItem(n, x)
|
||||
dec(h)
|
||||
while (n2 != n) and (h >=0) :
|
||||
n = n2
|
||||
n = n2
|
||||
var w = addr Path[h]
|
||||
x = w.Xi -1
|
||||
if x >= 0 :
|
||||
if (n == nil) and isClean(w.Nd, x) :
|
||||
n = w.Nd
|
||||
n.slots[x].node = nil
|
||||
n.slots[x].node = nil
|
||||
n2 = DeleteItem(n, x)
|
||||
else :
|
||||
w.Nd.slots[x].node = n
|
||||
|
|
@ -161,7 +161,7 @@ proc internalFind[T,D] (n: PNode[T,D], key: T): ref TItem[T,D] {.inline.} =
|
|||
wn = wn.left
|
||||
else :
|
||||
x = (-x) -1
|
||||
if x < wn.count :
|
||||
if x < wn.count :
|
||||
wn = wn.slots[x].node
|
||||
else :
|
||||
return nil
|
||||
|
|
@ -171,7 +171,7 @@ proc internalFind[T,D] (n: PNode[T,D], key: T): ref TItem[T,D] {.inline.} =
|
|||
return nil
|
||||
|
||||
proc traceTree[T,D](root: PNode[T,D]) =
|
||||
proc traceX(x: int) =
|
||||
proc traceX(x: int) =
|
||||
write stdout, "("
|
||||
write stdout, x
|
||||
write stdout, ") "
|
||||
|
|
@ -184,7 +184,7 @@ proc traceTree[T,D](root: PNode[T,D]) =
|
|||
|
||||
|
||||
proc traceln(space: string) =
|
||||
writeln stdout, ""
|
||||
writeLine stdout, ""
|
||||
write stdout, space
|
||||
|
||||
proc doTrace(n: PNode[T,D], level: int) =
|
||||
|
|
@ -192,7 +192,7 @@ proc traceTree[T,D](root: PNode[T,D]) =
|
|||
traceln(space)
|
||||
write stdout, "node: "
|
||||
if n == nil:
|
||||
writeln stdout, "is empty"
|
||||
writeLine stdout, "is empty"
|
||||
return
|
||||
write stdout, n.count
|
||||
write stdout, " elements: "
|
||||
|
|
@ -204,7 +204,7 @@ proc traceTree[T,D](root: PNode[T,D]) =
|
|||
if el != nil and not isClean(el):
|
||||
traceln(space)
|
||||
traceX(i)
|
||||
if i >= n.count:
|
||||
if i >= n.count:
|
||||
write stdout, "error "
|
||||
else:
|
||||
traceEl(el)
|
||||
|
|
@ -219,14 +219,14 @@ proc traceTree[T,D](root: PNode[T,D]) =
|
|||
else : write stdout, el.key
|
||||
if el.node != nil: doTrace(el.node, level +1)
|
||||
else : write stdout, " empty "
|
||||
writeln stdout,""
|
||||
writeLine stdout,""
|
||||
|
||||
doTrace(root, 0)
|
||||
|
||||
proc InsertItem[T,D](APath: RPath[T,D], ANode:PNode[T,D], Akey: T, Avalue: D) =
|
||||
var x = - APath.Xi
|
||||
inc(APath.Nd.count)
|
||||
case APath.Nd.count
|
||||
case APath.Nd.count
|
||||
of cLen1: setLen(APath.Nd.slots, cLen2)
|
||||
of cLen2: setLen(APath.Nd.slots, cLen3)
|
||||
of cLen3: setLen(APath.Nd.slots, cLenCenter)
|
||||
|
|
@ -286,7 +286,7 @@ proc internalPut[T,D](ANode: ref TNode[T,D], Akey: T, Avalue: D, Oldvalue: var D
|
|||
if x <= 0 :
|
||||
Path[h].Nd = n
|
||||
Path[h].Xi = x
|
||||
inc(h)
|
||||
inc(h)
|
||||
if x == 0 :
|
||||
n = n.left
|
||||
else :
|
||||
|
|
@ -337,40 +337,40 @@ proc CleanTree[T,D](n: PNode[T,D]): PNode[T,D] =
|
|||
proc VisitAllNodes[T,D](n: PNode[T,D], visit: proc(n: PNode[T,D]): PNode[T,D] {.closure.} ): PNode[T,D] =
|
||||
if n != nil :
|
||||
if n.left != nil :
|
||||
n.left = VisitAllNodes(n.left, visit)
|
||||
n.left = VisitAllNodes(n.left, visit)
|
||||
for i in 0 .. n.count - 1 :
|
||||
var w = n.slots[i]
|
||||
if w.node != nil :
|
||||
w.node = VisitAllNodes(w.node, visit)
|
||||
w.node = VisitAllNodes(w.node, visit)
|
||||
return visit(n)
|
||||
return nil
|
||||
|
||||
proc VisitAllNodes[T,D](n: PNode[T,D], visit: proc(n: PNode[T,D]) {.closure.} ) =
|
||||
if n != nil:
|
||||
if n.left != nil :
|
||||
VisitAllNodes(n.left, visit)
|
||||
VisitAllNodes(n.left, visit)
|
||||
for i in 0 .. n.count - 1 :
|
||||
var w = n.slots[i]
|
||||
if w.node != nil :
|
||||
VisitAllNodes(w.node, visit)
|
||||
VisitAllNodes(w.node, visit)
|
||||
visit(n)
|
||||
|
||||
proc VisitAll[T,D](n: PNode[T,D], visit: proc(Akey: T, Avalue: D) {.closure.} ) =
|
||||
if n != nil:
|
||||
if n.left != nil :
|
||||
VisitAll(n.left, visit)
|
||||
VisitAll(n.left, visit)
|
||||
for i in 0 .. n.count - 1 :
|
||||
var w = n.slots[i]
|
||||
if not w.isClean :
|
||||
visit(w.key, w.value)
|
||||
visit(w.key, w.value)
|
||||
if w.node != nil :
|
||||
VisitAll(w.node, visit)
|
||||
VisitAll(w.node, visit)
|
||||
|
||||
proc VisitAll[T,D](n: PNode[T,D], visit: proc(Akey: T, Avalue: var D):bool {.closure.} ): PNode[T,D] =
|
||||
if n != nil:
|
||||
var n1 = n.left
|
||||
if n1 != nil :
|
||||
var n2 = VisitAll(n1, visit)
|
||||
var n2 = VisitAll(n1, visit)
|
||||
if n1 != n2 :
|
||||
n.left = n2
|
||||
var i = 0
|
||||
|
|
@ -395,7 +395,7 @@ iterator keys* [T,D] (n: PNode[T,D]): T =
|
|||
var level = 0
|
||||
var nd = n
|
||||
var i = -1
|
||||
while true :
|
||||
while true :
|
||||
if i < nd.count :
|
||||
Path[level].Nd = nd
|
||||
Path[level].Xi = i
|
||||
|
|
@ -471,4 +471,4 @@ when isMainModule:
|
|||
|
||||
|
||||
|
||||
test()
|
||||
test()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue