Check out sizehint().
On Oct 17, 2014 11:32 PM, "Michele Zaffalon" <[email protected]>
wrote:

> Hello,
>
> I am using a dict as a look up table for the result of a computation (it
> is for a Coursera class on cryptography if anybody is wondering):
>
> accum = BigInt(1)
> lhs = Dict(accum => 0)
> for x1 = 1:2^20-1
>     accum = rem(accum * invg, p)
>     lhs[accum] = x1
> end
>
> and this takes about 20 seconds on my computer. On the other hand, for
> comparison (but not useful for my purpose because I index by the variable
> x1), storing the result in an array of preallocated size is about 2
> seconds. Here is the code:
>
> lhs = Array(Float64, 2^20)
> for x1 = 1:2^20-1
>     accum = rem(accum * invg, p)
>     lhs[x1] = accum
> end
>
> Declaring
> lhs = Dict{BigInt, Int64}(accum => 0)
> does not make any difference.
>
> Is there a way of preallocating the dictionary of a given size?
>
> Thank you,
> michele
>

Reply via email to