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.
精彩评论