When does it makes sense to use a map?

Posted by kiwicptn on Stack Overflow See other posts from Stack Overflow or by kiwicptn
Published on 2010-03-11T20:06:28Z Indexed on 2010/03/11 20:09 UTC
Read the original article Hit count: 422

Filed under:
|
|
|
|

I am trying to round up cases when it makes sense to use a map (set of key-value entries). So far I have five categories (see below). Assuming more exist, what are they?

Please limit each answer to one unique category, put up an example, and vote up the fascinating ones.


Property values (like a bean)

age -> 30
sex -> male
loc -> calgary   

Histograms

peter -> 1
john  -> 7
paul  -> 5

Presence, with O(1) performance

peter -> 1
john  -> 1
paul  -> 1

Functions

peter -> treatPeter()
john  -> dealWithJohn()
paul  -> managePaul()

Conversion

peter -> pierre
john  -> jean
paul  -> paul

© Stack Overflow or respective owner

Related posts about map

Related posts about mapping