summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorMiran <narimiran@disroot.org>2020-02-10 20:50:55 +0100
committerGitHub <noreply@github.com>2020-02-10 20:50:55 +0100
commitceb3d5ad68a29d8800333c2f5065bc12cdce9cd1 (patch)
tree834ce092b1f8e19f91939e5c433806214ecf5dc0 /lib
parent2fee89f7db54e1425ba43c3d9a5eb4156eb6c765 (diff)
downloadNim-ceb3d5ad68a29d8800333c2f5065bc12cdce9cd1.tar.gz
remove outplace version of 'merge' for CountTables (#13377)
* remove outplace version of 'merge' for CountTables

* remove 'merge' tests
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/collections/tables.nim32
1 files changed, 13 insertions, 19 deletions
diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim
index 2cfb6c2c6..a0cc73ad6 100644
--- a/lib/pure/collections/tables.nim
+++ b/lib/pure/collections/tables.nim
@@ -2487,18 +2487,19 @@ proc merge*[A](s: var CountTable[A], t: CountTable[A]) =
   for key, value in t:
     s.inc(key, value)
 
-proc merge*[A](s, t: CountTable[A]): CountTable[A] =
-  ## Merges the two tables into a new one.
-  runnableExamples:
-    let
-      a = toCountTable("aaabbc")
-      b = toCountTable("bcc")
-    doAssert merge(a, b) == toCountTable("aaabbbccc")
-
-  result = initCountTable[A](nextPowerOfTwo(max(s.len, t.len)))
-  for table in @[s, t]:
-    for key, value in table:
-      result.inc(key, value)
+when (NimMajor, NimMinor) <= (1, 0):
+  proc merge*[A](s, t: CountTable[A]): CountTable[A] =
+    ## Merges the two tables into a new one.
+    runnableExamples:
+      let
+        a = toCountTable("aaabbc")
+        b = toCountTable("bcc")
+      doAssert merge(a, b) == toCountTable("aaabbbccc")
+
+    result = initCountTable[A](nextPowerOfTwo(max(s.len, t.len)))
+    for table in @[s, t]:
+      for key, value in table:
+        result.inc(key, value)
 
 proc `$`*[A](t: CountTable[A]): string =
   ## The ``$`` operator for count tables. Used internally when calling `echo`
@@ -3006,13 +3007,6 @@ when isMainModule:
   t2l.inc("foo", 4)
   t2l.inc("bar")
   t2l.inc("baz", 11)
-  let
-    t1merging = t1l
-    t2merging = t2l
-  let merged = merge(t1merging, t2merging)
-  assert(merged["foo"] == 5)
-  assert(merged["bar"] == 3)
-  assert(merged["baz"] == 14)
 
   block:
     const testKey = "TESTKEY"