An array is a list of ordered items where as a hash is a set of key-value pairs of unordered items.
To be precise, hash is for mapping and arrays for ordering. Numerically indexed array is more efficient than that of the hash lookup.Hash is slower than array.
If you have things in a line or ordered or in a sequence, use an array. For instance:
- A list of files to read
- A list of people in a queue
If you have a bag of unordered things to look up, use a hash. For example:
- An index of last names, looked up by first name
- An index showing the size of files, looked up by name
To be precise, hash is for mapping and arrays for ordering. Numerically indexed array is more efficient than that of the hash lookup.Hash is slower than array.
If you have things in a line or ordered or in a sequence, use an array. For instance:
- A list of files to read
- A list of people in a queue
If you have a bag of unordered things to look up, use a hash. For example:
- An index of last names, looked up by first name
- An index showing the size of files, looked up by name
No comments :
Post a Comment