CS262 - Lecture 2
CS262 - Lecture 2
The Map
ADT
Chapter 8: The Map ADT
8.1 – The Map Interface
8.2 – Map Implementations
8.3 – Application: String-to-String Map
8.4 – Hashing
8.5 – Hash Functions
8.6 – A Hash-Based Map
8.7 – Map Variations
8.1 The Map Interface
• Maps associate a
key with exactly
one value
• In other words
– a map structure
does not permit
duplicate keys
– but two distinct
keys can map onto
the same value
Legal mapping variations
MapInterface
//------------------------------------------------------------------------/
/ MapInterface.java by Dale/Joyce/Weems Chapter
8 //
// A map provides (K = key, V = value) pairs, mapping the key onto
// the value.
// Keys are unique. Keys cannot be null.
//
// Methods throw IllegalArgumentException if passed a null key argument.
//
// Values can be null, so a null value returned by put, get, or remove does
// not necessarily mean that an entry did not exist.
//------------------------------------------------------------------------
//
// . . . continued on next slide
package ch08.maps;
import java.util.Iterator;
V get(K k);
// If an entry in this map with a key k exists then the value associated
// with that entry is returned; otherwise null is returned.
V remove(K k);
// If an entry in this map with key k exists then the entry is removed
// from the map and the value associated with that entry is returned;
// otherwise null is returned.
//
// Optional. Throws UnsupportedOperationException if not supported.