forked from alessandro1105/HashMap_Arduino_Library
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashMap.h
More file actions
167 lines (101 loc) · 2.47 KB
/
Copy pathHashMap.h
File metadata and controls
167 lines (101 loc) · 2.47 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
||
|| @author Alexander Brevig <abrevig@wiring.org.co>
|| @url http://wiring.org.co/
|| @url http://alexanderbrevig.com/
|| @contribution https://github.com/alessandro1105
|| @contribution Brett Hagman <bhagman@wiring.org.co>
||
|| @description
|| | Implementation of a HashMap data structure.
|| | This version is heavily based upon a suggestion from Alessandro1105
|| | Thank you for your contribution!
|| |
|| | Wiring Cross-platform Library
|| #
||
|| @license Please see LICENSE.
||
*/
/*
WARNING!!!!!!!!!
Header file: HashMap.h
Cpp File: HashMap_Impl.h
La suddivisione è stata così imposta per aggirare il problema dei template e allo stesso
tempo mantenere la suddivisione tra Header e Implementazione.
*/
#ifndef HASHMAP_H
#define HASHMAP_H
//---HASH TYPE---
//class template
template<typename hash, typename map>
//class HashType
class HashType {
public:
//--costruttori
HashType();
HashType(hash code, map value);
~HashType(); //distruttore
void reset();
hash getHash();
void setHash(hash code);
map getValue();
void setValue(map value);
//void operator()(hash code, map value);
private:
hash hashCode;
map mappedValue;
};
//---HASH NODE---
//class template
template<typename hash, typename map>
//class HashNode
class HashNode {
public:
HashNode(hash code, map value);
~HashNode();
HashType<hash, map> *getHashType();
HashNode<hash, map> *getPrevius();
HashNode<hash, map> *getNext();
void setPrevius(HashNode<hash, map> *previus);
void setNext(HashNode<hash, map> *next);
private:
HashType<hash, map> *hashType;
HashNode *previus;
HashNode *next;
};
//---HASH MAP---
//Classe principale
//class template
template<typename hash, typename map>
//class HashMap
class HashMap {
public:
HashMap();
~HashMap();
void put(hash key, map value);
bool containsKey(hash key);
map valueFor(hash key);
map valueAt(int i);
map value();
hash keyFor(map value);
hash keyAt(int i);
hash key();
void remove(hash key);
void remove();
unsigned int count();
bool moveToFirst();
bool moveToLast();
bool moveToNext();
bool moveToPrev();
private:
HashNode<hash, map> *hashPairForKey(hash key);
void remove(HashNode<hash, map> *pointer);
HashNode<hash, map> *start;
HashNode<hash, map> *finish;
HashNode<hash, map> *position;
int size;
};
//incluso per workaround problema template
#include "HashMap_Impl.h"
#endif // HASHMAP_H