diff options
author | Araq <rumpf_a@web.de> | 2011-11-20 16:13:03 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-11-20 16:13:03 +0100 |
commit | 72651de7103a85f68b6e86353960daf6e62b37df (patch) | |
tree | 7ec632d331ab39149fef59d8bcee66247a6556c7 /lib/pure/collections | |
parent | a274f3bf5be3fc35f1538e5aab0e32fb9ed2ff82 (diff) | |
download | Nim-72651de7103a85f68b6e86353960daf6e62b37df.tar.gz |
bugfix: 'when' sections in generic objects now work, so TThread[void] compiles
Diffstat (limited to 'lib/pure/collections')
-rwxr-xr-x | lib/pure/collections/intsets.nim | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/lib/pure/collections/intsets.nim b/lib/pure/collections/intsets.nim index 3fd81acf6..6164593c1 100755 --- a/lib/pure/collections/intsets.nim +++ b/lib/pure/collections/intsets.nim @@ -11,7 +11,7 @@ ## sparse bit set. ## **Note**: Since Nimrod currently does not allow the assignment operator to ## be overloaded, ``=`` for int sets performs some rather meaningless shallow -## copy. +## copy; use ``assign`` to get a deep copy. import os, hashes, math @@ -137,6 +137,30 @@ proc initIntSet*: TIntSet = result.counter = 0 result.head = nil +proc assign*(dest: var TIntSet, src: TIntSet) = + ## copies `src` to `dest`. `dest` does not need to be initialized by + ## `initIntSet`. + dest.counter = src.counter + dest.max = src.max + newSeq(dest.data, src.data.len) + + var it = src.head + while it != nil: + + var h = it.key and dest.max + while dest.data[h] != nil: h = nextTry(h, dest.max) + assert(dest.data[h] == nil) + + var n: PTrunk + new(n) + n.next = dest.head + n.key = it.key + n.bits = it.bits + dest.head = n + dest.data[h] = n + + it = it.next + template dollarImpl(): stmt = result = "{" for key in items(s): @@ -174,4 +198,7 @@ when isMainModule: x.incl(1056) for e in items(x): echo e + var y: TIntSet + assign(y, x) + for e in items(y): echo e |