Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove outplace version of 'merge' for CountTables #13377

Merged
merged 2 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
compiler type trait instead of macro. `distinctBase` in sugar module is now deprecated.
- `CountTable.mget` has been removed from `tables.nim`. It didn't work, and it
was an oversight to be included in v1.0.
- `tables.merge(CountTable, CountTable): CountTable` has been removed.
It didn't work well together with the existing inplace version of the same proc
(`tables.merge(var CountTable, CountTable)`).
It was an oversight to be included in v1.0.


### Breaking changes in the compiler
Expand Down
32 changes: 13 additions & 19 deletions lib/pure/collections/tables.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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"
Expand Down