summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pure')
-rwxr-xr-xlib/pure/collections/intsets.nim29
-rwxr-xr-xlib/pure/terminal.nim2
2 files changed, 29 insertions, 2 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
 
diff --git a/lib/pure/terminal.nim b/lib/pure/terminal.nim
index 0fd631eed..20eaa4d36 100755
--- a/lib/pure/terminal.nim
+++ b/lib/pure/terminal.nim
@@ -224,7 +224,7 @@ proc setStyle*(style: set[TStyle]) =
     if styleBlink in style: a = a or int16(BACKGROUND_INTENSITY)

     if styleReverse in style: a = a or 0x4000'i16 # COMMON_LVB_REVERSE_VIDEO

     if styleUnderscore in style: a = a or 0x8000'i16 # COMMON_LVB_UNDERSCORE

-    discard SetConsoleTextAttribute(conHandle, old or a)

+    discard SetConsoleTextAttribute(conHandle, a)

   else:

     for s in items(style):

       stdout.write("\e[" & $ord(s) & 'm')