开发者

How do I initialize the size of a Hash in Ruby?

I would like to specify an initial size for my Hash in Ruby. I know I am going to be adding tens of millions of entries in the hash and a lot of time is wasting rehashing t开发者_运维问答he data every time Ruby decides it needs a larger hash.

Other languages support something like a "reserve" call to pre-size the hash. Can this be done in Ruby?


Ruby's Hash doesn't have any way to do that. It should still be relatively performant either way, but you might want to consider other data storage methods, such as a database or key/value store like Memcached or Redis, for data sets of that magnitude.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜