Why Nostr? What is Njump?
2023-09-06 09:29:11
in reply to

Mo Bitar :ferris: on Nostr: npub1mda8w…wux44 Either use `with_capacity` and see if it works: Or use `new` and ...

Either use `with_capacity` and see if it works:

https://doc.rust-lang.org/std/collections/struct.HashMap.html#method.with_capacity

Or use `new` and then `try_reserve`:

https://doc.rust-lang.org/std/collections/struct.HashMap.html#method.try_reserve

I would always recommend using `with_capacity` when you know how many insertions you will have. It will cause only one allocation instead of reallocating multiple times while the HashMap grows.

Now, if you see `with_capacity` failing or you suspect that you need too much memory, use `try_reserve` to just get a `Result` from the allocator.
Author Public Key
npub1j7fc87rk03whjh72mphc9hrm8zecfsdywdcscsesznwzcrasudvs75mapy