lec25 - CSE 12 The Map Abstract Data Type The Map ADT...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
25 The Map ADT Implementations of the Map ADT Hashing and Hash Tables Collisions and Collision Resolution Strategies CSE 12 The Map Abstract Data Type
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The Map ADT The other ADT's we have talked about are container structures intended to hold data of a certain type The ADT’s operations deal with objects of that type, sometimes called keys : adding them, removing them, checking if the data structure contains them, iterating over them, etc. The Map ADT has a slightly different emphasis: it is intended to hold pairs of data of certain types Map operations deal with <key,value> pairs: adding a pair, removing a pair given its key, returning the value of a pair given its key, iterating over the keys or values or pairs, etc. Map is also sometimes known as: Table, Dictionary, Associative Memory
Background image of page 2
Examples of Map Applications dictionary – a set of words, each one associated with its definition: < word,definition > pairs book index – collection of key words, each one associated with the page numbers on which the word appears: < keyword,list-of-pages > pairs symbol table – a compiler data structure associating identifiers with declaration information: < identifier,declaration-information > pairs ...Can you think of others? A map is a collection type that stores key, value pairs. A value associated with a key is retrieved by supplying the map with the key.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Description A map stores <key, value> pairs. Given a key, a map provides the value associated with that key. The types of the key and value are such that it must be possible to test for equality among keys and among values. Properties 1. Duplicate keys are not allowed. 2. A key may be associated with only one value. 3. A value may be associated with more than one key. 4. Keys can be compared to one another for equality; similarly for values. 5. Null keys and values are not allowed. Attributes size : The number of <key, value> pairs in this map.
Background image of page 4
Map Operations Map() pre-condition: none responsibilities: constructor—create an empty map post-condition: size is set to 0 returns: nothing put( KeyType key, ValueType value ) pre-condition: key and value are not null key can be compared for equality to other keys in this map value can be compared for equality to other values in this map responsibilities: puts the <key, value> pair into the map. If key already exists in this map, its value is replaced with the new value post-condition: size is increased by one if key was not already in this map returns: null if key was not already in this map, the old value associated with key otherwise exception: if key or value is null or cannot be compared to keys/values in this map
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Map Operations get( KeyType key ) pre-condition: key is not null and can be compared for equality to other keys in this map responsibilities: gets the value associated with key in this map post-condition: the map is unchanged
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/27/2012 for the course CSE 12 taught by Professor Gary during the Fall '08 term at UCSD.

Page1 / 24

lec25 - CSE 12 The Map Abstract Data Type The Map ADT...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online