FreeNOS
HashIterator.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __LIBSTD_HASHITERATOR_H
19#define __LIBSTD_HASHITERATOR_H
20
21#include "Macros.h"
22#include "Types.h"
23#include "Iterator.h"
24#include "ListIterator.h"
25#include "HashTable.h"
26#include "Assert.h"
27
39template <class K, class V> class HashIterator : public Iterator<V>
40{
41 public:
42
52
56 virtual ~HashIterator()
57 {
58 }
59
63 virtual void reset()
64 {
65 m_iter.reset();
66 }
67
73 virtual bool hasNext() const
74 {
75 return m_iter.hasNext();
76 }
77
83 virtual bool hasCurrent() const
84 {
85 return m_iter.hasCurrent();
86 }
87
93 virtual const V & current() const
94 {
95 return m_hash[m_iter.current()];
96 }
97
103 virtual V & current()
104 {
105 return m_hash[m_iter.current()];
106 }
107
113 virtual const K & key()
114 {
115 return m_iter.current();
116 }
117
126 virtual V & next()
127 {
128 return m_hash[m_iter.next()];
129 }
130
136 virtual bool remove()
137 {
138 K key = m_iter.current();
139 m_iter.remove();
140 return m_hash.remove(key);
141 }
142
151 virtual void operator ++(int num)
152 {
153 m_iter++;
154 }
155
156 private:
157
160
163
166};
167
173#endif /* __LIBSTD_HASHITERATOR_H */
Iterate through a HashTable.
virtual void reset()
Reset the iterator.
virtual ~HashIterator()
Destructor.
virtual bool hasNext() const
Check if there is more to iterate.
HashTable< K, V > & m_hash
Points to the HashTable to iterate.
virtual const V & current() const
Get the current value (read-only).
virtual const K & key()
Get the current key.
virtual void operator++(int num)
Increment operator.
HashIterator(HashTable< K, V > &hash)
Class constructor.
ListIterator< K > m_iter
Iterator of keys.
virtual V & current()
Get the current value.
virtual bool remove()
Remove the current item from the underlying Container.
List< K > m_keys
List of keys to iterate.
virtual V & next()
Fetch the next item.
virtual bool hasCurrent() const
Check if there is a current item.
Efficient key -> value lookups.
Definition HashTable.h:45
Abstracts an iteration process.
Definition Iterator.h:35
Iterate through a List.
virtual bool remove()
Remove the current item from the List.
virtual T & next()
Fetch the next item.
virtual bool hasCurrent() const
Check if there is a current item on the List.
virtual void reset()
Reset the iterator.
virtual const T & current() const
Get current item in the List.
virtual bool hasNext() const
Check if there is more on the List to iterate.
Simple linked list template class.
Definition List.h:37
Size hash(const String &key, Size mod)
Compute a hash using the FNV algorithm.