I apologize for bringing up these old messages, but for me, and perhaps for others too, they are of current interest.
I tried to use the instructions of the update function!() but I get no improvements.
Maybe I apply it wrong
julia> function solve(stones, n)
d = Dict{Int64,Int64}()
for s ∈ stones
d[s] = 1
end
for _ in 1:n
d_n = Dict{Int64,Int64}()
for (s, n) ∈ d
for s2 ∈ blink(s)
s2 == NO_STONE && continue
index = Base.ht_keyindex2!(d_n, s2)
if index > 0
@inbounds d_n.vals[index] += n # = func(dict.vals[index])
else
@inbounds Base._setindex!(d_n, n, s2, -index)
end
# if haskey(d_n, s2)
# d_n[s2] += n
# else
# d_n[s2] = n
# end
end
end
d = d_n
end
sum(values(d))
end
solve (generic function with 1 method)
julia> solve(stones, 25)
197357
julia> solve(stones, 75)
234568186890978
julia> @btime solve(stones, 25) # 260 us
635.100 μs (9800 allocations: 496.95 KiB)
197357
julia> @btime solve(stones, 75) # 12ms
29.340 ms (590514 allocations: 23.42 MiB)
234568186890978