Presentation is loading. Please wait.

Presentation is loading. Please wait.

STL: Maps Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University.

Similar presentations


Presentation on theme: "STL: Maps Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University."— Presentation transcript:

1 STL: Maps Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University

2 2 Intro to Maps STL map class An easy way to create “associative array” of key-data pairs, for instance: Dictionary  key: word, data: word’s definition Yellow page  key: name, data: phone number Can be viewed as a vector indexed by keys of strings Keys could be strings or numbers Alternatively, we may want to create hash tables, which involves more hassles To create a good hash function To handle collisions Aka dictionary

3 3 Examples of Maps Examples

4 4 Summary The Good Maps provide a way of using “associative arrays” that allow you to store data indexed by keys of any type Maps can be accessed using iterators with two members “first” corresponds to the key “second” is the value associated with the key Maps are fast to have O(log(n)) time for insertion and lookup. Internally, the elements in a map are sorted from lower to higher keys The gotchas Lookup in a map requires using the find function. You need to use multimap if a key is associated with multiple pieces of data.

5 5 References http://www.cprogramming.com/tutorial/stl/stlmap.html: A basic tutorial http://www.cprogramming.com/tutorial/stl/stlmap.html http://www.yolinux.com/TUTORIALS/CppStlMultiMap.html: More working examples http://www.yolinux.com/TUTORIALS/CppStlMultiMap.html


Download ppt "STL: Maps Jyh-Shing Roger Jang ( 張智星 ) CSIE Dept, National Taiwan University."

Similar presentations


Ads by Google