13 template <
typename TKey,
typename TValue>
36 Element* element = this->find(key);
38 return element->
value;
45 const Element* element = this->find(key);
47 return element->
value;
52 Element* element = this->find(key);
54 return this->add(key, value);
56 element->
value = value;
57 return element->
value;
63 Element* element = this->find(key);
65 return this->add(key, std::move(value));
67 element->
value = std::move(value);
68 return element->
value;
76 Element* element = this->find(key);
78 const Size index = element - &data[0];
86 Element* element = this->find(key);
90 const Size index = element - &data[0];
105 Element* element = this->find(key);
109 return element->
value;
115 const Element* element = this->find(key);
119 return element->
value;
127 return this->find(key) !=
nullptr;
170 cloned.data = data.
clone();
176 INLINE Element* find(
const TKey& key) {
177 for (Element& element : data) {
178 if (element.key == key) {
185 INLINE const Element* find(
const TKey& key)
const {
190 template <
typename T>
191 INLINE TValue& add(
const TKey& key, T&& value) {
192 data.push(Element{ key, std::forward<T>(value) });
193 return data.back().value;
Generic dynamically allocated resizable storage.
#define SPH_ASSERT(x,...)
uint32_t Size
Integral type used to index arrays (by default).
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
Wrapper of type value of which may or may not be present.
const NothingType NOTHING
Object providing safe access to continuous memory of data.
INLINE Iterator< StorageType > end() noexcept
void remove(const TCounter idx)
Removes an element with given index from the array.
void clear()
Removes all elements from the array, but does NOT release the memory.
INLINE TCounter size() const noexcept
INLINE bool empty() const noexcept
INLINE Iterator< StorageType > begin() noexcept
Array clone() const
Performs a deep copy of all elements of the array.
Simple (forward) iterator over continuous array of objects of type T.
Wrapper of type value of which may or may not be present.
INLINE Size size() const
Returns the number of elements in the map.
UnorderedMap(std::initializer_list< Element > list)
Constructs the map fromm initializer list of elements.
INLINE Iterator< const Element > end() const
Returns the iterator pointing to the one-past-last element.
INLINE bool contains(const TKey &key) const
Returns true if the map contains element of given key.
INLINE TValue & insert(const TKey &key, TValue &&value)
Adds a new element into the map or sets new value of element with the same key.
INLINE Optional< const TValue & > tryGet(const TKey &key) const
Returns a reference to the value matching the given key, or NOTHING if no such value exists.
INLINE void clear()
Removes all elements from the map.
UnorderedMap clone() const
INLINE Iterator< Element > end()
Returns the iterator pointing to the one-past-last element.
INLINE TValue & insert(const TKey &key, const TValue &value)
Adds a new element into the map or sets new value of element with the same key.
INLINE bool tryRemove(const TKey &key)
Removes element with given key if present, otherwise it does nothing.
INLINE Iterator< Element > begin()
Returns the iterator pointing to the first element.
INLINE void remove(const TKey &key)
Removes element with given key from the map.
INLINE const TValue & operator[](const TKey &key) const
Returns a reference to the element, given its key.
INLINE Optional< TValue & > tryGet(const TKey &key)
Returns a reference to the value matching the given key, or NOTHING if no such value exists.
INLINE Iterator< const Element > begin() const
Returns the iterator pointing to the first element.
INLINE TValue & operator[](const TKey &key)
Returns a reference to the element, given its key.
INLINE Size empty() const
Returns true if the map contains no elements, false otherwise.
Object with deleted copy constructor and copy operator.
Element of the container.