mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-17 22:41:14 +00:00
destructors: work in progress
This commit is contained in:
@@ -19,7 +19,7 @@ var
|
||||
proc `=destroy`*[T](x: var opt[T]) =
|
||||
if x.data != nil:
|
||||
when not supportsCopyMem(T):
|
||||
`=destroy`(x.data)
|
||||
`=destroy`(x.data[])
|
||||
dealloc(x.data)
|
||||
inc deallocCount
|
||||
x.data = nil
|
||||
@@ -69,11 +69,12 @@ proc createTree(data: float): Tree =
|
||||
result.data = data
|
||||
|
||||
proc insert(t: var opt[Tree]; newVal: float) =
|
||||
if it ?= t:
|
||||
if it.data > newVal:
|
||||
insert(it.le, newVal)
|
||||
elif it.data < newVal:
|
||||
insert(it.ri, newVal)
|
||||
#if it ?= t:
|
||||
if t.data != nil:
|
||||
if newVal < t.data[].data:
|
||||
insert(t.data[].le, newVal)
|
||||
elif t.data[].data < newVal:
|
||||
insert(t.data[].ri, newVal)
|
||||
else:
|
||||
discard "already in the tree"
|
||||
else:
|
||||
Reference in New Issue
Block a user