You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import std/sets
import std/hashes
typeVec2i=tuple[x, y: int32]
prochash(vec: Vec2i): Hash=result=Hash(0)
result=result!&hash(vec.x)
result=result!&hash(vec.y)
result=!$resultvarset: HashSet[Vec2i]
for y in1..4:
for x in0..<32:
let vec: Vec2i= (x.int32, y.int32)
set.incl(vec)
let i =set.len
var j =0for vec inset:
inc(j)
set.excl(vec)
echo (i, j)
Current Output
(128, 96)
32 elements are magically gone from the set while we're iterating over it.
Expected Output
(128, 128)
Additional Information
If we change the HashSet to an OrderedSet, the program gets stuck at an infinite loop. Adding echo vec to the loop at the end of the program yields that it gets stuck at (x: 22, y: 1). ^C'ing out of the program, I could trace that it gets stuck in this while loop:
If sets cannot handle excluding elements while iterating over them, then that should be clearly stated in the documentation and ideally also trigger an assertion.
$ nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2020-10-22
Copyright (c) 2006-2020 by Andreas Rumpf
git hash: 2cb484cefb13e4663afd8e0eb2ad81d43f097803
active boot switches: -d:release
The text was updated successfully, but these errors were encountered:
Example
Current Output
32 elements are magically gone from the set while we're iterating over it.
Expected Output
Additional Information
If we change the
HashSet
to anOrderedSet
, the program gets stuck at an infinite loop. Addingecho vec
to the loop at the end of the program yields that it gets stuck at(x: 22, y: 1)
. ^C'ing out of the program, I could trace that it gets stuck in thiswhile
loop:Nim/lib/pure/collections/sets.nim
Lines 620 to 629 in a156484
If sets cannot handle excluding elements while iterating over them, then that should be clearly stated in the documentation and ideally also trigger an assertion.
The text was updated successfully, but these errors were encountered: