4 ms·
Or even use an array of size 3, but include the IDs in each element and linearly scan for the right ID. As the whole array will likely fit on a cache line and
by mhandley 5y ago
Or even use an array of size 3, but include the IDs in each element and linearly scan for the right ID. As the whole array will likely fit on a cache line and you want to access all three elements in a short time anyway, this is likely no slower than a hash table.
- munchbunny 5y agoThat's what I was thinking after reading the rationale, there are plenty of options that don't involve a hash map. That said, linearly scanning is not much different from a hash map with linear probing that has no empty slots left, so it's not necessarily obvious that the hash map actually takes that much more space.
- usefulcat 5y agoI wouldn't expect a hash map that uses linear probing to wait until it's full (or even nearly full) before increasing the size of the table. Doing a linear scan on a hash table which is both nearly full and very large would be quite bad.
- munchbunny 5y agoNormally I wouldn't expect it either, but if you know it caps out at single-digit numbers of elements, then it's not the worst idea. I'd still just use a plain array, but my point was that hash maps aren't necessarily big and unwieldy.