|
Open Graph Drawing Framework |
v. 2023.09 (Elderberry)
|
|
|
Go to the documentation of this file.
41 #include <unordered_map>
51 template<
typename Key2,
typename Value,
int array_max>
76 if (
copy.m_value ==
nullptr) {
91 swap(first.m_size, second.m_size);
92 swap(first.m_value, second.m_value);
101 int cnt = map.erase(key);
109 for (
int i = 0; i <
m_size; ++i) {
110 if (array[i].first == key) {
131 auto it = map.find(key);
132 if (it != map.end()) {
137 auto ins = map.insert({key, def});
139 return ins.first->second;
142 if (pair.first == key) {
151 return (*array)[1].second;
154 for (
int i = 0; i <
m_size; ++i) {
155 if (array[i].first == key) {
156 return array[i].second;
165 return array[i].second;
169 for (
int i = 0; i < array_max; ++i) {
182 throw std::out_of_range(
"no keys stored");
185 auto it = map.find(key);
186 if (it == map.end()) {
187 throw std::out_of_range(
"key not in map");
192 if (pair.first == key) {
195 throw std::out_of_range(
"key not in scalar");
199 for (
int i = 0; i <
m_size; ++i) {
200 if (array[i].first == key) {
201 return array[i].second;
204 throw std::out_of_range(
"key not in array");
217 for (
int i = 0; i <
m_size; ++i) {
218 if (array[i].first == key) {
259 template<
typename Key1,
typename Key2,
typename Value,
template<
typename...>
class BaseArray,
288 return m_array[k1].get_or_raise(k2);
295 void remove(
const Key1& k1,
const Key2& k2) {
return m_array[k1].unset(k2); }
297 bool contains(
const Key1& k1,
const Key2& k2)
const {
return m_array[k1].contains(k2); }
301 bool has(
const Key1& k1)
const {
return !
m_array[k1].empty(k1); }
The namespace for all OGDF objects.
ValueArrayType & getValueArray() const
void remove(const Key1 &k1, const Key2 &k2)
Value & get_or_raise(const Key2 &key) const
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
friend void swap(UsuallySmallMap &first, UsuallySmallMap &second) noexcept
Utility macros for declaring copy and move constructors and assignment operations.
ValuePairType & getValueScalar() const
#define OGDF_DEFAULT_MOVE(cls)
Explicitly provides default move construction and assignment for class cls.
RegisteredMultiArray(T &&... t)
Value & operator()(const Key1 &k1, const Key2 &k2)
std::array< ValuePairType, array_max > ValueArrayType
BaseArray< EntryType > m_array
A wrapper around std::map that uses a constant-size array (or only a single value) plus linear search...
UsuallySmallMap()=default
void unset(const Key2 &key)
static void copy(const T &from, T &to)
Data structure for two-dimensional mappings that are sparse in the second dimension.
const T & move(const T &v)
Value & get_or_create(const Key2 &key, const Value &def=Value())
Value & get_or_raise(const Key1 &k1, const Key2 &k2)
const Value & get_or_raise(const Key1 &k1, const Key2 &k2) const
bool contains(const Key2 &key) const
ValueMapType & getValueMap() const
size_t count(const Key1 &k1) const
const EntryType & get_all(const Key1 &k1) const
#define OGDF_COPY_MOVE_BY_SWAP(cls)
Provide move construct/assign and copy assign given there is a copy constructor and swap.
EntryType & get_all(const Key1 &k1)
bool has(const Key1 &k1) const
Basic declarations, included by all source files.
bool contains(const Key1 &k1, const Key2 &k2) const
UsuallySmallMap(const UsuallySmallMap ©)
std::pair< Key2, Value > ValuePairType
Value & get_or_create(const Key1 &k1, const Key2 &k2)
std::unordered_map< Key2, Value > ValueMapType
#define OGDF_DEFAULT_COPY(cls)
Explicitly provides default copy construction and assignment for class cls.
RegisteredMultiArray()=default
#define OGDF_SWAP_OP(cls)
Declares the swap function for class cls.