FreeNOS
ConstHashIterator.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 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_CONSTHASHITERATOR_H
19#define __LIBSTD_CONSTHASHITERATOR_H
20
21#include "Macros.h"
22#include "Types.h"
23#include "ConstIterator.h"
24#include "ListIterator.h"
25#include "HashTable.h"
26#include "Assert.h"
27
39template <class K, class V> class ConstHashIterator : public ConstIterator<V>
40{
41 public:
42
52
57 {
58 }
59
63 virtual void reset()
64 {
65 m_iter.reset();
66 }
67
72 virtual bool hasNext() const
73 {
74 return m_iter.hasNext();
75 }
76
82 virtual bool hasCurrent() const
83 {
84 return m_iter.hasCurrent();
85 }
86
92 virtual const V & current() const
93 {
94 return m_hash[m_iter.current()];
95 }
96
102 virtual const K & key() const
103 {
104 return m_iter.current();
105 }
106
115 virtual const V & next()
116 {
117 return m_hash[m_iter.next()];
118 }
119
128 virtual void operator ++(int num)
129 {
130 m_iter++;
131 }
132
133 private:
134
137
140
143};
144
150#endif /* __LIBSTD_HASHITERATOR_H */
Iterate through a constant (read-only) HashTable.
virtual bool hasCurrent() const
Check if there is a current item.
virtual ~ConstHashIterator()
Destructor.
virtual const V & next()
Fetch the next item.
virtual const V & current() const
Get the current value (read-only).
virtual bool hasNext() const
Check if there is more to iterate.
virtual void reset()
Reset the iterator.
const HashTable< K, V > & m_hash
Points to the HashTable to iterate.
ListIterator< K > m_iter
Iterator of keys.
ConstHashIterator(const HashTable< K, V > &hash)
Class constructor.
List< K > m_keys
List of keys to iterate.
virtual const K & key() const
Get the current key.
virtual void operator++(int num)
Increment operator.
Abstracts an iteration process for a constant.
Efficient key -> value lookups.
Definition HashTable.h:45
Iterate through a 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.