Contents
Page-10
Prev
Next
Page+10
Index
Array as a Map
Suppose that:
- The KeyType is an integer.
- The size of the domain (largest possible key minus smallest)
is not too large.
In this case, the best map to use is an array:
- O(1) and very fast.
- very simple code: a[i]
- no space required for keys (key is the array index).
When it is applicable, use an array in your programs rather than a
switch statement:
- runs faster
- uses less storage
- better software engineering