Map< K, V > Class Template Reference

#include <map.h>

List of all members.

Public Member Functions

 Map ()
 Map (const Map< K, V > &) throw ( bad_alloc )
ceilingKey (const K &) const throw ( NoSuchObject )
void clear ()
bool containsKey (const K &) const
bool containsValue (const V &) const
bool empty () const
V & get (const K &) const throw ( NoSuchObject )
MapIterator< K, V > getIterator ()
MapIterator< K, V > getIterator (const K &) throw ( NoSuchObject )
vector< V > higherEntries (const K &) const
vector< V > lowerEntries (const K &) const
const Map< K, V > & operator= (const Map< K, V > &) throw ( bad_alloc )
void put (const K &, const V &) throw ( bad_alloc )
void printInternal (ostream &=cout)
remove (const K &) throw ( NoSuchObject )
unsigned size () const
vector< V > values () const
 ~Map ()

Private Member Functions

Node< K, V > * findKey (const K &) const
Node< K, V > * findValue (const V &) const
void initialize ()

Private Attributes

Node< K, V > * headPtr
unsigned sz

Friends

ostream & operator<< (ostream &, const Map< K, V > &)

Detailed Description

template<typename K, typename V>
class Map< K, V >

Implementation of a Map ADT using a doubly-linked list.

Author:
Mark Maloof
Version:
1.0, 3/13/13

Constructor & Destructor Documentation

template<typename K , typename V >
Map< K, V >::Map (  )  [inline]

Default constructor.

template<typename K , typename V >
Map< K, V >::Map ( const Map< K, V > &  map  )  throw ( bad_alloc ) [inline]

Copy constructor. Makes a deep copy of the specified map.

Parameters:
map the map to be copied
Exceptions:
bad_alloc if memory cannot be allocated
template<typename K , typename V >
Map< K, V >::~Map (  )  [inline]

Class destructor.


Member Function Documentation

template<typename K , typename V >
K Map< K, V >::ceilingKey ( const K &  key  )  const throw ( NoSuchObject ) [inline]

Returns the smallest key greater than or equal to the specified key.

Parameters:
key the specified key
Returns:
the ceiling key
Exceptions:
NoSuchObject if there is no ceiling key
template<typename K , typename V >
void Map< K, V >::clear (  )  [inline]

Clears this map by removing all of its elements.

template<typename K , typename V >
bool Map< K, V >::containsKey ( const K &  key  )  const [inline]

Returns true if this map contains the specified key; otherwise, returns false.

Parameters:
key the specified key
Returns:
true if this map contains the key
template<typename K , typename V >
bool Map< K, V >::containsValue ( const V &  value  )  const [inline]

Returns true if this map contains the specified value; otherwise, returns false.

Parameters:
value the specified value
Returns:
true if this map contains the value
template<typename K , typename V >
bool Map< K, V >::empty (  )  const [inline]

Returns true if this map contains no key-value pairs; otherwise, returns false.

Returns:
true if this map is empty
template<typename K , typename V >
Node< K, V > * Map< K, V >::findKey ( const K &  key  )  const [inline, private]

Returns a pointer to the node containing the specified key. Returns null if no such key exists.

Parameters:
key the specified key
Returns:
a pointer to the node containing the key
template<typename K , typename V >
Node< K, V > * Map< K, V >::findValue ( const V &  value  )  const [inline, private]

Returns a pointer to the node containing the specified value. Returns null if no such value exists.

Parameters:
value the specified value
Returns:
a pointer to the node containing the value
template<typename K , typename V >
V & Map< K, V >::get ( const K &  key  )  const throw ( NoSuchObject ) [inline]

Returns a reference to the value in this map with the specified key.

Parameters:
key the specified key
Returns:
a reference to the value with the specified key
Exceptions:
NoSuchObject if no such key exists
template<typename K , typename V >
MapIterator< K, V > Map< K, V >::getIterator ( const K &  key  )  throw ( NoSuchObject ) [inline]

Returns an iterator positioned before the specified key.

Parameters:
key the key for positioning the iterator
Returns:
an iterator positioned before the specified key
Exceptions:
NoSuchObject if no such key exists
template<typename K , typename V >
MapIterator< K, V > Map< K, V >::getIterator (  )  [inline]

Returns an iterator positioned at the front of this map.

Returns:
an iterator positioned at the front of this map
template<typename K , typename V >
vector< V > Map< K, V >::higherEntries ( const K &  key  )  const [inline]

Returns a vector of values with keys greater than or equal to the specified key.

Parameters:
key the specified key
Returns:
a vector of values
template<typename K , typename V >
void Map< K, V >::initialize (  )  [inline, private]

Initializes the private data members of this map to their defaults values; that is, sets the pointer to null and size to zero.

template<typename K , typename V >
vector< V > Map< K, V >::lowerEntries ( const K &  key  )  const [inline]

Returns a vector of values with keys less than or equal to the specified key.

Parameters:
key the specified key
Returns:
a vector of values
template<typename K , typename V >
const Map< K, V > & Map< K, V >::operator= ( const Map< K, V > &  map  )  throw ( bad_alloc ) [inline]

Returns a deep copy of the specified map.

Parameters:
map the map to be copied.
Returns:
a copy of the map.
Exceptions:
bad_alloc if memory cannot be allocated.
template<typename K , typename V >
void Map< K, V >::printInternal ( ostream &  out = cout  )  [inline]

A utility method that prints the internal state of this map.

template<typename K , typename V >
void Map< K, V >::put ( const K &  key,
const V &  value 
) throw ( bad_alloc ) [inline]

Puts the specified key-value pair at the front of this map. If the key exists, then its value is replaced with the specified value.

Parameters:
key the specified key
value the specified value
Exceptions:
bad_alloc if memory cannot be allocated
template<typename K , typename V >
V Map< K, V >::remove ( const K &  key  )  throw ( NoSuchObject ) [inline]

Removes and returns the value in this map with the specified key.

Returns:
the value with the specified key
Exceptions:
NoSuchObject if no such key exists
template<typename K , typename V >
unsigned Map< K, V >::size (  )  const [inline]

Returns the number key-value pairs stored in this map.

Returns:
an unsigned integer indicating this map's size
template<typename K , typename V >
vector< V > Map< K, V >::values (  )  const [inline]

Returns a vector containing the values of this map.

Returns:
a vector of values stored in this map

Friends And Related Function Documentation

template<typename K , typename V >
ostream& operator<< ( ostream &  out,
const Map< K, V > &  map 
) [friend]

Overloaded stream insertion operator that outputs the specified map to the output stream in the format [<k1:v1>, <k2:v2>, ...], where <ki:vi> are the elements of the map.

Parameters:
out the output stream
map the specified map
Returns:
the modified output stream

The documentation for this class was generated from the following file:
Generated on Sat Mar 16 11:19:43 2013 by  doxygen 1.6.3