containers::HashList< T, KeyT, SIZE > Class Template Reference

Hash list. More...

#include <hashlist.h>

List of all members.

Public Types

typedef T value_type
 Value type.
typedef T & reference
 Reference type.
typedef T const & const_reference
 Const reference type.
typedef T * pointer
 Pointer type.
typedef T const * const_pointer
 Const pointer type.
typedef
list_type::size_type 
size_type
 Size type.
typedef
list_type::difference_type 
difference_type
 Difference type.
typedef KeyT key_type
 Key type.
typedef Hash< T, KeyT > hash_type
 Type of the Hash class.
typedef Iterator iterator
 Normal iterator type.
typedef ConstIterator const_iterator
 Const iterator type.
typedef
std::reverse_iterator
< iterator
reverse_iterator
 Reverse iterator.
typedef
std::reverse_iterator
< const_iterator
const_reverse_iterator
 Const reverse iterator.

Public Member Functions

 HashList (hash_type const &hash)
 Constructor.
 HashList (HashList const &hl)
 Copy constructor.
HashListoperator= (HashList const &right)
 Assignment operator.
iterator add (KeyT const &key, T const &value)
 Adds a value to the hash list.
iterator add_sorted (KeyT const &key, T const &value)
 Adds a value to the hash list in sorted order.
void clear ()
 Clears the hash list.
void erase (iterator it)
 Erases the value pointed to by the given iterator.
void erase (iterator first, iterator last)
 Erases values pointed to by the given iterator range.
iterator find (KeyT const &key)
 Finds a value matching the given key.
const_iterator find (KeyT const &key) const
 Const version of find().
iterator find_sorted (KeyT const &key)
 Finds a value matching the given key in a sorted list.
const_iterator find_sorted (KeyT const &key) const
 Const version of find().
bool remove (KeyT const &key)
 Removes a value matching the given key.
bool remove_sorted (KeyT const &key)
 Removes a value matching the given key in a sorted list.
iterator begin ()
 Returns an iterator for the beginning of the hash list.
iterator end ()
 Returns an iterator to the end of the hash list.
const_iterator begin () const
 Returns a const iterator for the beginning of the hash list.
const_iterator end () const
 Returns a const iterator to the end of the hash list.
reverse_iterator rbegin ()
 Returns a reverse iterator to the beginning of the hash list.
reverse_iterator rend ()
 Returns a reverse iterator to the end of the hash list.
const_reverse_iterator rbegin () const
 Returns a const reverse iterator to the beginning of the hash list.
const_reverse_iterator rend () const
 Returns a const reverse iterator to the end of the hash list.
size_type size () const
 Returns the actual number of elements in the hash list.
bool empty () const
 Returns whether the hash list is empty.
size_type max_size () const
 Returns the maximum size of the hash list.

Static Public Attributes

static int const hash_size = SIZE
 Hash size.

Friends

class Iterator
class ConstIterator

Classes

class  ConstIterator
class  Iterator


Detailed Description

template<class T, class KeyT, uint32_t SIZE>
class containers::HashList< T, KeyT, SIZE >

This template class implements a hash list which stores values of arbitrary types using keys to speedup their retrieval. It uses a specialized Hash class that is responsible to compute the hash of the keys and match and compare keys against the values.

Parameters:
T The type of values stored in the list.
KeyT The type of the keys used to retrieve a value.
SIZE The size of the hash list (the number of possible values, from 0 to SIZE-1, the associated Hash class will return).

Constructor & Destructor Documentation

template<class T, class KeyT, uint32_t SIZE>
containers::HashList< T, KeyT, SIZE >::HashList ( hash_type const &  hash  )  [inline, explicit]

Constructor.

Parameters:
[in] hash The class Hash object associated with the list and used to compute the hash and do value and key match and comparison on the values in the list. No copy of Hash object is done. It must remain valid until the HashList object is destroyed.


Member Function Documentation

template<class T, class KeyT, uint32_t SIZE>
HashList< T, KeyT, SIZE >::iterator containers::HashList< T, KeyT, SIZE >::add ( KeyT const &  key,
T const &  value 
) [inline]

Adds a value to the hash list that can be retrieved with the given key.

Parameters:
[in] key The key associated with the value.
[in] value The value to add to the list.
Returns:
An iterator to the newly added value, or end() if a value with the same key is already in the list.

template<class T, class KeyT, uint32_t SIZE>
HashList< T, KeyT, SIZE >::iterator containers::HashList< T, KeyT, SIZE >::add_sorted ( KeyT const &  key,
T const &  value 
) [inline]

Adds a value to the hash list in sorted order. The Hash::compare() function is used to sort the value using its key. This allows to use functions such as find_sorted() that work faster on sorted lists, but all elements of the list must have been added through the add_sorted() function.

Parameters:
[in] key The key associated with the value.
[in] value The value to add to the list.
Returns:
An iterator to the newly added value, or end() if a value with the same key is already in the list.

template<class T, class KeyT, uint32_t SIZE>
void containers::HashList< T, KeyT, SIZE >::erase ( iterator  it  )  [inline]

Erases the value pointed to by the given iterator.

Parameters:
[in] it The iterator pointing to the value to erase.

template<class T, class KeyT, uint32_t SIZE>
void containers::HashList< T, KeyT, SIZE >::erase ( iterator  first,
iterator  last 
) [inline]

Erases values pointed to by the given iterator range.

Parameters:
[in] first The first iterator of the range.
[in] last The last iterator of the range.

template<class T, class KeyT, uint32_t SIZE>
HashList< T, KeyT, SIZE >::iterator containers::HashList< T, KeyT, SIZE >::find ( KeyT const &  key  )  [inline]

Finds a value matching the given key.

Parameters:
[in] key The key of the value to find.
Returns:
An iterator to the requested value, or end() if no matching value was found.

template<class T, class KeyT, uint32_t SIZE>
HashList< T, KeyT, SIZE >::iterator containers::HashList< T, KeyT, SIZE >::find_sorted ( KeyT const &  key  )  [inline]

Finds a value matching the given key in a sorted list. All values in the hash list should have been added with the add_sorted() function. Finding a value in a sorted list is usually faster when no value matching the key exists in the list, and runs at the same speed otherwise.

Parameters:
[in] key The key of the value to find.
Returns:
An iterator to the requested value, or end() if no matching value was found.

template<class T, class KeyT, uint32_t SIZE>
bool containers::HashList< T, KeyT, SIZE >::remove ( KeyT const &  key  )  [inline]

Removes a value matching the given key.

Parameters:
[in] key The key of the value to remove.
Returns:
true if a value has been removed, false otherwise.

template<class T, class KeyT, uint32_t SIZE>
bool containers::HashList< T, KeyT, SIZE >::remove_sorted ( KeyT const &  key  )  [inline]

Removes a value matching the given key in a sorted list. All values in the hash list should have been added with the add_sorted() function. Removing a value in a sorted list is usually faster when no value matching the key exists in the list, and runs at the same speed otherwise.

Parameters:
[in] key The key of the value to remove.
Returns:
true if a value has been removed, false otherwise.


The documentation for this class was generated from the following file:
Generated on Fri Apr 18 22:03:28 2008 for Epona API by  doxygen 1.5.3