3 ms·
That's a terrible example. You're using two different data structures. A hashmap is not the generic version of an array.
by vmchale 8y ago
That's a terrible example. You're using two different data structures.
A hashmap is not the generic version of an array.
- jstimpfle 8y agoCan you clarify what's "terrible" about it? Provided a hash function for the key type exists, the hash map is one valid implementation for a generic map from keys to values. An array is a more efficient map from keys to values if the key type is an integral type and the actual keys at runtime are contiguous. It's also efficient if the keys are only nearly contiguous, and we have a "N/A" sentinel in the value type.