mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 05:50:30 +00:00
fixes #2625
This commit is contained in:
@@ -819,15 +819,18 @@ proc enlarge[A](t: var CountTable[A]) =
|
||||
swap(t.data, n)
|
||||
|
||||
proc `[]=`*[A](t: var CountTable[A], key: A, val: int) =
|
||||
## puts a (key, value)-pair into `t`. `val` has to be positive.
|
||||
## puts a (key, value)-pair into `t`.
|
||||
assert val > 0
|
||||
var h = rawGet(t, key)
|
||||
if h >= 0:
|
||||
t.data[h].val = val
|
||||
else:
|
||||
h = -1 - h
|
||||
t.data[h].key = key
|
||||
t.data[h].val = val
|
||||
if mustRehash(len(t.data), t.counter): enlarge(t)
|
||||
rawInsert(t, t.data, key, val)
|
||||
inc(t.counter)
|
||||
#h = -1 - h
|
||||
#t.data[h].key = key
|
||||
#t.data[h].val = val
|
||||
|
||||
proc initCountTable*[A](initialSize=64): CountTable[A] =
|
||||
## creates a new count table that is empty.
|
||||
|
||||
19
tests/collections/tcounttable.nim
Normal file
19
tests/collections/tcounttable.nim
Normal file
@@ -0,0 +1,19 @@
|
||||
discard """
|
||||
output: "And we get here"
|
||||
"""
|
||||
|
||||
# bug #2625
|
||||
|
||||
const s_len = 32
|
||||
|
||||
import tables
|
||||
var substr_counts: CountTable[string] = initCountTable[string]()
|
||||
var my_string = "Hello, this is sadly broken for strings over 64 characters. Note that it *does* appear to work for short strings."
|
||||
for i in 0..(my_string.len - s_len):
|
||||
let s = my_string[i..i+s_len-1]
|
||||
substr_counts[s] = 1
|
||||
# substr_counts[s] = substr_counts[s] + 1 # Also breaks, + 2 as well, etc.
|
||||
# substr_counts.inc(s) # This works
|
||||
#echo "Iteration ", i
|
||||
|
||||
echo "And we get here"
|
||||
Reference in New Issue
Block a user