Map in c++
map : A collection that stores pairs where each pair consists of a first half called a key and second half called a vlues.
- sometimes called a "dictionary","associative array", or "hash"
- usage: add(key,value) pairs; look up a values by supplying a key.
real-world examples:
- dictionary of words and definations
- phone book
- social buddy list.
Map Opration
m.put(key.value) : adds key/value pair to the map.
m.get(key): returns the value paired with the given key.
m.remove(key): removes the given key and its paired value.
Map Vs HashMap
Map - implemented using a linked structure called binary search tree.
- pretty fast for all operations; keys are stored in sorted order.
- both kinds of maps implement exactly the same operations.
HashMap - implemented using a special array called a hash table.
- very fast but keys are stored in unpredictable order.
- sometimes called a "dictionary","associative array", or "hash"
- usage: add(key,value) pairs; look up a values by supplying a key.
real-world examples:
- dictionary of words and definations
- phone book
- social buddy list.
Map Opration
m.put(key.value) : adds key/value pair to the map.
m.get(key): returns the value paired with the given key.
m.remove(key): removes the given key and its paired value.
Map Vs HashMap
Map - implemented using a linked structure called binary search tree.
- pretty fast for all operations; keys are stored in sorted order.
- both kinds of maps implement exactly the same operations.
HashMap - implemented using a special array called a hash table.
- very fast but keys are stored in unpredictable order.
Comments
Post a Comment