Hello, please tell me a way to effectively replace a key in a dictionary, or a package that implements a data structure that allows you to do this, due to a fixed number of key-value pairs
i have too many allocations, it is bad
using BenchmarkTools n = 10^6; d = Dict([i => i for i = 1 : n]...); keys = [rand(1:n) for i in 1:2*n]; replace_keys(d, n) = for k in keys if !haskey(d, k) pop!(d) d[k] = k end end; @btime replace_keys(d, keys); # -> 320.215 ms (5998457 allocations: 122.05 MiB) !!!