Skip to content

Commit 38c9c82

Browse files
committed
Add SequentialMap::find, and name element to match std::map
1 parent adff191 commit 38c9c82

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

util/sequential_map.hh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class SequentialMap {
77
public:
88
struct PairT {
99
KeyT key;
10-
ValT element;
10+
ValT second;
1111
};
1212

1313
using DataT = FixedVector<PairT, N>;
@@ -16,23 +16,23 @@ public:
1616
const ValT &operator[](const KeyT key) const {
1717
for (auto &pair : data) {
1818
if (pair.key == key)
19-
return pair.element;
19+
return pair.second;
2020
}
2121
return ValT{};
2222
}
2323

2424
ValT &operator[](const KeyT key) {
2525
for (auto &pair : data) {
2626
if (pair.key == key)
27-
return pair.element;
27+
return pair.second;
2828
}
2929

3030
auto newsize = data.push_back_for_overwrite();
3131
if (newsize == data.max_size()) {
3232
// Overflow: silently return last element
3333
newsize--;
3434
}
35-
return data[newsize].element;
35+
return data[newsize].second;
3636
}
3737

3838
void clear() {
@@ -43,7 +43,15 @@ public:
4343
return data.size() == data.max_size();
4444
}
4545

46-
bool exists(const KeyT key) {
46+
auto find(KeyT key) {
47+
for (auto it = data.begin(); it < data.end(); it++) {
48+
if (it->key == key)
49+
return it;
50+
}
51+
return data.end();
52+
}
53+
54+
bool exists(const KeyT key) const {
4755
for (auto &pair : data) {
4856
if (pair.key == key)
4957
return true;

0 commit comments

Comments
 (0)