-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashTableIterator.cpp
More file actions
80 lines (65 loc) · 1.5 KB
/
HashTableIterator.cpp
File metadata and controls
80 lines (65 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "HashTable.h"
#include "HashTableException.h"
#include <stdio.h>
using namespace std;
HashTable::Iterator::Iterator(const HashTable *t) {
ht = t;
int i=0;
while(i<t->capacity && t->isAvailable(i)){
i++;
}
curr = &t->table[i];
}
HashTable::Iterator::Iterator(const HashTable *t, bool start) {
ht = t;
if(start){
int i=0;
while(i<t->capacity && t->isAvailable(i)){
i++;
}
curr = &t->table[i];
}
else{
int i = t->capacity-1;
while(i>0 && t->isAvailable(i)){
i--;
}
curr = &t->table[++i];
}
}
HashTable::Iterator::Iterator(const Iterator &it) {
ht = it.ht;
curr = it.curr;
}
HashTable::Iterator& HashTable::Iterator::operator=(const HashTable::Iterator &it) {
ht = it.ht;
curr = it.curr;
return *this;
}
HashTable::Iterator HashTable::Iterator::operator++() {
curr++;
while(curr!=&ht->table[ht->capacity] && (!(*curr).compare("") || !(*curr).compare("##tomb##"))){
curr++;
}
return *this;
}
HashTable::Iterator HashTable::Iterator::operator++(int a) {
Iterator it (*this);
curr++;
while(curr!=&ht->table[ht->capacity] && (!(*curr).compare("") || !(*curr).compare("##tomb##"))){
curr++;
}
return it;
}
bool HashTable::Iterator::operator==(const HashTable::Iterator &it) const {
return it.curr==curr && it.ht==ht;
}
bool HashTable::Iterator::operator!=(const HashTable::Iterator &it) const {
return it.curr!=curr || it.ht!=ht;
}
const string& HashTable::Iterator::operator*() {
return *curr;
}
const string* HashTable::Iterator::operator->() {
return curr;
}