20#ifndef BEAST_CONTAINER_DETAIL_AGED_ORDERED_CONTAINER_H_INCLUDED
21#define BEAST_CONTAINER_DETAIL_AGED_ORDERED_CONTAINER_H_INCLUDED
23#include <xrpl/beast/clock/abstract_clock.h>
24#include <xrpl/beast/container/aged_container.h>
25#include <xrpl/beast/container/detail/aged_associative_container.h>
26#include <xrpl/beast/container/detail/aged_container_iterator.h>
27#include <xrpl/beast/container/detail/empty_base_optimization.h>
29#include <boost/intrusive/list.hpp>
30#include <boost/intrusive/set.hpp>
31#include <boost/version.hpp>
110 : boost::intrusive::set_base_hook<
111 boost::intrusive::link_mode<boost::intrusive::normal_link>>,
112 boost::intrusive::list_base_hook<
113 boost::intrusive::link_mode<boost::intrusive::normal_link>>
159 return Compare::operator()(lhs.first, rhs.first);
225 make_list<element, boost::intrusive::constant_time_size<false>>::type;
229 typename boost::intrusive::make_multiset<
231 boost::intrusive::constant_time_size<true>,
232 boost::intrusive::compare<KeyValueCompare>>::type,
233 typename boost::intrusive::make_set<
235 boost::intrusive::constant_time_size<true>,
236 boost::intrusive::compare<KeyValueCompare>>::type>::type;
239 Allocator>::template rebind_alloc<element>;
266 Allocator
const& alloc_)
319 compare() = std::move(other.compare());
320 alloc() = std::move(other.alloc());
366 template <
class... Args>
380 ElementAllocatorTraits::deallocate(a_.
get(), p, 1);
425 aged_container_iterator<!IsMap, typename cont_type::iterator>;
427 aged_container_iterator<true, typename cont_type::iterator>;
429 aged_container_iterator<!IsMap, typename cont_type::reverse_iterator>;
431 aged_container_iterator<true, typename cont_type::reverse_iterator>;
448 aged_container_iterator<!IsMap, typename list_type::iterator>;
450 aged_container_iterator<true, typename list_type::iterator>;
453 typename list_type::reverse_iterator>;
455 aged_container_iterator<true, typename list_type::reverse_iterator>;
534 "must be standard layout");
535 return list.iterator_to(*
reinterpret_cast<element*
>(
536 reinterpret_cast<uint8_t*
>(&value) -
545 "must be standard layout");
546 return list.iterator_to(*
reinterpret_cast<element const*
>(
547 reinterpret_cast<uint8_t const*
>(&value) -
580 Allocator
const& alloc);
582 template <
class InputIt>
585 template <
class InputIt>
590 Compare
const& comp);
592 template <
class InputIt>
597 Allocator
const& alloc);
599 template <
class InputIt>
605 Allocator
const& alloc);
611 Allocator
const& alloc);
617 Allocator
const& alloc);
626 Compare
const& comp);
631 Allocator
const& alloc);
637 Allocator
const& alloc);
676 bool maybe_multi = IsMulti,
677 bool maybe_map = IsMap,
684 bool maybe_multi = IsMulti,
685 bool maybe_map = IsMap,
688 at(K
const& k)
const;
691 bool maybe_multi = IsMulti,
692 bool maybe_map = IsMap,
698 bool maybe_multi = IsMulti,
699 bool maybe_map = IsMap,
788 reinterpret_cast<uint8_t*
>(&value) -
798 reinterpret_cast<uint8_t const*
>(&value) -
836 template <
bool maybe_multi = IsMulti>
842 template <
bool maybe_multi = IsMulti>
848 template <
bool maybe_multi = IsMulti,
bool maybe_map = IsMap>
851 !maybe_multi && !maybe_map,
855 template <
bool maybe_multi = IsMulti,
bool maybe_map = IsMap>
863 template <
bool maybe_multi = IsMulti>
869 template <
bool maybe_multi = IsMulti>
878 template <
bool maybe_multi = IsMulti>
884 template <
bool maybe_multi = IsMulti>
889 return insert(std::move(value));
893 template <
class P,
bool maybe_map = IsMap>
905 template <
class P,
bool maybe_map = IsMap>
916 template <
class InputIt>
920 for (; first != last; ++first)
931 template <
bool maybe_multi = IsMulti,
class... Args>
937 template <
bool maybe_multi = IsMulti,
class... Args>
943 template <
bool maybe_multi = IsMulti,
class... Args>
949 template <
bool maybe_multi = IsMulti,
class... Args>
1119 class OtherDuration,
1120 class OtherAllocator>
1129 OtherAllocator>
const& other)
const;
1135 class OtherDuration,
1136 class OtherAllocator>
1145 OtherAllocator>
const& other)
const
1154 class OtherDuration,
1155 class OtherAllocator>
1164 OtherAllocator>
const& other)
const
1168 cbegin(),
cend(), other.cbegin(), other.cend(), comp);
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 other < *
this;
1213 class OtherDuration,
1214 class OtherAllocator>
1223 OtherAllocator>
const& other)
const
1225 return !(*
this < other);
1241 Allocator>::propagate_on_container_swap::value>
1247 Allocator>::propagate_on_container_swap::value>
1282 : m_config(clock, comp), m_cont(comp)
1296 : m_config(clock, alloc)
1311 Compare
const& comp,
1312 Allocator
const& alloc)
1313 : m_config(clock, comp, alloc), m_cont(comp)
1325template <
class InputIt>
1341template <
class InputIt>
1347 Compare
const& comp)
1348 : m_config(clock, comp), m_cont(comp)
1361template <
class InputIt>
1367 Allocator
const& alloc)
1368 : m_config(clock, alloc)
1381template <
class InputIt>
1387 Compare
const& comp,
1388 Allocator
const& alloc)
1389 : m_config(clock, comp, alloc), m_cont(comp)
1404 : m_config(other.m_config)
1405#if BOOST_VERSION >= 108000
1406 , m_cont(other.m_cont.get_comp())
1408 , m_cont(other.m_cont.comp())
1425 Allocator
const& alloc)
1426 : m_config(other.m_config, alloc)
1427#if BOOST_VERSION >= 108000
1428 , m_cont(other.m_cont.get_comp())
1430 , m_cont(other.m_cont.comp())
1446 : m_config(
std::move(other.m_config)), m_cont(
std::move(other.m_cont))
1462 Allocator
const& alloc)
1463 : m_config(
std::move(other.m_config), alloc)
1464#if BOOST_VERSION >= 108000
1465 , m_cont(
std::move(other.m_cont.get_comp()))
1467 , m_cont(
std::move(other.m_cont.comp()))
1471 insert(other.cbegin(), other.cend());
1504 Compare
const& comp)
1505 : m_config(clock, comp), m_cont(comp)
1522 Allocator
const& alloc)
1523 : m_config(clock, alloc)
1540 Compare
const& comp,
1541 Allocator
const& alloc)
1542 : m_config(clock, comp, alloc), m_cont(comp)
1576 this->m_config = other.m_config;
1577 insert(other.begin(), other.end());
1595 this->m_config = std::move(other.m_config);
1596 insert(other.begin(), other.end());
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 <
class K,
bool maybe_multi,
bool maybe_map,
class>
1652 auto const iter(m_cont.find(k,
std::cref(m_config.key_compare())));
1653 if (iter == m_cont.end())
1655 return iter->value.second;
1666template <
bool maybe_multi,
bool maybe_map,
class>
1671 typename cont_type::insert_commit_data d;
1673 m_cont.insert_check(key,
std::cref(m_config.key_compare()), d));
1680 m_cont.insert_commit(*p, d);
1681 chronological.list.push_back(*p);
1682 return p->
value.second;
1684 return result.first->value.second;
1695template <
bool maybe_multi,
bool maybe_map,
class>
1700 typename cont_type::insert_commit_data d;
1702 m_cont.insert_check(key,
std::cref(m_config.key_compare()), d));
1709 m_cont.insert_commit(*p, d);
1710 chronological.list.push_back(*p);
1711 return p->
value.second;
1713 return result.first->value.second;
1730 for (
auto iter(chronological.list.begin());
1731 iter != chronological.list.end();)
1732 delete_element(&*iter++);
1733 chronological.list.clear();
1746template <
bool maybe_multi>
1752 typename cont_type::insert_commit_data d;
1753 auto const result(m_cont.insert_check(
1754 extract(value),
std::cref(m_config.key_compare()), d));
1757 element*
const p(new_element(value));
1758 auto const iter(m_cont.insert_commit(*p, d));
1759 chronological.list.push_back(*p);
1774template <
bool maybe_multi>
1777 insert(value_type
const& value) ->
1781 m_cont.upper_bound(extract(value),
std::cref(m_config.key_compare())));
1782 element*
const p(new_element(value));
1783 chronological.list.push_back(*p);
1784 auto const iter(m_cont.insert_before(before, *p));
1785 return iterator(iter);
1797template <
bool maybe_multi,
bool maybe_map>
1804 typename cont_type::insert_commit_data d;
1805 auto const result(m_cont.insert_check(
1806 extract(value),
std::cref(m_config.key_compare()), d));
1809 element*
const p(new_element(std::move(value)));
1810 auto const iter(m_cont.insert_commit(*p, d));
1811 chronological.list.push_back(*p);
1826template <
bool maybe_multi,
bool maybe_map>
1829 insert(value_type&& value) ->
1833 m_cont.upper_bound(extract(value),
std::cref(m_config.key_compare())));
1834 element*
const p(new_element(std::move(value)));
1835 chronological.list.push_back(*p);
1836 auto const iter(m_cont.insert_before(before, *p));
1837 return iterator(iter);
1851template <
bool maybe_multi>
1857 typename cont_type::insert_commit_data d;
1858 auto const result(m_cont.insert_check(
1859 hint.iterator(), extract(value),
std::cref(m_config.key_compare()), d));
1862 element*
const p(new_element(value));
1863 auto const iter(m_cont.insert_commit(*p, d));
1864 chronological.list.push_back(*p);
1879template <
bool maybe_multi>
1885 typename cont_type::insert_commit_data d;
1886 auto const result(m_cont.insert_check(
1887 hint.iterator(), extract(value),
std::cref(m_config.key_compare()), d));
1890 element*
const p(new_element(std::move(value)));
1891 auto const iter(m_cont.insert_commit(*p, d));
1892 chronological.list.push_back(*p);
1907template <
bool maybe_multi,
class... Args>
1916 typename cont_type::insert_commit_data d;
1917 auto const result(m_cont.insert_check(
1921 auto const iter(m_cont.insert_commit(*p, d));
1922 chronological.list.push_back(*p);
1938template <
bool maybe_multi,
class... Args>
1945 auto const before(m_cont.upper_bound(
1946 extract(p->value),
std::cref(m_config.key_compare())));
1947 chronological.list.push_back(*p);
1948 auto const iter(m_cont.insert_before(before, *p));
1949 return iterator(iter);
1961template <
bool maybe_multi,
class... Args>
1970 typename cont_type::insert_commit_data d;
1971 auto const result(m_cont.insert_check(
1978 auto const iter(m_cont.insert_commit(*p, d));
1979 chronological.list.push_back(*p);
1994template <
bool is_const,
class Iterator,
class>
1999 unlink_and_delete_element(&*((pos++).
iterator()));
2012template <
bool is_const,
class Iterator,
class>
2019 for (; first != last;)
2020 unlink_and_delete_element(&*((first++).
iterator()));
2039 auto iter(m_cont.find(k,
std::cref(m_config.key_compare())));
2040 if (iter == m_cont.end())
2046 bool const done(m_config(*p, extract(iter->value)));
2047 unlink_and_delete_element(p);
2068 std::swap(chronological, other.chronological);
2087 auto const now(clock().now());
2089 auto const range(equal_range(k));
2090 for (
auto iter : range)
2112 class OtherDuration,
2113 class OtherAllocator>
2123 OtherAllocator>
const& other)
const
2133 if (size() != other.size())
2142 value_type const& lhs,
typename Other::value_type
const& rhs) {
2143 return eq(extract(lhs), other.extract(rhs));
2157template <
bool is_const,
class Iterator,
class>
2166 chronological.list.erase(chronological.list.iterator_to(e));
2167 chronological.list.push_back(e);
2178template <
bool maybe_propagate>
2183 std::swap(m_config.key_compare(), other.m_config.key_compare());
2184 std::swap(m_config.alloc(), other.m_config.alloc());
2185 std::swap(m_config.clock, other.m_config.clock);
2196template <
bool maybe_propagate>
2201 std::swap(m_config.key_compare(), other.m_config.key_compare());
2202 std::swap(m_config.clock, other.m_config.clock);
2256 Allocator>& rhs)
noexcept
2285 auto const expired(c.clock().now() - age);
2286 for (
auto iter(c.chronological.cbegin());
2287 iter != c.chronological.cend() && iter.when() <= expired;)
2289 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