cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
cam8.hpp
Go to the documentation of this file.
1 
17 
31 #ifndef _NAL_CAM8_H_
32 #define _NAL_CAM8_H_
33 
34 #include <stdio.h>
35 #include <string>
36 #include <stdint.h>
37 
38 #ifndef _NAL_KVP_DEF_
39 #define _NAL_KVP_DEF_
40 template<typename K, typename V>
41 struct KeyValuePair {
42  public:
43  K key;
44  V value;
45  bool valid;
47  key = 0x0;
48  value = 0x0;
49  valid = false;
50  }
52  key(key), value(value), valid(true) {}
53  KeyValuePair(K key, V value, bool valid) :
54  key(key), value(value), valid(valid) {}
55 };
56 #endif
57 
58 template<typename K, typename V>
59 struct Cam8 {
60  protected:
69  public:
70  Cam8() {
71 #pragma HLS pipeline II=1
72  CamArray0.valid = false;
73  CamArray1.valid = false;
74  CamArray2.valid = false;
75  CamArray3.valid = false;
76  CamArray4.valid = false;
77  CamArray5.valid = false;
78  CamArray6.valid = false;
79  CamArray7.valid = false;
80  }
81 
89  bool lookup(K key, V &value)
90  {
91 #pragma HLS pipeline II=1
92 #pragma HLS INLINE
93  if ((CamArray0.key == key) && (CamArray0.valid == true)) {
94  value = CamArray0.value;
95  return true;
96  }
97  else if ((CamArray1.key == key) && (CamArray1.valid == true)) {
98  value = CamArray1.value;
99  return true;
100  }
101  else if ((CamArray2.key == key) && (CamArray2.valid == true)) {
102  value = CamArray2.value;
103  return true;
104  }
105  else if ((CamArray3.key == key) && (CamArray3.valid == true)) {
106  value = CamArray3.value;
107  return true;
108  }
109  else if ((CamArray4.key == key) && (CamArray4.valid == true)) {
110  value = CamArray4.value;
111  return true;
112  }
113  else if ((CamArray5.key == key) && (CamArray5.valid == true)) {
114  value = CamArray5.value;
115  return true;
116  }
117  else if ((CamArray6.key == key) && (CamArray6.valid == true)) {
118  value = CamArray6.value;
119  return true;
120  }
121  else if ((CamArray7.key == key) && (CamArray7.valid == true)) {
122  value = CamArray7.value;
123  return true;
124  }
125  else {
126  return false;
127  }
128  }
129 
130 
138  bool reverse_lookup(V value, K &key)
139  {
140 #pragma HLS pipeline II=1
141 #pragma HLS INLINE
142  if ((CamArray0.value == value) && (CamArray0.valid == true)) {
143  key = CamArray0.key;
144  return true;
145  }
146  else if ((CamArray1.value == value) && (CamArray1.valid == true)) {
147  key = CamArray1.key;
148  return true;
149  }
150  else if ((CamArray2.value == value) && (CamArray2.valid == true)) {
151  key = CamArray2.key;
152  return true;
153  }
154  else if ((CamArray3.value == value) && (CamArray3.valid == true)) {
155  key = CamArray3.key;
156  return true;
157  }
158  else if ((CamArray4.value == value) && (CamArray4.valid == true)) {
159  key = CamArray4.key;
160  return true;
161  }
162  else if ((CamArray5.value == value) && (CamArray5.valid == true)) {
163  key = CamArray5.key;
164  return true;
165  }
166  else if ((CamArray6.value == value) && (CamArray6.valid == true)) {
167  key = CamArray6.key;
168  return true;
169  }
170  else if ((CamArray7.value == value) && (CamArray7.valid == true)) {
171  key = CamArray7.key;
172  return true;
173  }
174  else {
175  return false;
176  }
177  }
178 
179 
180 
188  {
189 #pragma HLS pipeline II=1
190 #pragma HLS INLINE
191 
192  if (CamArray0.valid == false) {
193  CamArray0 = kVP;
194  return true;
195  }
196  else if (CamArray1.valid == false) {
197  CamArray1 = kVP;
198  return true;
199  }
200  else if (CamArray2.valid == false) {
201  CamArray2 = kVP;
202  return true;
203  }
204  else if (CamArray3.valid == false) {
205  CamArray3 = kVP;
206  return true;
207  }
208  else if (CamArray4.valid == false) {
209  CamArray4 = kVP;
210  return true;
211  }
212  else if (CamArray5.valid == false) {
213  CamArray5 = kVP;
214  return true;
215  }
216  else if (CamArray6.valid == false) {
217  CamArray6 = kVP;
218  return true;
219  }
220  else if (CamArray7.valid == false) {
221  CamArray7 = kVP;
222  return true;
223  }
224  else {
225  return false;
226  }
227  }
228 
229  bool insert(K key, V value)
230  {
231 #pragma HLS INLINE
232  return insert(KeyValuePair<K,V>(key,value,true));
233  }
234 
235 
243  bool update(K key, V value)
244  {
245 #pragma HLS pipeline II=1
246 #pragma HLS INLINE
247  if ((CamArray0.key == key) && (CamArray0.valid == true)) {
248  CamArray0.value = value;
249  return true;
250  }
251  else if ((CamArray1.key == key) && (CamArray1.valid == true)) {
252  CamArray1.value = value;
253  return true;
254  }
255  else if ((CamArray2.key == key) && (CamArray2.valid == true)) {
256  CamArray2.value = value;
257  return true;
258  }
259  else if ((CamArray3.key == key) && (CamArray3.valid == true)) {
260  CamArray3.value = value;
261  return true;
262  }
263  else if ((CamArray4.key == key) && (CamArray4.valid == true)) {
264  CamArray4.value = value;
265  return true;
266  }
267  else if ((CamArray5.key == key) && (CamArray5.valid == true)) {
268  CamArray5.value = value;
269  return true;
270  }
271  else if ((CamArray6.key == key) && (CamArray6.valid == true)) {
272  CamArray6.value = value;
273  return true;
274  }
275  else if ((CamArray7.key == key) && (CamArray7.valid == true)) {
276  CamArray7.value = value;
277  return true;
278  }
279  else {
280  return false;
281  }
282  }
283 
285  {
286 #pragma HLS INLINE
287  return update(kVP.key, kVP.value);
288  }
289 
290 
297  bool deleteEntry(K key)
298  {
299 #pragma HLS pipeline II=1
300 #pragma HLS INLINE
301 
302  if ((CamArray0.key == key) && (CamArray0.valid == true)) {
303  CamArray0.valid = false;
304  return true;
305  }
306  else if ((CamArray1.key == key) && (CamArray1.valid == true)) {
307  CamArray1.valid = false;
308  return true;
309  }
310  else if ((CamArray2.key == key) && (CamArray2.valid == true)) {
311  CamArray2.valid = false;
312  return true;
313  }
314  else if ((CamArray3.key == key) && (CamArray3.valid == true)) {
315  CamArray3.valid = false;
316  return true;
317  }
318  else if ((CamArray4.key == key) && (CamArray4.valid == true)) {
319  CamArray4.valid = false;
320  return true;
321  }
322  else if ((CamArray5.key == key) && (CamArray5.valid == true)) {
323  CamArray5.valid = false;
324  return true;
325  }
326  else if ((CamArray6.key == key) && (CamArray6.valid == true)) {
327  CamArray6.valid = false;
328  return true;
329  }
330  else if ((CamArray7.key == key) && (CamArray7.valid == true)) {
331  CamArray7.valid = false;
332  return true;
333  }
334  else {
335  return false;
336  }
337  }
338 
339 
343  void reset()
344  {
345 #pragma HLS pipeline II=1
346 #pragma HLS INLINE
347 
348  CamArray0.valid = false;
349  CamArray1.valid = false;
350  CamArray2.valid = false;
351  CamArray3.valid = false;
352  CamArray4.valid = false;
353  CamArray5.valid = false;
354  CamArray6.valid = false;
355  CamArray7.valid = false;
356  }
357 };
358 
359 
360 #endif
361 
Definition: cam8.hpp:59
Cam8()
Definition: cam8.hpp:70
bool update(K key, V value)
Search the CAM array for a key and updates the corresponding value.
Definition: cam8.hpp:243
KeyValuePair< K, V > CamArray0
Definition: cam8.hpp:61
bool insert(K key, V value)
Definition: cam8.hpp:229
bool lookup(K key, V &value)
Search the CAM array for a key.
Definition: cam8.hpp:89
bool reverse_lookup(V value, K &key)
Reverse-search the CAM array for a key to a value.
Definition: cam8.hpp:138
bool deleteEntry(K key)
Remove a key-value pair from the CAM array.
Definition: cam8.hpp:297
KeyValuePair< K, V > CamArray1
Definition: cam8.hpp:62
bool update(KeyValuePair< K, V > kVP)
Definition: cam8.hpp:284
KeyValuePair< K, V > CamArray4
Definition: cam8.hpp:65
bool insert(KeyValuePair< K, V > kVP)
Insert a new key-value pair in the CAM array.
Definition: cam8.hpp:187
KeyValuePair< K, V > CamArray7
Definition: cam8.hpp:68
KeyValuePair< K, V > CamArray5
Definition: cam8.hpp:66
KeyValuePair< K, V > CamArray6
Definition: cam8.hpp:67
KeyValuePair< K, V > CamArray2
Definition: cam8.hpp:63
KeyValuePair< K, V > CamArray3
Definition: cam8.hpp:64
void reset()
Invalidate all entries of the CAM array.
Definition: cam8.hpp:343
KeyValuePair()
Definition: cam8.hpp:46
KeyValuePair(K key, V value)
Definition: cam8.hpp:51
KeyValuePair(K key, V value, bool valid)
Definition: cam8.hpp:53
bool valid
Definition: cam16.hpp:46