| 20 | // fail. Because of this limitation, this set is not a drop in |
| 21 | // replacement for std::map. |
| 22 | template <typename Key, typename Value, fl::size N> class unsorted_map_fixed { |
| 23 | public: |
| 24 | enum insert_result { inserted = 0, exists = 1, at_capacity = 2 }; |
| 25 | |
| 26 | using PairKV = fl::pair<Key, Value>; |
| 27 | |
| 28 | typedef FixedVector<PairKV, N> VectorType; |
| 29 | typedef typename VectorType::iterator iterator; |
| 30 | typedef typename VectorType::const_iterator const_iterator; |
| 31 | |
| 32 | // Constructor |
| 33 | constexpr unsorted_map_fixed() FL_NOEXCEPT = default; |
| 34 | |
| 35 | iterator begin() { return data.begin(); } |
| 36 | iterator end() { return data.end(); } |
| 37 | const_iterator begin() const { return data.begin(); } |
| 38 | const_iterator end() const { return data.end(); } |
| 39 | |
| 40 | iterator find(const Key &key) { |
| 41 | for (auto it = begin(); it != end(); ++it) { |
| 42 | if (it->first == key) { |
| 43 | return it; |
| 44 | } |
| 45 | } |
| 46 | return end(); |
| 47 | } |
| 48 | |
| 49 | const_iterator find(const Key &key) const { |
| 50 | for (auto it = begin(); it != end(); ++it) { |
| 51 | if (it->first == key) { |
| 52 | return it; |
| 53 | } |
| 54 | } |
| 55 | return end(); |
| 56 | } |
| 57 | |
| 58 | template <typename Less> iterator lowest(Less less_than = Less()) { |
| 59 | iterator lowest = end(); |
| 60 | for (iterator it = begin(); it != end(); ++it) { |
| 61 | if (lowest == end() || less_than(it->first, lowest->first)) { |
| 62 | lowest = it; |
| 63 | } |
| 64 | } |
| 65 | return lowest; |
| 66 | } |
| 67 | |
| 68 | template <typename Less> |
| 69 | const_iterator lowest(Less less_than = Less()) const { |
| 70 | const_iterator lowest = end(); |
| 71 | for (const_iterator it = begin(); it != end(); ++it) { |
| 72 | if (lowest == end() || less_than(it->first, lowest->first)) { |
| 73 | lowest = it; |
| 74 | } |
| 75 | } |
| 76 | return lowest; |
| 77 | } |
| 78 | |
| 79 | template <typename Less> iterator highest(Less less_than = Less()) { |