Cpp Utilities 1.2.3
SequencialMap.hpp
Go to the documentation of this file.
1#ifndef CPP_UTILITIES_CONTAINERS_SEQUENCIALMAP_HPP
2#define CPP_UTILITIES_CONTAINERS_SEQUENCIALMAP_HPP
3
4#include <cassert>
5#include <utility>
6#include <algorithm>
7#include <map>
8#include <vector>
9#include <memory>
10#include <iterator>
11#include <type_traits>
12#include <initializer_list>
13#include <functional>
14#include "../Common.h"
15
28
35namespace Container {
66template<typename Key,
67 typename T,
68 typename Compare = std::less<Key>,
69 typename Allocator = std::allocator<std::pair<const Key, T>>>
71{
72public:
76 using allocator_type = Allocator;
80 using map_type = std::map<Key, T, Compare, Allocator>;
85 using vector_type = std::vector<typename map_type::iterator>;
86
90 using key_type = typename map_type::key_type;
94 using mapped_type = typename map_type::mapped_type;
98 using key_compare = typename map_type::key_compare;
102 using value_compare = typename map_type::value_compare;
103
107 using value_type = typename map_type::value_type;
111 using pointer = typename map_type::pointer;
115 using const_pointer = typename map_type::const_pointer;
119 using reference = typename map_type::reference;
123 using const_reference = typename map_type::const_reference;
127 using size_type = typename map_type::size_type;
131 using difference_type = typename map_type::difference_type;
132
133 // Forward declaration
134 template<bool constant> struct iterator_base;
146 using reverse_iterator = std::reverse_iterator<iterator>;
150 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
151 // Forward declaration
152 struct key_iterator;
156 using reverse_key_iterator = std::reverse_iterator<key_iterator>;
157
162 {
163// static_assert(!std::is_arithmetic<Key>::value, "Key type cannot not be arithmetic!");
164 }
165
171 explicit SequencialMap(const Compare& comp, const Allocator& alloc = Allocator())
172 : m(comp, alloc)
173 {
174// static_assert(!std::is_arithmetic<Key>::value, "Key type cannot not be arithmetic!");
175 }
176
186 template<typename InputIt>
187 SequencialMap(InputIt first, InputIt last, const Compare& comp = Compare(), const Allocator& alloc = Allocator())
188 : m(comp, alloc)
189 {
190// static_assert(!std::is_arithmetic<Key>::value, "Key type cannot not be arithmetic!");
191 push_back(first, last);
192 }
193
202 template<typename InputIt>
203 SequencialMap(InputIt first, InputIt last, const Allocator& alloc)
204 : m(Compare(), alloc)
205 {
206// static_assert(!std::is_arithmetic<Key>::value, "Key type cannot not be arithmetic!");
207 push_back(first, last);
208 }
209
221 SequencialMap(const SequencialMap& other, const Allocator& alloc = Allocator())
222 : m(Compare(), alloc)
223 { push_back(other.begin(), other.end()); }
224
234 SequencialMap(SequencialMap&& other, const Allocator& alloc = Allocator())
235 : v(std::forward<vector_type>(other.v), alloc), m(std::forward<map_type>(other.m))
236 {
237 }
238
247 SequencialMap(std::initializer_list<value_type> init,
248 const Compare& comp = Compare(),
249 const Allocator& alloc = Allocator())
250 : v(alloc), m(comp)
251 {
252// static_assert(!std::is_arithmetic<Key>::value, "Key type cannot not be arithmetic!");
253 push_back(init);
254 }
255
261 ~SequencialMap() = default;
262
268 { return m.get_allocator(); }
269
278 bool empty() const noexcept
279 { return m.empty(); }
280
289 size_type size() const noexcept
290 { return m.size(); }
291
305 size_type max_size() const noexcept
306 { return m.max_size(); }
307
318 void clear() noexcept
319 { v.clear(); m.clear(); }
320
330 bool contains(const key_type& key) const
331 { return find(key) != cend(); }
332
343 {
344 return std::find_if(begin(), end(), [&key](const value_type& value){
345 return value.first == key;
346 });
347 }
348
359 {
360 return std::find_if(cbegin(), cend(), [&key](const value_type& value){
361 return value.first == key;
362 });
363 }
364
378 template<typename Container = std::vector<key_type>>
380 {
381 Container ret;
382 for (auto it = key_begin(); it != key_end(); ++it)
383 { ret.push_back(*it); }
384 return ret;
385 }
386
401 const key_type key(const T& value, const key_type& defaultKey = key_type()) const
402 {
403 auto it = std::find_if(cbegin(), cend(), [&value](const value_type& v){
404 return v.second == value;
405 });
406 if (it == cend()) return defaultKey;
407 else return it->first;
408 }
409
423 template<typename Container = std::vector<T>>
425 {
426 Container ret;
427 for (auto it = cbegin(); it != cend(); ++it)
428 { ret.push_back(it->second); }
429 return ret;
430 }
431
446 const T& value(const key_type& key, const T& defaultValue = T()) const
447 {
448 auto it = find(key);
449 if (it == cend()) return defaultValue;
450 else return it->second;
451 }
452
466 { return *v.at(pos); }
467
481 { return *v.at(pos); }
482
496 {
497 auto pair = m.insert(std::make_pair(key, T()));
498 if (pair.second) v.push_back(pair.first);
499 return pair.first->second;
500 }
501
515 {
516 auto pair = m.insert(std::make_pair(key, T()));
517 if (pair.second) v.push_back(pair.first);
518 return pair.first->second;
519 }
520
532 const T operator[](const key_type& key) const
533 {
534 auto it = find(key);
535 if (it != cend()) return it->second;
536 else return T();
537 }
538
550 const T operator[](key_type&& key) const
551 {
552 auto it = find(key);
553 if (it != cend()) return it->second;
554 else return T();
555 }
556
566 { return *begin(); }
567
577 { return *cbegin(); }
578
588 { return *(end() - 1); }
589
599 { return *(cend() - 1); }
600
612 { return mid(pos, size() - pos); }
613
627 {
628 SequencialMap ret;
629 if (pos >= size()) return ret;
630 length = std::min(length, size() - pos);
631 ret.insert(0, begin() + pos, begin() + pos + length);
632 return ret;
633 }
634
647 std::pair<iterator, bool> push_back(const_reference value)
648 {
649 auto it = find(value.first);
650 if (it != end()) return std::make_pair(it, false);
651 auto pair = m.insert(value);
652 v.push_back(pair.first);
653 return std::make_pair(end() - 1, true);
654 }
655
668 std::pair<iterator, bool> push_back(value_type&& value)
669 {
670 value_type temp(std::forward<value_type>(value));
671 auto it = find(temp.first);
672 if (it != end()) return std::make_pair(it, false);
673 auto pair = m.insert(std::move(temp));
674 v.push_back(pair.first);
675 return std::make_pair(end() - 1, true);
676 }
677
691 std::pair<iterator, bool> push_back(const key_type& key, const T& value)
692 { return push_back(std::make_pair(key, value)); }
693
707 std::pair<iterator, bool> push_back(const key_type& key, T&& value)
708 { return push_back(std::make_pair(key, std::forward<T>(value))); }
709
719 void push_back(const SequencialMap& other)
720 { push_back(other.cbegin(), other.cend()); }
721
731 void push_back(std::initializer_list<value_type> ilist)
732 { push_back(ilist.begin(), ilist.end()); }
733
744 template<typename InputIt>
745 void push_back(InputIt first, InputIt last)
746 {
747 for (auto it = first; it != last; ++it)
748 { push_back(*it); }
749 }
750
768 template<typename... Args>
769 std::pair<iterator, bool> emplace_back(const key_type& key, Args&&... args)
770 {
771 return emplace_at(size(), key, std::forward<Args>(args)...);
772 }
773
791 template<typename... Args>
792 std::pair<iterator, bool> emplace_back(key_type&& key, Args&&... args)
793 {
794 return emplace_at(size(), std::forward<key_type>(key), std::forward<Args>(args)...);
795 }
796
807 { auto ret = *this; ret.push_back(other.begin(), other.end()); return ret; }
808
819 {
820 SequencialMap ret = *this;
821 for (auto&& value : other) {
822 ret.push_back(std::forward<value_type>(value));
823 }
824 return ret;
825 }
826
838 { push_back(other.begin(), other.end()); return *this; }
839
851 {
852 for (auto&& value : other) {
853 push_back(std::forward<value_type>(value));
854 }
855 return *this;
856 }
857
871 {
872 auto it = find(value.first);
873 if (it != end()) return it;
874 auto pair = m.insert(value);
875 v.insert(v.begin() + pos, pair.first);
876 return begin() + pos;
877 }
878
894 {
895 value_type temp(std::forward<value_type>(value));
896 auto it = find(temp.first);
897 if (it != end()) return it;
898 auto pair = m.insert(std::move(temp));
899 v.insert(v.begin() + pos, pair.first);
900 return begin() + pos;
901 }
902
918 iterator insert(size_t pos, const key_type& key, const T& value)
919 { return insert(pos, std::make_pair(key, value)); }
920
936 iterator insert(size_t pos, const key_type& key, T&& value)
937 { return insert(pos, std::make_pair(key, std::forward<T>(value))); }
938
954 { return insert(pos - begin(), value); }
955
971 { return insert(pos - begin(), std::forward<value_type>(value)); }
972
988 iterator insert(iterator pos, const key_type& key, const T& value)
989 { return insert(pos, std::make_pair(key, value)); }
990
1007 { return insert(pos, std::make_pair(key, std::forward<T>(value))); }
1008
1023 template<typename InputIt>
1024 void insert(size_t pos, InputIt first, InputIt last)
1025 { insert(begin() + pos, first, last); }
1026
1039 void insert(size_t pos, std::initializer_list<value_type> ilist)
1040 { insert(begin() + pos, ilist); }
1041
1056 template<typename InputIt>
1057 void insert(iterator pos, InputIt first, InputIt last)
1058 {
1059 difference_type index = pos - begin();
1060 for (auto it = first; it != last; ++it)
1061 {
1062 auto temp = find(it->first);
1063 if (temp != cend()) { continue; }
1064 else { insert(index, it->first, it->second); ++index; }
1065 }
1066 }
1067
1080 void insert(iterator pos, std::initializer_list<value_type> ilist)
1081 { insert(pos, ilist.begin(), ilist.end()); }
1082
1108 template<typename... Args>
1109 std::pair<iterator, bool> emplace_at(size_t pos, const key_type& key, Args&&... args)
1110 {
1111 key_type k = key;
1112 auto it = find(k);
1113 if (it != end()) return std::make_pair(it, false);
1114 auto pair = m.emplace(std::move(k), std::forward<Args>(args)...);
1115 v.insert(v.begin() + pos, pair.first);
1116 return std::make_pair(begin() + pos, true);
1117 }
1118
1144 template<typename... Args>
1145 std::pair<iterator, bool> emplace_at(size_t pos, key_type&& key, Args&&... args)
1146 {
1147 key_type k = key;
1148 auto it = find(k);
1149 if (it != end()) return std::make_pair(it, false);
1150 auto pair = m.emplace(std::move(k), std::forward<Args>(args)...);
1151 v.insert(v.begin() + pos, pair.first);
1152 return std::make_pair(begin() + pos, true);
1153 }
1154
1180 template<typename... Args>
1182 {
1183 return emplace_at(hint - cbegin(),
1184 std::forward<key_type>(key),
1185 std::forward<Args>(args)...)
1186 .first;
1187 }
1188
1200 {
1201 auto it = v.back();
1202 v.pop_back();
1203 m.erase(it);
1204 }
1205
1222 void erase(const key_type& key)
1223 {
1224 auto it = find(key);
1225 if (it == cend()) return;
1226 else erase(it);
1227 }
1228
1246 void erase(size_type pos, size_type count = 1)
1247 {
1248 erase(cbegin() + pos, cbegin() + pos + count);
1249 }
1250
1270 {
1271 difference_type index = pos - cbegin();
1272 m.erase(*(pos.n));
1273 v.erase(v.begin() + (pos.n - v.data()));
1274 return begin() + index;
1275 }
1276
1297 {
1298 iterator ret;
1299 for (auto it = const_reverse_iterator(last); it != const_reverse_iterator(first); ++it)
1300 { ret = erase(it.base() - 1); }
1301 return ret;
1302 }
1303
1315 { return iterator(v.data()); }
1316
1328 { return cbegin(); }
1329
1341 { return const_iterator(v.data()); }
1342
1355 { return iterator(v.data() + size()); }
1356
1369 { return cend(); }
1370
1383 { return const_iterator(v.data() + size()); }
1384
1397 { return reverse_iterator(end()); }
1398
1411 { return crbegin(); }
1412
1425 { return const_reverse_iterator(cend()); }
1426
1439 { return reverse_iterator(begin()); }
1440
1453 { return crend(); }
1454
1467 { return const_reverse_iterator(cbegin()); }
1468
1480 { return key_iterator(v.data()); }
1481
1494 { return key_iterator(v.data() + size()); }
1495
1508 { return reverse_key_iterator(key_end()); }
1509
1522 { return reverse_key_iterator(key_begin()); }
1523
1533 {
1534 if (this == &other) return *this;
1535 clear(); push_back(other.begin(), other.end()); return *this;
1536 }
1537
1549 { other.swap(*this); return *this; }
1550
1560 SequencialMap& operator=(std::initializer_list<value_type> ilist)
1561 { clear(); insert(ilist); return *this; }
1562
1576 bool operator==(const SequencialMap& other) const
1577 { return m == other.m; }
1578
1592 bool operator!=(const SequencialMap& other) const
1593 { return *this != other; }
1594
1607 bool operator<(const SequencialMap& other) const
1608 { return m < other.m; }
1609
1622 bool operator<=(const SequencialMap& other) const
1623 { return m <= other.n; }
1624
1637 bool operator>(const SequencialMap& other) const
1638 { return m > other.m; }
1639
1653 bool operator>=(const SequencialMap& other) const
1654 { return m >= other.m; }
1655
1669 void swap(SequencialMap& other)
1670 {
1671 v.swap(other.v);
1672 m.swap(other.m);
1673 }
1674
1684 {
1685 return m.key_comp();
1686 }
1687
1698 {
1699 return m.value_comp();
1700 }
1701
1715 template<typename Stream>
1716 friend Stream& operator<<(Stream& out, const SequencialMap& map)
1717 {
1718 size_t count = std::min(size_t(10u), map.size());
1719 out << "SequencialMap(";
1720 for (auto it = map.cbegin(); it != map.cbegin() + count; ++it)
1721 {
1722 out << '(' << it->first << ',' << it->second << ')';
1723 if (it != map.cbegin() + count - 1) out << ',';
1724 }
1725 if (count < map.size()) out << ",...";
1726 out << ')';
1727 return out;
1728 }
1729
1730 struct SerializeManipulator;
1731
1744 { return SerializeManipulator{const_cast<SequencialMap&>(*this)}; }
1745
1758 { return SerializeManipulator{*this}; }
1759
1765 {
1774 template<typename Stream>
1775 friend Stream& operator<<(Stream& out, const SerializeManipulator& manip)
1776 {
1777 out << manip.map.size();
1778 for (const value_type& value : manip.map)
1779 { out << value.first << value.second; }
1780 return out;
1781 }
1782
1791 template<typename Stream>
1792 friend Stream& operator>>(Stream& in, SerializeManipulator manip)
1793 {
1794 manip.map.clear();
1795 size_t size;
1796 in >> size;
1797 for (size_t i = 0; i < size; ++i)
1798 {
1799 Key key;
1800 T value;
1801 in >> key >> value;
1802 manip.map.push_back(key, value);
1803 }
1804 return in;
1805 }
1806
1807 private:
1808 SequencialMap& map;
1809 };
1810
1815 template<bool constant>
1817 {
1818 using iterator_category = std::random_access_iterator_tag;
1820 using node_type = typename SequencialMap::vector_type::value_type;
1822 using pointer = typename std::conditional<constant, const value_type*, value_type*>::type;
1823 using reference = typename std::conditional<constant, const value_type&, value_type&>::type;
1824
1825 inline iterator_base() = default;
1826
1827 template<bool OtherConstant>
1829 : n(other.n)
1830 {
1831 }
1832
1833 inline reference operator*() const
1834 { return n->operator*(); }
1835
1836 inline pointer operator->() const
1837 { return n->operator->(); }
1838
1839 template<bool OtherConstant>
1841 { n = other.n; return *this; }
1842
1843 template<bool otherConstant>
1844 inline bool operator==(const iterator_base<otherConstant>& other) const
1845 { return (n == other.n); }
1846
1847 template<bool otherConstant>
1848 inline bool operator!=(const iterator_base<otherConstant>& other) const
1849 { return n != other.n; }
1850
1851 template<bool otherConstant>
1852 inline bool operator<(const iterator_base<otherConstant>& other) const
1853 { return n < other.n; }
1854
1855 template<bool otherConstant>
1856 inline bool operator<=(const iterator_base<otherConstant>& other) const
1857 { return n <= other.n; }
1858
1859 template<bool otherConstant>
1860 inline bool operator>(const iterator_base<otherConstant>& other) const
1861 { return n > other.n; }
1862
1863 template<bool otherConstant>
1864 inline bool operator>=(const iterator_base<otherConstant>& other) const
1865 { return n >= other.n; }
1866
1868 { ++n; return *this; }
1869
1871 { node_type* node = n; ++n; return iterator_base(node); }
1872
1874 { --n; return *this; }
1875
1877 { node_type* node = n; --n; return iterator_base(node); }
1878
1880 { n += j; return *this; }
1881
1883 { n -= j; return *this; }
1884
1886 { return iterator_base(n + j); }
1887
1889 { return it + j; }
1890
1892 { return iterator_base(n - j); }
1893
1895 { return difference_type(n - j.n); }
1896
1897 protected:
1898 inline explicit iterator_base(const node_type* node)
1899 : n(const_cast<node_type*>(node))
1900 {
1901 }
1902
1903 mutable node_type* n = nullptr;
1904 friend class SequencialMap;
1905 friend struct iterator_base<!constant>;
1906 };
1907
1912 {
1913 using iterator_category = std::random_access_iterator_tag;
1915 using node_type = typename SequencialMap::vector_type::value_type;
1916 using value_type = Key;
1917 using reference = const value_type&;
1918 using pointer = const value_type*;
1919
1920 inline key_iterator() = default;
1921
1922 inline key_iterator(const key_iterator& other)
1923 : n(other.n)
1924 {
1925 }
1926
1927 inline reference operator*() const
1928 { return n->operator*().first; }
1929
1930 inline pointer operator->() const
1931 { return &(n->operator->()->first); }
1932
1934 { n = other.n; return *this; }
1935
1936 inline bool operator==(const key_iterator& other) const
1937 { return (n == other.n); }
1938
1939 inline bool operator!=(const key_iterator& other) const
1940 { return n != other.n; }
1941
1942 inline bool operator<(const key_iterator& other) const
1943 { return n < other.n; }
1944
1945 inline bool operator<=(const key_iterator& other) const
1946 { return n <= other.n; }
1947
1948 inline bool operator>(const key_iterator& other) const
1949 { return n > other.n; }
1950
1951 inline bool operator>=(const key_iterator& other) const
1952 { return n >= other.n; }
1953
1955 { ++n; return *this; }
1956
1958 { const node_type* node = n; ++n; return key_iterator(node); }
1959
1961 { --n; return *this; }
1962
1964 { const node_type* node = n; --n; return key_iterator(node); }
1965
1967 { n += j; return *this; }
1968
1970 { n -= j; return *this; }
1971
1973 { return key_iterator(n + j); }
1974
1976 { return it + j; }
1977
1979 { return key_iterator(n - j); }
1980
1982 { return difference_type(n - j.n); }
1983
1984 private:
1985 inline explicit key_iterator(const node_type* node)
1986 : n(node)
1987 {
1988 }
1989
1990 const node_type* n = nullptr;
1991 friend class SequencialMap;
1992 };
1993
1994private:
1995 vector_type v;
1996 map_type m;
1997};
1998} // namespace Container
2002
2003namespace std {
2022template<typename Key,
2023 typename T,
2024 typename Compare = std::less<Key>,
2025 typename Allocator = std::allocator<std::pair<const Key, T>>>
2027{ lhs.swap(rhs); }
2028
2046template<class Key, class T, class Compare, class Alloc, class Pred>
2048{
2049 for (auto i = c.begin(), last = c.end(); i != last; )
2050 {
2051 if (pred(*i)) {
2052 i = c.erase(i);
2053 } else {
2054 ++i;
2055 }
2056 }
2057}
2058} // namespace std
2059
2062#endif // CPP_UTILITIES_CONTAINERS_SEQUENCIALMAP_HPP
#define UTILITIES_NAMESPACE_END
Define for end namespace declaration, nothing will be generated if UTILITIES_NAMESPACE isn't defined.
Definition: Common.h:92
#define UTILITIES_NAMESPACE_BEGIN
Define for begin namespace declaration, nothing will be generated if UTILITIES_NAMESPACE isn't define...
Definition: Common.h:91
Key-value container behaves like std::map, but extended with random-access operations and traverses i...
Definition: SequencialMap.hpp:71
std::reverse_iterator< iterator > reverse_iterator
Mutable reverse iterator type.
Definition: SequencialMap.hpp:146
void erase(size_type pos, size_type count=1)
Removes specified elements from the container.
Definition: SequencialMap.hpp:1246
const_reverse_iterator rend() const
Returns a reverse iterator to the element following the last element of the reversed container....
Definition: SequencialMap.hpp:1452
SequencialMap & operator=(const SequencialMap &other)
Replaces the contents of the input container.
Definition: SequencialMap.hpp:1532
bool empty() const noexcept
Checks if the container has no elements, i.e. whether begin() == end().
Definition: SequencialMap.hpp:278
reference back()
Returns a reference to the last element in the container.
Definition: SequencialMap.hpp:587
void swap(SequencialMap &other)
Exchanges the contents of the container with those of other. Does not invoke any move,...
Definition: SequencialMap.hpp:1669
const_iterator end() const
Returns an iterator to the element following the last element of the container. This element acts as...
Definition: SequencialMap.hpp:1368
const_reference front() const
Returns a const reference to the first element in the container.
Definition: SequencialMap.hpp:576
SequencialMap(std::initializer_list< value_type > init, const Compare &comp=Compare(), const Allocator &alloc=Allocator())
Constructs the container with the contents of the initializer list init. If multiple elements in the ...
Definition: SequencialMap.hpp:247
SequencialMap()
Default constructor, constructs an empty container.
Definition: SequencialMap.hpp:161
SequencialMap mid(size_type pos, size_type length) const
Returns a sub-map which contains elements from this map, starting at position pos,...
Definition: SequencialMap.hpp:626
std::vector< typename map_type::iterator > vector_type
Underlying map type for random-access operations and sequencial traversal.
Definition: SequencialMap.hpp:85
std::reverse_iterator< key_iterator > reverse_key_iterator
Reverse iterator to traverse keys.
Definition: SequencialMap.hpp:156
bool operator>(const SequencialMap &other) const
Compares the contents of two containers lexicographically.
Definition: SequencialMap.hpp:1637
SequencialMap operator+(const SequencialMap &other) const
Same as push_back, appends all elements from given container other to the end of the container,...
Definition: SequencialMap.hpp:806
SequencialMap(InputIt first, InputIt last, const Allocator &alloc)
Constructs the container with the contents of the range [first, last). If multiple elements in the ra...
Definition: SequencialMap.hpp:203
iterator find(const key_type &key)
Finds an element with key equivalent to key.
Definition: SequencialMap.hpp:342
SequencialMap(const Compare &comp, const Allocator &alloc=Allocator())
Constructs an empty container with given comparator and allocator.
Definition: SequencialMap.hpp:171
bool operator>=(const SequencialMap &other) const
Compares the contents of two containers lexicographically.
Definition: SequencialMap.hpp:1653
iterator insert(size_t pos, const key_type &key, T &&value)
Inserts element into the container, if the container doesn't already contain an element with an equiv...
Definition: SequencialMap.hpp:936
const_iterator cbegin() const
Returns an iterator to the first element of the container. If the container is empty,...
Definition: SequencialMap.hpp:1340
void erase_if(Container::SequencialMap< Key, T, Compare, Alloc > &c, Pred pred)
Erases all elements that satisfy the predicate pred from the container.
Definition: SequencialMap.hpp:2047
const_reverse_iterator crend() const
Returns a reverse iterator to the element following the last element of the reversed container....
Definition: SequencialMap.hpp:1466
typename map_type::difference_type difference_type
Provide same member type of std::map.
Definition: SequencialMap.hpp:131
void insert(iterator pos, std::initializer_list< value_type > ilist)
Inserts elements into the container, if the container doesn't already contain an element with an equi...
Definition: SequencialMap.hpp:1080
allocator_type get_allocator() const
Returns the allocator associated with the container.
Definition: SequencialMap.hpp:267
iterator insert(iterator pos, const_reference value)
Inserts element into the container, if the container doesn't already contain an element with an equiv...
Definition: SequencialMap.hpp:953
typename map_type::const_pointer const_pointer
Provide same member type of std::map.
Definition: SequencialMap.hpp:115
void pop_back()
Removes the last element of the container.
Definition: SequencialMap.hpp:1199
iterator erase(const_iterator pos)
Removes specified elements from the container.
Definition: SequencialMap.hpp:1269
SerializeManipulator serialize() const
Serialize the contents to output stream.
Definition: SequencialMap.hpp:1743
iterator insert(size_t pos, const_reference value)
Inserts element into the container, if the container doesn't already contain an element with an equiv...
Definition: SequencialMap.hpp:870
reverse_iterator rbegin()
Returns a reverse iterator to the first element of the reversed container. It corresponds to the last...
Definition: SequencialMap.hpp:1396
iterator erase(const_iterator first, const_iterator last)
Removes specified elements from the container.
Definition: SequencialMap.hpp:1296
reverse_iterator rend()
Returns a reverse iterator to the element following the last element of the reversed container....
Definition: SequencialMap.hpp:1438
std::pair< iterator, bool > push_back(value_type &&value)
Appends the given element value to the end of the container, if the container doesn't already contain...
Definition: SequencialMap.hpp:668
iterator emplace_hint(const_iterator hint, key_type &&key, Args &&... args)
Inserts a new element to the container as close as possible to the position just before hint....
Definition: SequencialMap.hpp:1181
typename map_type::value_compare value_compare
Provide same member type of std::map.
Definition: SequencialMap.hpp:102
size_type max_size() const noexcept
Returns the maximum number of elements the container is able to hold due to system or library impleme...
Definition: SequencialMap.hpp:305
SequencialMap & operator=(SequencialMap &&other)
Replaces the contents of the input container.
Definition: SequencialMap.hpp:1548
size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
Definition: SequencialMap.hpp:289
const T operator[](key_type &&key) const
Returns a copy to the value that is mapped to a key equivalent to key, return a default constructed v...
Definition: SequencialMap.hpp:550
SequencialMap & operator=(std::initializer_list< value_type > ilist)
Replaces the contents of the input container.
Definition: SequencialMap.hpp:1560
const_reference at(size_type pos) const
Returns a const reference to the element at specified location pos, with bounds checking.
Definition: SequencialMap.hpp:480
reference front()
Returns a reference to the first element in the container.
Definition: SequencialMap.hpp:565
T & operator[](const key_type &key)
Returns a reference to the value that is mapped to a key equivalent to key, performing an insertion i...
Definition: SequencialMap.hpp:495
value_compare value_comp() const
Returns a function object that compares objects of type std::map::value_type (key-value pairs) by usi...
Definition: SequencialMap.hpp:1697
T & operator[](key_type &&key)
Returns a reference to the value that is mapped to a key equivalent to key, performing an insertion i...
Definition: SequencialMap.hpp:514
std::pair< iterator, bool > emplace_at(size_t pos, const key_type &key, Args &&... args)
Inserts a new element to the container as close as possible to the position just before hint....
Definition: SequencialMap.hpp:1109
Allocator allocator_type
Provide same member type of std::map.
Definition: SequencialMap.hpp:76
iterator insert(iterator pos, const key_type &key, const T &value)
Inserts element into the container, if the container doesn't already contain an element with an equiv...
Definition: SequencialMap.hpp:988
iterator insert(iterator pos, const key_type &key, T &&value)
Inserts element into the container, if the container doesn't already contain an element with an equiv...
Definition: SequencialMap.hpp:1006
SequencialMap(InputIt first, InputIt last, const Compare &comp=Compare(), const Allocator &alloc=Allocator())
Constructs the container with the contents of the range [first, last). If multiple elements in the ra...
Definition: SequencialMap.hpp:187
bool operator<=(const SequencialMap &other) const
Compares the contents of two containers lexicographically.
Definition: SequencialMap.hpp:1622
reverse_key_iterator key_rbegin() const
Returns a reverse iterator to the first key of the reversed container. It corresponds to the last key...
Definition: SequencialMap.hpp:1507
reverse_key_iterator key_rend() const
Returns a reverse iterator to the key following the last key of the reversed container....
Definition: SequencialMap.hpp:1521
const_reference back() const
Returns a const reference to the last element in the container.
Definition: SequencialMap.hpp:598
const_reverse_iterator rbegin() const
Returns a reverse iterator to the first element of the reversed container. It corresponds to the last...
Definition: SequencialMap.hpp:1410
bool contains(const key_type &key) const
Checks if there is an element with key equivalent to key in the container.
Definition: SequencialMap.hpp:330
const T operator[](const key_type &key) const
Returns a copy to the value that is mapped to a key equivalent to key, return a default constructed v...
Definition: SequencialMap.hpp:532
friend Stream & operator<<(Stream &out, const SequencialMap &map)
Writes the contents of list to output stream.
Definition: SequencialMap.hpp:1716
const_reverse_iterator crbegin() const
Returns a reverse iterator to the first element of the reversed container. It corresponds to the last...
Definition: SequencialMap.hpp:1424
Container values() const
Returns a list containing all the values in the map in the sequence order of value appends.
Definition: SequencialMap.hpp:424
typename map_type::pointer pointer
Provide same member type of std::map.
Definition: SequencialMap.hpp:111
void insert(iterator pos, InputIt first, InputIt last)
Inserts elements into the container, if the container doesn't already contain an element with an equi...
Definition: SequencialMap.hpp:1057
std::pair< iterator, bool > emplace_back(key_type &&key, Args &&... args)
Appends a new element to the end of the container.
Definition: SequencialMap.hpp:792
void insert(size_t pos, InputIt first, InputIt last)
Inserts elements into the container, if the container doesn't already contain an element with an equi...
Definition: SequencialMap.hpp:1024
iterator_base< true > const_iterator
Immutable iterator type for constant LegacyRandomAccessIterator.
Definition: SequencialMap.hpp:142
void swap(Container::SequencialMap< Key, T, Compare, Allocator > &lhs, Container::SequencialMap< Key, T, Compare, Allocator > &rhs) noexcept
Specializes the std::swap algorithm.
Definition: SequencialMap.hpp:2026
void push_back(InputIt first, InputIt last)
Appends all elements from from range [first, last) to the end of the container, ignores all values wi...
Definition: SequencialMap.hpp:745
std::pair< iterator, bool > push_back(const_reference value)
Appends the given element value to the end of the container, if the container doesn't already contain...
Definition: SequencialMap.hpp:647
SequencialMap & operator+=(const SequencialMap &other)
Same as push_back, appends all elements from given container other to the end of the container and re...
Definition: SequencialMap.hpp:837
std::pair< iterator, bool > push_back(const key_type &key, T &&value)
Appends the given element value to the end of the container, if the container doesn't already contain...
Definition: SequencialMap.hpp:707
typename map_type::value_type value_type
Provide same member type of std::map.
Definition: SequencialMap.hpp:107
std::map< Key, T, Compare, Allocator > map_type
Underlying map type for map APIs.
Definition: SequencialMap.hpp:80
std::pair< iterator, bool > push_back(const key_type &key, const T &value)
Appends the given element value to the end of the container, if the container doesn't already contain...
Definition: SequencialMap.hpp:691
const T & value(const key_type &key, const T &defaultValue=T()) const
Returns the value associated with the key key.
Definition: SequencialMap.hpp:446
std::reverse_iterator< const_iterator > const_reverse_iterator
Immutable reverse iterator type.
Definition: SequencialMap.hpp:150
reference at(size_type pos)
Returns a reference to the element at specified location pos, with bounds checking.
Definition: SequencialMap.hpp:465
SequencialMap & operator+=(SequencialMap &&other)
Same as push_back, appends all elements from given container other to the end of the container and re...
Definition: SequencialMap.hpp:850
SequencialMap mid(size_type pos) const
Returns a sub-map which contains elements from this map, starting at position pos to the end.
Definition: SequencialMap.hpp:611
SequencialMap(const SequencialMap &other, const Allocator &alloc=Allocator())
Copy constructor. Constructs the container with the copy of the contents of other....
Definition: SequencialMap.hpp:221
Container keys() const
Returns a list containing all the keys in the map in the sequence order of value appends.
Definition: SequencialMap.hpp:379
~SequencialMap()=default
Destructs the container. The destructors of the elements are called and the used storage is deallocat...
key_iterator key_end() const
Returns an iterator to the key following the last key of the container. This key acts as a placehold...
Definition: SequencialMap.hpp:1493
typename map_type::key_compare key_compare
Provide same member type of std::map.
Definition: SequencialMap.hpp:98
iterator_base< false > iterator
Mutable iterator type for LegacyRandomAccessIterator.
Definition: SequencialMap.hpp:138
const_iterator begin() const
Returns an iterator to the first element of the container. If the container is empty,...
Definition: SequencialMap.hpp:1327
const_iterator find(const key_type &key) const
Finds an element with key equivalent to key.
Definition: SequencialMap.hpp:358
typename map_type::size_type size_type
Provide same member type of std::map.
Definition: SequencialMap.hpp:127
iterator insert(size_t pos, value_type &&value)
Inserts element into the container, if the container doesn't already contain an element with an equiv...
Definition: SequencialMap.hpp:893
typename map_type::key_type key_type
Provide same member type of std::map.
Definition: SequencialMap.hpp:90
SequencialMap operator+(SequencialMap &&other) const
Same as push_back, appends all elements from given container other to the end of the container,...
Definition: SequencialMap.hpp:818
const key_type key(const T &value, const key_type &defaultKey=key_type()) const
Returns the key with value value, or defaultKey if the map contains no item with value value.
Definition: SequencialMap.hpp:401
void erase(const key_type &key)
Removes specified element from the container.
Definition: SequencialMap.hpp:1222
bool operator<(const SequencialMap &other) const
Compares the contents of two containers lexicographically.
Definition: SequencialMap.hpp:1607
void clear() noexcept
Definition: SequencialMap.hpp:318
std::pair< iterator, bool > emplace_at(size_t pos, key_type &&key, Args &&... args)
Inserts a new element to the container as close as possible to the position just before hint....
Definition: SequencialMap.hpp:1145
typename map_type::const_reference const_reference
Provide same member type of std::map.
Definition: SequencialMap.hpp:123
typename map_type::mapped_type mapped_type
Provide same member type of std::map.
Definition: SequencialMap.hpp:94
key_compare key_comp() const
Returns the function object that compares the keys, which is a copy of this container's constructor a...
Definition: SequencialMap.hpp:1683
void insert(size_t pos, std::initializer_list< value_type > ilist)
Inserts elements into the container, if the container doesn't already contain an element with an equi...
Definition: SequencialMap.hpp:1039
iterator insert(iterator pos, value_type &&value)
Inserts element into the container, if the container doesn't already contain an element with an equiv...
Definition: SequencialMap.hpp:970
void push_back(std::initializer_list< value_type > ilist)
Appends all elements from initializer list ilist to the end of the container, ignores all values with...
Definition: SequencialMap.hpp:731
key_iterator key_begin() const
Returns an iterator to the first key of the container. If the container is empty,...
Definition: SequencialMap.hpp:1479
bool operator==(const SequencialMap &other) const
Checks if the contents of two containers are not equal.
Definition: SequencialMap.hpp:1576
bool operator!=(const SequencialMap &other) const
Checks if the contents of two containers are equal, that is,.
Definition: SequencialMap.hpp:1592
SerializeManipulator deserialize()
Deserialize the contents from input stream.
Definition: SequencialMap.hpp:1757
iterator begin()
Returns an iterator to the first element of the container. If the container is empty,...
Definition: SequencialMap.hpp:1314
void push_back(const SequencialMap &other)
Appends all elements from given container other to the end of the container, ignores all values with ...
Definition: SequencialMap.hpp:719
iterator end()
Returns an iterator to the element following the last element of the container. This element acts as...
Definition: SequencialMap.hpp:1354
SequencialMap(SequencialMap &&other, const Allocator &alloc=Allocator())
Move constructor. Constructs the container with the contents of other using move semantics....
Definition: SequencialMap.hpp:234
std::pair< iterator, bool > emplace_back(const key_type &key, Args &&... args)
Appends a new element to the end of the container.
Definition: SequencialMap.hpp:769
const_iterator cend() const
Returns an iterator to the element following the last element of the container. This element acts as...
Definition: SequencialMap.hpp:1382
iterator insert(size_t pos, const key_type &key, const T &value)
Inserts element into the container, if the container doesn't already contain an element with an equiv...
Definition: SequencialMap.hpp:918
typename map_type::reference reference
Provide same member type of std::map.
Definition: SequencialMap.hpp:119
Namespace for all classes and functions of convenient containers. See Containers for more instrucion.
Contains std functions overload for classes in Utilities, cannot hide in doxygen, just ignore it.
Stream manipulator for serialization and deserialization.
Definition: SequencialMap.hpp:1765
friend Stream & operator<<(Stream &out, const SerializeManipulator &manip)
Output stream operator for serialization.
Definition: SequencialMap.hpp:1775
friend Stream & operator>>(Stream &in, SerializeManipulator manip)
Input stream operator for deserialization.
Definition: SequencialMap.hpp:1792
Base type for iterators.
Definition: SequencialMap.hpp:1817
typename SequencialMap::vector_type::value_type node_type
Definition: SequencialMap.hpp:1820
typename SequencialMap::value_type value_type
Definition: SequencialMap.hpp:1821
typename SequencialMap::difference_type difference_type
Definition: SequencialMap.hpp:1819
friend iterator_base operator+(difference_type j, iterator_base &it)
Definition: SequencialMap.hpp:1888
bool operator<(const iterator_base< otherConstant > &other) const
Definition: SequencialMap.hpp:1852
iterator_base & operator++()
Definition: SequencialMap.hpp:1867
iterator_base operator+(difference_type j) const
Definition: SequencialMap.hpp:1885
bool operator>(const iterator_base< otherConstant > &other) const
Definition: SequencialMap.hpp:1860
iterator_base(const node_type *node)
Definition: SequencialMap.hpp:1898
pointer operator->() const
Definition: SequencialMap.hpp:1836
bool operator!=(const iterator_base< otherConstant > &other) const
Definition: SequencialMap.hpp:1848
iterator_base(const iterator_base< OtherConstant > &other)
Definition: SequencialMap.hpp:1828
iterator_base & operator=(const iterator_base< OtherConstant > &other)
Definition: SequencialMap.hpp:1840
bool operator==(const iterator_base< otherConstant > &other) const
Definition: SequencialMap.hpp:1844
iterator_base operator--(int)
Definition: SequencialMap.hpp:1876
bool operator>=(const iterator_base< otherConstant > &other) const
Definition: SequencialMap.hpp:1864
iterator_base & operator+=(difference_type j)
Definition: SequencialMap.hpp:1879
std::random_access_iterator_tag iterator_category
Definition: SequencialMap.hpp:1818
reference operator*() const
Definition: SequencialMap.hpp:1833
iterator_base & operator--()
Definition: SequencialMap.hpp:1873
typename std::conditional< constant, const value_type &, value_type & >::type reference
Definition: SequencialMap.hpp:1823
iterator_base & operator-=(difference_type j)
Definition: SequencialMap.hpp:1882
node_type * n
Definition: SequencialMap.hpp:1903
iterator_base operator++(int)
Definition: SequencialMap.hpp:1870
typename std::conditional< constant, const value_type *, value_type * >::type pointer
Definition: SequencialMap.hpp:1822
difference_type operator-(iterator_base j) const
Definition: SequencialMap.hpp:1894
iterator_base operator-(difference_type j) const
Definition: SequencialMap.hpp:1891
bool operator<=(const iterator_base< otherConstant > &other) const
Definition: SequencialMap.hpp:1856
Iterator to traverse keys.
Definition: SequencialMap.hpp:1912
typename SequencialMap::difference_type difference_type
Definition: SequencialMap.hpp:1914
key_iterator & operator+=(difference_type j)
Definition: SequencialMap.hpp:1966
Key value_type
Definition: SequencialMap.hpp:1916
pointer operator->() const
Definition: SequencialMap.hpp:1930
std::random_access_iterator_tag iterator_category
Definition: SequencialMap.hpp:1913
bool operator<=(const key_iterator &other) const
Definition: SequencialMap.hpp:1945
difference_type operator-(key_iterator j) const
Definition: SequencialMap.hpp:1981
key_iterator & operator=(const key_iterator &other)
Definition: SequencialMap.hpp:1933
bool operator<(const key_iterator &other) const
Definition: SequencialMap.hpp:1942
key_iterator operator++(int)
Definition: SequencialMap.hpp:1957
bool operator>(const key_iterator &other) const
Definition: SequencialMap.hpp:1948
bool operator!=(const key_iterator &other) const
Definition: SequencialMap.hpp:1939
key_iterator operator--(int)
Definition: SequencialMap.hpp:1963
const value_type & reference
Definition: SequencialMap.hpp:1917
bool operator>=(const key_iterator &other) const
Definition: SequencialMap.hpp:1951
key_iterator operator+(difference_type j) const
Definition: SequencialMap.hpp:1972
key_iterator & operator-=(difference_type j)
Definition: SequencialMap.hpp:1969
typename SequencialMap::vector_type::value_type node_type
Definition: SequencialMap.hpp:1915
reference operator*() const
Definition: SequencialMap.hpp:1927
const value_type * pointer
Definition: SequencialMap.hpp:1918
key_iterator & operator++()
Definition: SequencialMap.hpp:1954
key_iterator & operator--()
Definition: SequencialMap.hpp:1960
bool operator==(const key_iterator &other) const
Definition: SequencialMap.hpp:1936
friend key_iterator operator+(difference_type j, key_iterator &it)
Definition: SequencialMap.hpp:1975
key_iterator(const key_iterator &other)
Definition: SequencialMap.hpp:1922
key_iterator operator-(difference_type j) const
Definition: SequencialMap.hpp:1978