fixed ordered multi map changes integrated

This commit is contained in:
Robin Müller 2020-09-10 16:01:05 +02:00
parent d9dcee3692
commit e57d4a11ae
2 changed files with 8 additions and 20 deletions

View File

@ -1,5 +1,5 @@
#ifndef FRAMEWORK_CONTAINER_FIXEDORDEREDMULTIMAP_H_ #ifndef FSFW_CONTAINER_FIXEDORDEREDMULTIMAP_H_
#define FRAMEWORK_CONTAINER_FIXEDORDEREDMULTIMAP_H_ #define FSFW_CONTAINER_FIXEDORDEREDMULTIMAP_H_
#include "../container/ArrayList.h" #include "../container/ArrayList.h"
#include <cstring> #include <cstring>
@ -39,10 +39,6 @@ public:
Iterator(); Iterator();
/** Initializes iterator to given entry */ /** Initializes iterator to given entry */
Iterator(std::pair<key_t, T> *pair); Iterator(std::pair<key_t, T> *pair);
/** Dereference operator can be used to get value */
T operator*();
/** Arrow operator can be used to get pointer to value */
T *operator->();
}; };
/** Iterator to start of map */ /** Iterator to start of map */
@ -160,7 +156,8 @@ private:
if (_size <= position) { if (_size <= position) {
return; return;
} }
memmove(&theMap[position], &theMap[position + 1], std::memmove(static_cast<void*>(&theMap[position]),
static_cast<void*>(&theMap[position + 1]),
(_size - position - 1) * sizeof(std::pair<key_t,T>)); (_size - position - 1) * sizeof(std::pair<key_t,T>));
--_size; --_size;
} }
@ -168,4 +165,4 @@ private:
#include "FixedOrderedMultimap.tpp" #include "FixedOrderedMultimap.tpp"
#endif /* FRAMEWORK_CONTAINER_FIXEDORDEREDMULTIMAP_H_ */ #endif /* FSFW_CONTAINER_FIXEDORDEREDMULTIMAP_H_ */

View File

@ -10,11 +10,6 @@ inline FixedOrderedMultimap<key_t, T, KEY_COMPARE>::Iterator::Iterator(
std::pair<key_t, T> *pair): std::pair<key_t, T> *pair):
ArrayList<std::pair<key_t, T>, uint32_t>::Iterator(pair){} ArrayList<std::pair<key_t, T>, uint32_t>::Iterator(pair){}
template<typename key_t, typename T, typename KEY_COMPARE>
inline T FixedOrderedMultimap<key_t, T, KEY_COMPARE>::Iterator::operator*() {
return ArrayList<std::pair<key_t, T>, uint32_t>::Iterator::value->second;
}
template<typename key_t, typename T, typename KEY_COMPARE> template<typename key_t, typename T, typename KEY_COMPARE>
inline typename FixedOrderedMultimap<key_t, T, KEY_COMPARE>::Iterator inline typename FixedOrderedMultimap<key_t, T, KEY_COMPARE>::Iterator
FixedOrderedMultimap<key_t, T, KEY_COMPARE>::begin() const { FixedOrderedMultimap<key_t, T, KEY_COMPARE>::begin() const {
@ -33,11 +28,6 @@ inline size_t FixedOrderedMultimap<key_t, T, KEY_COMPARE>::size() const {
return _size; return _size;
} }
template<typename key_t, typename T, typename KEY_COMPARE>
inline T* FixedOrderedMultimap<key_t, T, KEY_COMPARE>::Iterator::operator->() {
return &ArrayList<std::pair<key_t, T>, uint32_t>::Iterator::value->second;
}
template<typename key_t, typename T, typename KEY_COMPARE> template<typename key_t, typename T, typename KEY_COMPARE>
inline FixedOrderedMultimap<key_t, T, KEY_COMPARE>::FixedOrderedMultimap( inline FixedOrderedMultimap<key_t, T, KEY_COMPARE>::FixedOrderedMultimap(
size_t maxSize): theMap(maxSize), _size(0) {} size_t maxSize): theMap(maxSize), _size(0) {}
@ -52,8 +42,9 @@ inline ReturnValue_t FixedOrderedMultimap<key_t, T, KEY_COMPARE>::insert(
uint32_t position = findNicePlace(key); uint32_t position = findNicePlace(key);
// Compiler might emitt warning because std::pair is not a POD type (yet..) // Compiler might emitt warning because std::pair is not a POD type (yet..)
// See: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2342.htm#std::pair-example // See: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2342.htm#std::pair-example
// Should still work without issues. // Circumvent warning by casting to void*
std::memmove(&theMap[position + 1], &theMap[position], std::memmove(static_cast<void*>(&theMap[position + 1]),
static_cast<void*>(&theMap[position]),
(_size - position) * sizeof(std::pair<key_t,T>)); (_size - position) * sizeof(std::pair<key_t,T>));
theMap[position].first = key; theMap[position].first = key;
theMap[position].second = value; theMap[position].second = value;