1#ifndef BEAST_CONTAINER_DETAIL_AGED_ORDERED_CONTAINER_H_INCLUDED
2#define BEAST_CONTAINER_DETAIL_AGED_ORDERED_CONTAINER_H_INCLUDED
4#include <xrpl/beast/clock/abstract_clock.h>
5#include <xrpl/beast/container/aged_container.h>
6#include <xrpl/beast/container/detail/aged_associative_container.h>
7#include <xrpl/beast/container/detail/aged_container_iterator.h>
8#include <xrpl/beast/container/detail/empty_base_optimization.h>
10#include <boost/intrusive/list.hpp>
11#include <boost/intrusive/set.hpp>
12#include <boost/version.hpp>
91 : boost::intrusive::set_base_hook<
92 boost::intrusive::link_mode<boost::intrusive::normal_link>>,
93 boost::intrusive::list_base_hook<
94 boost::intrusive::link_mode<boost::intrusive::normal_link>>
140 return Compare::operator()(lhs.first, rhs.first);
206 make_list<element, boost::intrusive::constant_time_size<false>>::type;
210 typename boost::intrusive::make_multiset<
212 boost::intrusive::constant_time_size<true>,
213 boost::intrusive::compare<KeyValueCompare>>::type,
214 typename boost::intrusive::make_set<
216 boost::intrusive::constant_time_size<true>,
217 boost::intrusive::compare<KeyValueCompare>>::type>::type;
220 Allocator>::template rebind_alloc<element>;
247 Allocator
const& alloc_)
300 compare() = std::move(other.compare());
301 alloc() = std::move(other.alloc());
347 template <
class... Args>
361 ElementAllocatorTraits::deallocate(a_.
get(), p, 1);
406 aged_container_iterator<!IsMap, typename cont_type::iterator>;
408 aged_container_iterator<true, typename cont_type::iterator>;
410 aged_container_iterator<!IsMap, typename cont_type::reverse_iterator>;
412 aged_container_iterator<true, typename cont_type::reverse_iterator>;
429 aged_container_iterator<!IsMap, typename list_type::iterator>;
431 aged_container_iterator<true, typename list_type::iterator>;
434 typename list_type::reverse_iterator>;
436 aged_container_iterator<true, typename list_type::reverse_iterator>;
515 "must be standard layout");
516 return list.iterator_to(*
reinterpret_cast<element*
>(
517 reinterpret_cast<uint8_t*
>(&value) -
526 "must be standard layout");
527 return list.iterator_to(*
reinterpret_cast<element const*
>(
528 reinterpret_cast<uint8_t const*
>(&value) -
561 Allocator
const& alloc);
563 template <
class InputIt>
566 template <
class InputIt>
571 Compare
const& comp);
573 template <
class InputIt>
578 Allocator
const& alloc);
580 template <
class InputIt>
586 Allocator
const& alloc);
592 Allocator
const& alloc);
598 Allocator
const& alloc);
607 Compare
const& comp);
612 Allocator
const& alloc);
618 Allocator
const& alloc);
657 bool maybe_multi = IsMulti,
658 bool maybe_map = IsMap,
665 bool maybe_multi = IsMulti,
666 bool maybe_map = IsMap,
669 at(K
const& k)
const;
672 bool maybe_multi = IsMulti,
673 bool maybe_map = IsMap,
679 bool maybe_multi = IsMulti,
680 bool maybe_map = IsMap,
769 reinterpret_cast<uint8_t*
>(&value) -
779 reinterpret_cast<uint8_t const*
>(&value) -
817 template <
bool maybe_multi = IsMulti>
823 template <
bool maybe_multi = IsMulti>
829 template <
bool maybe_multi = IsMulti,
bool maybe_map = IsMap>
832 !maybe_multi && !maybe_map,
836 template <
bool maybe_multi = IsMulti,
bool maybe_map = IsMap>
844 template <
bool maybe_multi = IsMulti>
850 template <
bool maybe_multi = IsMulti>
859 template <
bool maybe_multi = IsMulti>
865 template <
bool maybe_multi = IsMulti>
870 return insert(std::move(value));
874 template <
class P,
bool maybe_map = IsMap>
886 template <
class P,
bool maybe_map = IsMap>
897 template <
class InputIt>
901 for (; first != last; ++first)
912 template <
bool maybe_multi = IsMulti,
class... Args>
918 template <
bool maybe_multi = IsMulti,
class... Args>
924 template <
bool maybe_multi = IsMulti,
class... Args>
930 template <
bool maybe_multi = IsMulti,
class... Args>
1100 class OtherDuration,
1101 class OtherAllocator>
1110 OtherAllocator>
const& other)
const;
1116 class OtherDuration,
1117 class OtherAllocator>
1126 OtherAllocator>
const& other)
const
1135 class OtherDuration,
1136 class OtherAllocator>
1145 OtherAllocator>
const& other)
const
1149 cbegin(),
cend(), other.cbegin(), other.cend(), comp);
1156 class OtherDuration,
1157 class OtherAllocator>
1166 OtherAllocator>
const& other)
const
1168 return !(other < *
this);
1175 class OtherDuration,
1176 class OtherAllocator>
1185 OtherAllocator>
const& other)
const
1187 return other < *
this;
1194 class OtherDuration,
1195 class OtherAllocator>
1204 OtherAllocator>
const& other)
const
1206 return !(*
this < other);
1222 Allocator>::propagate_on_container_swap::value>
1228 Allocator>::propagate_on_container_swap::value>
1263 : m_config(clock, comp), m_cont(comp)
1277 : m_config(clock, alloc)
1292 Compare
const& comp,
1293 Allocator
const& alloc)
1294 : m_config(clock, comp, alloc), m_cont(comp)
1306template <
class InputIt>
1322template <
class InputIt>
1328 Compare
const& comp)
1329 : m_config(clock, comp), m_cont(comp)
1342template <
class InputIt>
1348 Allocator
const& alloc)
1349 : m_config(clock, alloc)
1362template <
class InputIt>
1368 Compare
const& comp,
1369 Allocator
const& alloc)
1370 : m_config(clock, comp, alloc), m_cont(comp)
1385 : m_config(other.m_config)
1386#if BOOST_VERSION >= 108000
1387 , m_cont(other.m_cont.get_comp())
1389 , m_cont(other.m_cont.comp())
1406 Allocator
const& alloc)
1407 : m_config(other.m_config, alloc)
1408#if BOOST_VERSION >= 108000
1409 , m_cont(other.m_cont.get_comp())
1411 , m_cont(other.m_cont.comp())
1427 : m_config(
std::move(other.m_config)), m_cont(
std::move(other.m_cont))
1443 Allocator
const& alloc)
1444 : m_config(
std::move(other.m_config), alloc)
1445#if BOOST_VERSION >= 108000
1446 , m_cont(
std::move(other.m_cont.get_comp()))
1448 , m_cont(
std::move(other.m_cont.comp()))
1452 insert(other.cbegin(), other.cend());
1485 Compare
const& comp)
1486 : m_config(clock, comp), m_cont(comp)
1503 Allocator
const& alloc)
1504 : m_config(clock, alloc)
1521 Compare
const& comp,
1522 Allocator
const& alloc)
1523 : m_config(clock, comp, alloc), m_cont(comp)
1557 this->m_config = other.m_config;
1558 insert(other.begin(), other.end());
1576 this->m_config = std::move(other.m_config);
1577 insert(other.begin(), other.end());
1609template <
class K,
bool maybe_multi,
bool maybe_map,
class>
1614 auto const iter(m_cont.find(k,
std::cref(m_config.key_compare())));
1615 if (iter == m_cont.end())
1617 return iter->value.second;
1628template <
class K,
bool maybe_multi,
bool maybe_map,
class>
1633 auto const iter(m_cont.find(k,
std::cref(m_config.key_compare())));
1634 if (iter == m_cont.end())
1636 return iter->value.second;
1647template <
bool maybe_multi,
bool maybe_map,
class>
1652 typename cont_type::insert_commit_data d;
1654 m_cont.insert_check(key,
std::cref(m_config.key_compare()), d));
1661 m_cont.insert_commit(*p, d);
1662 chronological.list.push_back(*p);
1663 return p->
value.second;
1665 return result.first->value.second;
1676template <
bool maybe_multi,
bool maybe_map,
class>
1681 typename cont_type::insert_commit_data d;
1683 m_cont.insert_check(key,
std::cref(m_config.key_compare()), d));
1690 m_cont.insert_commit(*p, d);
1691 chronological.list.push_back(*p);
1692 return p->
value.second;
1694 return result.first->value.second;
1711 for (
auto iter(chronological.list.begin());
1712 iter != chronological.list.end();)
1713 delete_element(&*iter++);
1714 chronological.list.clear();
1727template <
bool maybe_multi>
1733 typename cont_type::insert_commit_data d;
1734 auto const result(m_cont.insert_check(
1735 extract(value),
std::cref(m_config.key_compare()), d));
1738 element*
const p(new_element(value));
1739 auto const iter(m_cont.insert_commit(*p, d));
1740 chronological.list.push_back(*p);
1755template <
bool maybe_multi>
1758 insert(value_type
const& value) ->
1762 m_cont.upper_bound(extract(value),
std::cref(m_config.key_compare())));
1763 element*
const p(new_element(value));
1764 chronological.list.push_back(*p);
1765 auto const iter(m_cont.insert_before(before, *p));
1766 return iterator(iter);
1778template <
bool maybe_multi,
bool maybe_map>
1785 typename cont_type::insert_commit_data d;
1786 auto const result(m_cont.insert_check(
1787 extract(value),
std::cref(m_config.key_compare()), d));
1790 element*
const p(new_element(std::move(value)));
1791 auto const iter(m_cont.insert_commit(*p, d));
1792 chronological.list.push_back(*p);
1807template <
bool maybe_multi,
bool maybe_map>
1810 insert(value_type&& value) ->
1814 m_cont.upper_bound(extract(value),
std::cref(m_config.key_compare())));
1815 element*
const p(new_element(std::move(value)));
1816 chronological.list.push_back(*p);
1817 auto const iter(m_cont.insert_before(before, *p));
1818 return iterator(iter);
1832template <
bool maybe_multi>
1838 typename cont_type::insert_commit_data d;
1839 auto const result(m_cont.insert_check(
1840 hint.iterator(), extract(value),
std::cref(m_config.key_compare()), d));
1843 element*
const p(new_element(value));
1844 auto const iter(m_cont.insert_commit(*p, d));
1845 chronological.list.push_back(*p);
1860template <
bool maybe_multi>
1866 typename cont_type::insert_commit_data d;
1867 auto const result(m_cont.insert_check(
1868 hint.iterator(), extract(value),
std::cref(m_config.key_compare()), d));
1871 element*
const p(new_element(std::move(value)));
1872 auto const iter(m_cont.insert_commit(*p, d));
1873 chronological.list.push_back(*p);
1888template <
bool maybe_multi,
class... Args>
1897 typename cont_type::insert_commit_data d;
1898 auto const result(m_cont.insert_check(
1902 auto const iter(m_cont.insert_commit(*p, d));
1903 chronological.list.push_back(*p);
1919template <
bool maybe_multi,
class... Args>
1926 auto const before(m_cont.upper_bound(
1927 extract(p->value),
std::cref(m_config.key_compare())));
1928 chronological.list.push_back(*p);
1929 auto const iter(m_cont.insert_before(before, *p));
1930 return iterator(iter);
1942template <
bool maybe_multi,
class... Args>
1951 typename cont_type::insert_commit_data d;
1952 auto const result(m_cont.insert_check(
1959 auto const iter(m_cont.insert_commit(*p, d));
1960 chronological.list.push_back(*p);
1975template <
bool is_const,
class Iterator,
class>
1980 unlink_and_delete_element(&*((pos++).
iterator()));
1993template <
bool is_const,
class Iterator,
class>
2000 for (; first != last;)
2001 unlink_and_delete_element(&*((first++).
iterator()));
2020 auto iter(m_cont.find(k,
std::cref(m_config.key_compare())));
2021 if (iter == m_cont.end())
2027 bool const done(m_config(*p, extract(iter->value)));
2028 unlink_and_delete_element(p);
2049 std::swap(chronological, other.chronological);
2068 auto const now(clock().now());
2070 auto const range(equal_range(k));
2071 for (
auto iter : range)
2093 class OtherDuration,
2094 class OtherAllocator>
2104 OtherAllocator>
const& other)
const
2114 if (size() != other.size())
2123 value_type const& lhs,
typename Other::value_type
const& rhs) {
2124 return eq(extract(lhs), other.extract(rhs));
2138template <
bool is_const,
class Iterator,
class>
2147 chronological.list.erase(chronological.list.iterator_to(e));
2148 chronological.list.push_back(e);
2159template <
bool maybe_propagate>
2164 std::swap(m_config.key_compare(), other.m_config.key_compare());
2165 std::swap(m_config.alloc(), other.m_config.alloc());
2166 std::swap(m_config.clock, other.m_config.clock);
2177template <
bool maybe_propagate>
2182 std::swap(m_config.key_compare(), other.m_config.key_compare());
2183 std::swap(m_config.clock, other.m_config.clock);
2237 Allocator>& rhs)
noexcept
2266 auto const expired(c.clock().now() - age);
2267 for (
auto iter(c.chronological.cbegin());
2268 iter != c.chronological.cend() && iter.when() <= expired;)
2270 iter = c.erase(iter);
Abstract interface to a clock.
typename Clock::time_point time_point
typename Clock::duration duration
Iterator const & iterator() const
bool operator()(element const &e, Key const &k) const
Compare const & compare() const
bool operator()(element const &x, element const &y) const
KeyValueCompare(Compare const &compare)
KeyValueCompare()=default
bool operator()(Key const &k, element const &e) const
const_iterator iterator_to(value_type const &value) const
const_reverse_iterator rbegin() const
const_reverse_iterator crbegin() const
const_iterator cbegin() const
const_reverse_iterator crend() const
beast::detail::aged_container_iterator<!IsMap, typename list_type::iterator > iterator
chronological_t(chronological_t const &)=delete
reverse_iterator rbegin()
beast::detail::aged_container_iterator< !IsMap, typename list_type::reverse_iterator > reverse_iterator
const_iterator end() const
beast::detail::aged_container_iterator< true, typename list_type::reverse_iterator > const_reverse_iterator
const_reverse_iterator rend() const
const_iterator cend() const
beast::detail::aged_container_iterator< true, typename list_type::iterator > const_iterator
iterator iterator_to(value_type &value)
chronological_t(chronological_t &&)=delete
const_iterator begin() const
KeyValueCompare & key_compare()
config_t(config_t const &other, Allocator const &alloc)
ElementAllocator & alloc()
config_t(clock_type &clock_, Allocator const &alloc_)
KeyValueCompare const & key_compare() const
Compare const & compare() const
config_t & operator=(config_t &&other)
config_t(clock_type &clock_)
ElementAllocator const & alloc() const
config_t(config_t const &other)
std::reference_wrapper< clock_type > clock
config_t(clock_type &clock_, Compare const &comp, Allocator const &alloc_)
config_t & operator=(config_t const &other)
config_t(config_t &&other, Allocator const &alloc)
config_t(clock_type &clock_, Compare const &comp)
config_t(config_t &&other)
pair_value_compare(pair_value_compare const &other)
friend aged_ordered_container
value_type second_argument
bool operator()(value_type const &lhs, value_type const &rhs) const
pair_value_compare(Compare const &compare)
value_type first_argument
Associative container where each element is also indexed by time.
std::conditional< IsMap, T, void * >::type & operator[](Key const &key)
aged_ordered_container(aged_ordered_container &&other, Allocator const &alloc)
size_type touch(K const &k)
std::enable_if< maybe_multi, iterator >::type emplace_hint(const_iterator, Args &&... args)
typename std::allocator_traits< Allocator >::const_pointer const_pointer
aged_ordered_container(aged_ordered_container &&other)
value_compare value_comp() const
clock_type const & clock() const
auto insert(const_iterator hint, value_type const &value) -> typename std::enable_if<!maybe_multi, iterator >::type
aged_ordered_container(clock_type &clock)
std::conditional< IsMap, T, void * >::type & at(K const &k)
typename std::allocator_traits< Allocator >::pointer pointer
aged_ordered_container & operator=(std::initializer_list< value_type > init)
auto insert(value_type const &value) -> typename std::enable_if< maybe_multi, iterator >::type
const_iterator find(K const &k) const
reverse_iterator rbegin()
typename std::conditional< IsMap, pair_value_compare, Compare >::type value_compare
const_iterator cend() const
void swap(aged_ordered_container &other) noexcept
beast::detail::aged_container_iterator< false, Iterator > erase(beast::detail::aged_container_iterator< is_const, Iterator > pos)
const_reverse_iterator rbegin() const
beast::detail::aged_container_iterator< true, typename cont_type::reverse_iterator > const_reverse_iterator
aged_ordered_container(clock_type &clock, Compare const &comp)
~aged_ordered_container()
aged_ordered_container(aged_ordered_container const &other, Allocator const &alloc)
aged_ordered_container(std::initializer_list< value_type > init, clock_type &clock, Compare const &comp, Allocator const &alloc)
aged_ordered_container(std::initializer_list< value_type > init, clock_type &clock, Allocator const &alloc)
bool operator<=(aged_ordered_container< OtherIsMulti, OtherIsMap, Key, OtherT, OtherDuration, Compare, OtherAllocator > const &other) const
aged_ordered_container(std::initializer_list< value_type > init, clock_type &clock)
aged_ordered_container & operator=(aged_ordered_container const &other)
aged_ordered_container(InputIt first, InputIt last, clock_type &clock, Allocator const &alloc)
bool operator>(aged_ordered_container< OtherIsMulti, OtherIsMap, Key, OtherT, OtherDuration, Compare, OtherAllocator > const &other) const
auto insert(value_type &&value) -> typename std::enable_if< !maybe_multi &&!maybe_map, std::pair< iterator, bool > >::type
void insert(InputIt first, InputIt last)
const_reverse_iterator crend() const
std::pair< iterator, iterator > equal_range(K const &k)
bool operator==(aged_ordered_container< OtherIsMulti, OtherIsMap, Key, OtherT, OtherDuration, Compare, OtherAllocator > const &other) const
aged_ordered_container(clock_type &clock, Compare const &comp, Allocator const &alloc)
std::enable_if< maybe_map &&std::is_constructible< value_type, P && >::value, typenamestd::conditional< IsMulti, iterator, std::pair< iterator, bool > >::type >::type insert(P &&value)
void insert(std::initializer_list< value_type > init)
aged_ordered_container(aged_ordered_container const &other)
value_type const & const_reference
void unlink_and_delete_element(element const *p)
aged_ordered_container(std::initializer_list< value_type > init, clock_type &clock, Compare const &comp)
const_iterator end() const
std::enable_if< maybe_map &&std::is_constructible< value_type, P && >::value, typenamestd::conditional< IsMulti, iterator, std::pair< iterator, bool > >::type >::type insert(const_iterator hint, P &&value)
const_iterator cbegin() const
const_iterator lower_bound(K const &k) const
typename std::conditional< IsMulti, typename boost::intrusive::make_multiset< element, boost::intrusive::constant_time_size< true >, boost::intrusive::compare< KeyValueCompare > >::type, typename boost::intrusive::make_set< element, boost::intrusive::constant_time_size< true >, boost::intrusive::compare< KeyValueCompare > >::type >::type cont_type
const_iterator upper_bound(K const &k) const
bool operator!=(aged_ordered_container< OtherIsMulti, OtherIsMap, Key, OtherT, OtherDuration, Compare, OtherAllocator > const &other) const
const_iterator iterator_to(value_type const &value) const
std::enable_if< maybe_propagate >::type swap_data(aged_ordered_container &other) noexcept
allocator_type get_allocator() const
typename std::allocator_traits< Allocator >::template rebind_alloc< element > ElementAllocator
aged_ordered_container()=delete
auto insert(value_type &&value) -> typename std::enable_if< maybe_multi &&!maybe_map, iterator >::type
auto insert(value_type const &value) -> typename std::enable_if<!maybe_multi, std::pair< iterator, bool > >::type
beast::detail::aged_container_iterator< false, Iterator > erase(beast::detail::aged_container_iterator< is_const, Iterator > first, beast::detail::aged_container_iterator< is_const, Iterator > last)
std::enable_if< maybe_multi, iterator >::type insert(const_iterator, value_type const &value)
auto emplace(Args &&... args) -> typename std::enable_if< maybe_multi, iterator >::type
bool operator<(aged_ordered_container< OtherIsMulti, OtherIsMap, Key, OtherT, OtherDuration, Compare, OtherAllocator > const &other) const
key_compare key_comp() const
iterator lower_bound(K const &k)
typename clock_type::duration duration
auto insert(const_iterator hint, value_type &&value) -> typename std::enable_if<!maybe_multi, iterator >::type
element * new_element(Args &&... args)
void touch(beast::detail::aged_container_iterator< is_const, Iterator > pos, typename clock_type::time_point const &now)
beast::detail::aged_container_iterator<!IsMap, typename cont_type::iterator > iterator
auto erase(K const &k) -> size_type
beast::detail::aged_container_iterator< true, typename cont_type::iterator > const_iterator
void touch(beast::detail::aged_container_iterator< is_const, Iterator > pos)
class beast::detail::aged_ordered_container::chronological_t chronological
size_type size() const noexcept
size_type count(K const &k) const
aged_ordered_container(clock_type &clock, Allocator const &alloc)
void delete_element(element const *p)
aged_ordered_container(InputIt first, InputIt last, clock_type &clock, Compare const &comp)
size_type max_size() const noexcept
const_iterator begin() const
aged_ordered_container(InputIt first, InputIt last, clock_type &clock, Compare const &comp, Allocator const &alloc)
aged_ordered_container & operator=(aged_ordered_container &&other)
std::enable_if< maybe_multi, iterator >::type insert(const_iterator, value_type &&value)
bool operator>=(aged_ordered_container< OtherIsMulti, OtherIsMap, Key, OtherT, OtherDuration, Compare, OtherAllocator > const &other) const
abstract_clock< Clock > clock_type
typename boost::intrusive::make_list< element, boost::intrusive::constant_time_size< false > >::type list_type
iterator upper_bound(K const &k)
const_reverse_iterator crbegin() const
auto emplace_hint(const_iterator hint, Args &&... args) -> typename std::enable_if<!maybe_multi, std::pair< iterator, bool > >::type
std::conditional< IsMap, T, void * >::type const & at(K const &k) const
aged_ordered_container(InputIt first, InputIt last, clock_type &clock)
iterator find(K const &k)
typename std::conditional< IsMap, std::pair< Key const, T >, Key >::type value_type
auto emplace(Args &&... args) -> typename std::enable_if<!maybe_multi, std::pair< iterator, bool > >::type
std::conditional< IsMap, T, void * >::type & operator[](Key &&key)
beast::detail::aged_container_iterator<!IsMap, typename cont_type::reverse_iterator > reverse_iterator
const_reverse_iterator rend() const
static Key const & extract(value_type const &value)
bool empty() const noexcept
std::pair< const_iterator, const_iterator > equal_range(K const &k) const
iterator iterator_to(value_type &value)
typename clock_type::time_point time_point
ElementAllocator & member() noexcept
T forward_as_tuple(T... args)
T lexicographical_compare(T... args)
int compare(SemanticVersion const &lhs, SemanticVersion const &rhs)
Compare two SemanticVersions against each other.
std::enable_if< is_aged_container< AgedContainer >::value, std::size_t >::type expire(AgedContainer &c, std::chrono::duration< Rep, Period > const &age)
Expire aged container items past the specified age.
void swap(beast::detail::aged_ordered_container< IsMulti, IsMap, Key, T, Clock, Compare, Allocator > &lhs, beast::detail::aged_ordered_container< IsMulti, IsMap, Key, T, Clock, Compare, Allocator > &rhs) noexcept
typename aged_ordered_container::time_point time_point
typename aged_ordered_container::value_type value_type
element(time_point const &when_, value_type const &value_)
element(time_point const &when_, value_type &&value_)
element(time_point const &when_, Args &&... args)
is_boost_reverse_iterator()=default
is_boost_reverse_iterator()=default
is_aged_container()=default