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 
39 template <class K, class V> class ConstHashIterator : public ConstIterator<V>
40 {
41  public:
42 
49  : m_hash(hash), m_keys(hash.keys()), m_iter(m_keys)
50  {
51  }
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 */
ConstHashIterator::~ConstHashIterator
virtual ~ConstHashIterator()
Destructor.
Definition: ConstHashIterator.h:56
HashTable
Efficient key -> value lookups.
Definition: HashTable.h:44
ConstHashIterator::reset
virtual void reset()
Reset the iterator.
Definition: ConstHashIterator.h:63
Macros.h
Types.h
ConstHashIterator::hasCurrent
virtual bool hasCurrent() const
Check if there is a current item.
Definition: ConstHashIterator.h:82
ListIterator::next
virtual T & next()
Fetch the next item.
Definition: ListIterator.h:140
ConstIterator
Abstracts an iteration process for a constant.
Definition: ConstIterator.h:34
ConstHashIterator::hasNext
virtual bool hasNext() const
Check if there is more to iterate.
Definition: ConstHashIterator.h:72
ConstHashIterator::m_iter
ListIterator< K > m_iter
Iterator of keys.
Definition: ConstHashIterator.h:142
hash
Size hash(const String &key, Size mod)
Compute a hash using the FNV algorithm.
Definition: HashFunction.cpp:21
HashTable.h
ConstHashIterator::key
virtual const K & key() const
Get the current key.
Definition: ConstHashIterator.h:102
Assert.h
ConstHashIterator::m_keys
List< K > m_keys
List of keys to iterate.
Definition: ConstHashIterator.h:139
ListIterator::current
virtual const T & current() const
Get current item in the List.
Definition: ListIterator.h:114
ConstHashIterator::next
virtual const V & next()
Fetch the next item.
Definition: ConstHashIterator.h:115
ConstHashIterator::operator++
virtual void operator++(int num)
Increment operator.
Definition: ConstHashIterator.h:128
ListIterator::hasCurrent
virtual bool hasCurrent() const
Check if there is a current item on the List.
Definition: ListIterator.h:104
ConstHashIterator::m_hash
const HashTable< K, V > & m_hash
Points to the HashTable to iterate.
Definition: ConstHashIterator.h:136
ListIterator.h
ListIterator::hasNext
virtual bool hasNext() const
Check if there is more on the List to iterate.
Definition: ListIterator.h:94
ListIterator::reset
virtual void reset()
Reset the iterator.
Definition: ListIterator.h:83
ConstHashIterator::current
virtual const V & current() const
Get the current value (read-only).
Definition: ConstHashIterator.h:92
ConstIterator.h
List< K >
ConstHashIterator
Iterate through a constant (read-only) HashTable.
Definition: ConstHashIterator.h:39
ConstHashIterator::ConstHashIterator
ConstHashIterator(const HashTable< K, V > &hash)
Class constructor.
Definition: ConstHashIterator.h:48
ListIterator< K >