Open
Graph Drawing
Framework

 v.2007.11
 

ogdf::HashArray< I, E, H > Class Template Reference

Indexed arrays using hashing for element access. More...

#include <HashArray.h>

Inheritance diagram for ogdf::HashArray< I, E, H >:

ogdf::Hashing< I, E, H >

List of all members.

Public Types

typedef HashConstIterator< I,
E, H > 
const_terator
 The default value for elements.

Public Member Functions

 HashArray ()
 Creates a hashing array; the default value is the default value of the element type.
 HashArray (const E &defaultValue, const H &hashFunc=H())
 Creates a hashing array with default value defaultValue.
 HashArray (const HashArray< I, E, H > &A)
 Copy constructor.
HashConstIterator< I, E, H > begin () const
 Returns an iterator to the first element in the list of all elements.
int size () const
 Returns the number of defined indices (= number of elements in hash table).
int empty () const
 Returns if any indices are defined (= if the hash table is empty).
const E & operator[] (const I &i) const
 Returns the element with index i.
E & operator[] (const I &i)
 Returns a reference to the element with index i.
bool isDefined (const I &i) const
 Returns true iff index i is defined.
void undefine (const I &i)
 Undefines index i.
HashArray< I, E, H > & operator= (const HashArray< I, E, H > &A)
 Assignment operator.
void clear ()
 Undefines all indices.

Private Attributes

m_defaultValue


Detailed Description

template<class I, class E, class H = DefHashFunc<I>>
class ogdf::HashArray< I, E, H >

Indexed arrays using hashing for element access.

A hashing array can be used like a usual array but has a general index type. The class uses three template parameters:

The hashing array is only defined for a subset Idef of the index set (set of all elements of the index type). At construction, this set is empty. Whenever an index is assigned an element, this index is added to Idef. There are also method for testing if an index is defined (is in Idef).

Example

The following code snippet demonstrates how to use a hashing array. First, the example inserts elements into a hashing array simulating a tiny German–English dictionary, then it prints some elements via array access, and finally it iterates over all defined indices and prints the dictionary entries. We use a the const reference Hc, since we want to avoid that array access for undefined indices creates these elements.

   HashArray<String,String> H("[undefined]");
   const HashArray<String,String> &Hc = H;

   H["Hund"]  = "dog";
   H["Katze"] = "cat";
   H["Maus"]  = "mouse";

   cout << "Katze:   " << Hc["Katze"]   << endl;
   cout << "Hamster: " << Hc["Hamster"] << endl;

   cout << "\nAll elements:" << endl;
   HashConstIterator<String,String> it;
   for(it = Hc.begin(); it.valid(); ++it)
     cout << it.key() << " -> " << it.info() << endl;

The produced output is as follows:

 Katze:   cat
 Hamster: [undefined]

 All elements:
 Hund -> dog
 Maus -> mouse
 Katze -> cat

Definition at line 119 of file HashArray.h.


Member Typedef Documentation

template<class I, class E, class H = DefHashFunc<I>>
typedef HashConstIterator<I,E,H> ogdf::HashArray< I, E, H >::const_terator

The default value for elements.

The type of const-iterators for hash arrays.

Reimplemented from ogdf::Hashing< I, E, H >.

Definition at line 125 of file HashArray.h.


Constructor & Destructor Documentation

template<class I, class E, class H = DefHashFunc<I>>
ogdf::HashArray< I, E, H >::HashArray (  )  [inline]

Creates a hashing array; the default value is the default value of the element type.

Definition at line 128 of file HashArray.h.

template<class I, class E, class H = DefHashFunc<I>>
ogdf::HashArray< I, E, H >::HashArray ( const E &  defaultValue,
const H &  hashFunc = H() 
) [inline]

Creates a hashing array with default value defaultValue.

Definition at line 131 of file HashArray.h.

template<class I, class E, class H = DefHashFunc<I>>
ogdf::HashArray< I, E, H >::HashArray ( const HashArray< I, E, H > &  A  )  [inline]

Copy constructor.

Definition at line 135 of file HashArray.h.


Member Function Documentation

template<class I, class E, class H = DefHashFunc<I>>
HashConstIterator<I,E,H> ogdf::HashArray< I, E, H >::begin (  )  const [inline]

Returns an iterator to the first element in the list of all elements.

Reimplemented from ogdf::Hashing< I, E, H >.

Definition at line 138 of file HashArray.h.

template<class I, class E, class H = DefHashFunc<I>>
int ogdf::HashArray< I, E, H >::size (  )  const [inline]

Returns the number of defined indices (= number of elements in hash table).

Reimplemented from ogdf::Hashing< I, E, H >.

Definition at line 141 of file HashArray.h.

template<class I, class E, class H = DefHashFunc<I>>
int ogdf::HashArray< I, E, H >::empty (  )  const [inline]

Returns if any indices are defined (= if the hash table is empty).

Reimplemented from ogdf::Hashing< I, E, H >.

Definition at line 144 of file HashArray.h.

template<class I, class E, class H = DefHashFunc<I>>
const E& ogdf::HashArray< I, E, H >::operator[] ( const I &  i  )  const [inline]

Returns the element with index i.

Definition at line 148 of file HashArray.h.

template<class I, class E, class H = DefHashFunc<I>>
E& ogdf::HashArray< I, E, H >::operator[] ( const I &  i  )  [inline]

Returns a reference to the element with index i.

Definition at line 155 of file HashArray.h.

template<class I, class E, class H = DefHashFunc<I>>
bool ogdf::HashArray< I, E, H >::isDefined ( const I &  i  )  const [inline]

Returns true iff index i is defined.

Definition at line 162 of file HashArray.h.

template<class I, class E, class H = DefHashFunc<I>>
void ogdf::HashArray< I, E, H >::undefine ( const I &  i  )  [inline]

Undefines index i.

Definition at line 167 of file HashArray.h.

template<class I, class E, class H = DefHashFunc<I>>
HashArray<I,E,H>& ogdf::HashArray< I, E, H >::operator= ( const HashArray< I, E, H > &  A  )  [inline]

Assignment operator.

Definition at line 172 of file HashArray.h.

template<class I, class E, class H = DefHashFunc<I>>
void ogdf::HashArray< I, E, H >::clear (  )  [inline]

Undefines all indices.

Reimplemented from ogdf::Hashing< I, E, H >.

Definition at line 179 of file HashArray.h.


Member Data Documentation

template<class I, class E, class H = DefHashFunc<I>>
E ogdf::HashArray< I, E, H >::m_defaultValue [private]

Definition at line 121 of file HashArray.h.


The documentation for this class was generated from the following file:

© 1999-2007 by oreas GmbH, © 2005-2007 by University Dortmund and University Cologne.

Generated on Thu Nov 22 19:40:08 2007 by doxygen 1.5.4.