11 #ifndef INLCUDE_MOLASSEMBLER_TEMPLE_CONSTEXPR_DYNAMIC_MAP_H
12 #define INLCUDE_MOLASSEMBLER_TEMPLE_CONSTEXPR_DYNAMIC_MAP_H
18 namespace Molassembler {
29 template<
typename KeyType,
typename MappedType,
size_t N>
43 constexpr
static auto keyComparator_ = std::less<KeyType>();
47 constexpr
bool operator() (
51 return keyComparator_(a.first, b.first);
56 constexpr
static auto keyComparator_ = std::equal_to<KeyType>();
60 constexpr
bool operator() (
64 return keyComparator_(a.first, b.first);
78 : items_(other.items_)
82 : items_(other.items_)
85 constexpr DynamicMap& operator = (
const DynamicMap& other) {
86 items_ = other.items_;
90 constexpr DynamicMap& operator = (DynamicMap&& other) noexcept {
91 items_ = other.items_;
106 PairType pair { std::move(key), std::move(item) };
109 throw "Map already contains an item for this key!";
124 PairType pair { std::move(key), std::move(item) };
126 auto searchIter = items_.find(pair);
128 if(searchIter == items_.end()) {
132 auto indexOfElement =
static_cast<unsigned>(
133 searchIter - items_.begin()
137 *(items_.begin() + indexOfElement) = pair;
152 constexpr
const MappedType&
at(
const KeyType& key)
const {
154 auto keyOptional = items_.getOption(pair);
156 if(!keyOptional.hasValue()) {
157 throw "No such key in this DynamicMap!";
160 return keyOptional.value().second;
168 constexpr
unsigned size()
const {
169 return items_.size();
175 using const_iterator =
typename SetType::const_iterator;
177 constexpr const_iterator begin()
const {
178 return items_.begin();
181 constexpr const_iterator end()
const {
188 constexpr
bool operator == (
const DynamicMap& other)
const {
189 return items_ == other.items_;
192 constexpr
bool operator != (
const DynamicMap& other)
const {
193 return !(*
this == other);
196 constexpr
bool operator < (
const DynamicMap& other)
const {
197 return items_ < other.items_;
200 constexpr
bool operator > (
const DynamicMap& other)
const {
201 return other.items_ < items_;
PURITY_WEAK constexpr bool contains(const T &item) const
Check if the set contains an element.
Definition: DynamicSet.h:61
A constexpr associative container with reasonably fast key-based lookup.
Definition: DynamicMap.h:30
constexpr void clear()
Inserts an element into the map.
Definition: DynamicMap.h:141
Heterogeneous pair type.
Definition: Pair.h:27
Definition: DynamicMap.h:42
constexpr void insertOrUpdate(KeyType key, MappedType item)
Inserts a key-value pair into the map or updates the mapped value if the key exists.
Definition: DynamicMap.h:120
constexpr void insert(KeyType key, MappedType item)
Inserts an element into the map.
Definition: DynamicMap.h:102
constexpr unsigned size() const
Number of items in the map.
Definition: DynamicMap.h:168
BTree-based std::set-like container (but max size is space allocated)
constexpr const MappedType & at(const KeyType &key) const
Value lookup.
Definition: DynamicMap.h:152
constexpr void clear()
Remove all elements of the set.
Definition: DynamicSet.h:78
Definition: DynamicMap.h:55
constexpr void insert(const T &item)
Insertion an element into the set.
Definition: DynamicSet.h:69