Maps -- Chapter 16 + Hash_maps.

Introduction/Review:
	What containers have we seen in this class so far?

16.1 Idea:
A map takes Keys and links them to a Value.
	map : Key->Value
A multimap takes Keys and links them to many Values.
	multimap: Key -> set(Value)

(or you can do them explicitly: map<Key, set<Value> >)

The class of Key must have a comparison 'less' operator.
Values can be of any type.

Maps and the UML (not on final)
	Do not fit very well.
	At the conceptual level
		you probably don't need to distinguish containers.
	The UML does have Qualified Associations that a like maps,
	but each has an attribute name as a key.
	http://www.csci.csusb.edu/dick/cs330/Slides/umlmap.gif
        
Maps are sets of pairs!
class pair
  is part of the <utility> STL library.
   http://www.csci.csusb.edu/dick/c++std/cd2/lib-utilities.html#lib.utility

	http://www.csci.csusb.edu/dick/cs330/Slides/19ch16.gif

16.2 Sample Programs
	Telephone directory
		page 390:  not "long integer" but "long int"!
	Silly Sentences/grammars
		page 394, top line: incredible grammarType
			map< string, vector< list< string > > >
	Concordances
		Useful for text and for working on code.

	http://www.csci.csusb.edu/dick/cs330/Slides/19ch16.gif

16.3  class map
	page 399 talks of 'map<T>' it is map<X, Y> etc.
	Notice the speeds of the operations.
	Notice that m[k] lets us treat a map as an array/vector.
	m.insert(make_pair(x,y))
		(book 16.3.4, p400 is wrong to use map_three::value_type)
	m.erase(x)
	m.erase(p)
        iterators
		find begin end...
	search (find) and count
http://www.csci.csusb.edu/dick/cs330/SourceCode/demoMaps.cpp

Here is the most complex thing I've done with maps and sets
recently (not on quiz or final.... just because I'm proud of it)
http://ftp.csci.csusb.edu/dick/cs330/SourceCode/conceptAnalysis.cpp
(The theory is in
 http://www.csci.csusb.edu/dick/maths/logic_42_Properties_of_Relation.html#Formal%20Concept%20Analysis
)

Note:  Certain algorithms work well on maps.
Don't forget to use an inserter to insert pairs into a
map.  Iterators overwrite the existing values (if it exists).

16.4 Example Implementation
	Just a special set of pairs....   The math rules here.
	No more needed for final.
	You'd need to fix 'iterator' in the books code.

There is a non standard variation on the STL map called the hash_map.
	hash-map: a container to add to the STL
		Stroustroup pages 497-504
	We have it in our STL library.

Works like a map but doesn't use a tree structure.  Gives very
fast access if you can waste some space.

Use Hash_maps for unordered data 
 and when space is cheap and time is tight

Simple to use with simple data types

   http://www.csci.csusb.edu/dick/cs330/SourceCode/charHashMap.cpp
To store objects with a special key you need to define a class that knows 
how to hash your special key.  Precisely like the following code:
   http://www.csci.csusb.edu/dick/cs330/SourceCode/stringHashMap.cpp

We will talk about implementing hash tables next time.
Study: special handout on Hashing plus
	chapter 17.1, 17.2, 17.3, not 17.4(bucket sort), 
	Chapter 17.4.3 radix sorting, 17.5 17.6,...
   	chapter 20.5.1,.2 open table hashing