Introduction
Downloads
Documentation
Tutorials
Pixie Lite
Forum

Home

HashTableIterator< HASHTABLEKEY, TYPE > Class Template Reference
[Containers]

Iterator for HashTable. More...

List of all members.


Public Member Functions

 HashTableIterator (const HashTable< HASHTABLEKEY, TYPE > &table)
void MoveFirst ()
void MoveNext ()
void MovePrevious ()
void MoveLast ()
TYPE & GetCurrent () const
bool IsValid () const
bool Find (const HASHTABLEKEY &key)
const HASHTABLEKEY & GetCurrentKey () const

Friends

class HashTable< HASHTABLEKEY, TYPE >

Detailed Description

template<class HASHTABLEKEY, class TYPE>
class HashTableIterator< HASHTABLEKEY, TYPE >

Iterator for HashTable.

Author:
Mattias Gustavsson
The iterator provides a convenient way to loop trough all the items of a hash table in the same way as you would a linked list. When created, the iterator points at the first item in the table, and you can then move it around using GetFirst, GetNext, GetLast and GetPrevious, and even search for a specific item using Find. Note that hash tables are optimized to be extremely fast when searching (using Find), but this also results in stepping through the table using GetFirst, GetNext etc. might be very slow, and it is not recommended that you do this in performance critical code. If you need fast looping through, consider using a linked list or a dynamic array instead (which are much less efficient when using Find).

Definition at line 34 of file HashTableIterator.h.


Constructor & Destructor Documentation

template<class HASHTABLEKEY , class TYPE >
HashTableIterator< HASHTABLEKEY, TYPE >::HashTableIterator ( const HashTable< HASHTABLEKEY, TYPE > &  table  ) 

Constructor

Definition at line 8 of file HashTableIterator.inl.


Member Function Documentation

template<class HASHTABLEKEY , class TYPE >
void HashTableIterator< HASHTABLEKEY, TYPE >::MoveFirst (  ) 

Returns the first item in the table, and resets the iterator to return the second item the next time GetNext is called

Returns:
The first item in the table

Definition at line 19 of file HashTableIterator.inl.

template<class HASHTABLEKEY , class TYPE >
void HashTableIterator< HASHTABLEKEY, TYPE >::MoveNext (  ) 

Returns the next item in the table, and advances the iterator

Returns:
The next item in the table, or 0 if there is none

Definition at line 42 of file HashTableIterator.inl.

template<class HASHTABLEKEY , class TYPE >
void HashTableIterator< HASHTABLEKEY, TYPE >::MovePrevious (  ) 

Returns the previous item in the table, and moves the iterator back

Returns:
The previous item in the table, or 0 if there is none

Definition at line 95 of file HashTableIterator.inl.

template<class HASHTABLEKEY , class TYPE >
void HashTableIterator< HASHTABLEKEY, TYPE >::MoveLast (  ) 

Returns the last item in the table, and resets the iterator to return the next to last item the next time GetPrevious is called

Returns:
The last item in the table

Definition at line 72 of file HashTableIterator.inl.

template<class HASHTABLEKEY , class TYPE >
TYPE & HashTableIterator< HASHTABLEKEY, TYPE >::GetCurrent (  )  const

Returns the item the iterator is currently pointing at

Returns:
The current item

Definition at line 119 of file HashTableIterator.inl.

template<class HASHTABLEKEY , class TYPE >
bool HashTableIterator< HASHTABLEKEY, TYPE >::IsValid (  )  const

Checks if the iterator have reached the end of the table

Returns:
True if the iterator is at the end of the table

Definition at line 139 of file HashTableIterator.inl.

template<class HASHTABLEKEY , class TYPE >
bool HashTableIterator< HASHTABLEKEY, TYPE >::Find ( const HASHTABLEKEY &  key  ) 

Finds an item in the table

Returns:
A pointer to the item, or 0 if it was not found
Parameters:
key Key of item to look for

Definition at line 158 of file HashTableIterator.inl.

template<class HASHTABLEKEY , class TYPE >
const HASHTABLEKEY & HashTableIterator< HASHTABLEKEY, TYPE >::GetCurrentKey (  )  const

Gets the key of the item that the iterator is currently pointing at

Returns:
Key of the item the iterator is currently pointing at

Definition at line 206 of file HashTableIterator.inl.


Friends And Related Function Documentation

template<class HASHTABLEKEY, class TYPE>
friend class HashTable< HASHTABLEKEY, TYPE > [friend]

Definition at line 104 of file HashTableIterator.h.



Pixie University and the Pixie Game Engine is created and managed by Mattias Gustavsson.
Reproduction/republishing of any material on this site without permission is strictly prohibited.