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>
111 : boost::intrusive::set_base_hook<
112 boost::intrusive::link_mode<boost::intrusive::normal_link>>,
113 boost::intrusive::list_base_hook<
114 boost::intrusive::link_mode<boost::intrusive::normal_link>>
160 return Compare::operator()(lhs.first, rhs.first);
226 make_list<element, boost::intrusive::constant_time_size<false>>::type;
230 typename boost::intrusive::make_multiset<
232 boost::intrusive::constant_time_size<true>,
233 boost::intrusive::compare<KeyValueCompare>>::type,
234 typename boost::intrusive::make_set<
236 boost::intrusive::constant_time_size<true>,
237 boost::intrusive::compare<KeyValueCompare>>::type>::type;
240 Allocator>::template rebind_alloc<element>;
267 Allocator
const& alloc_)
320 compare() = std::move(other.compare());
321 alloc() = std::move(other.alloc());
367 template <
class... Args>
381 ElementAllocatorTraits::deallocate(a_.
get(), p, 1);
392 std::forward<Args>(args)...);
426 aged_container_iterator<!IsMap, typename cont_type::iterator>;
428 aged_container_iterator<true, typename cont_type::iterator>;
430 aged_container_iterator<!IsMap, typename cont_type::reverse_iterator>;
432 aged_container_iterator<true, typename cont_type::reverse_iterator>;
449 aged_container_iterator<!IsMap, typename list_type::iterator>;
451 aged_container_iterator<true, typename list_type::iterator>;
454 typename list_type::reverse_iterator>;
456 aged_container_iterator<true, typename list_type::reverse_iterator>;
535 "must be standard layout");
536 return list.iterator_to(*
reinterpret_cast<element*
>(
537 reinterpret_cast<uint8_t*
>(&value) -
546 "must be standard layout");
547 return list.iterator_to(*
reinterpret_cast<element const*
>(
548 reinterpret_cast<uint8_t const*
>(&value) -
581 Allocator
const& alloc);
583 template <
class InputIt>
586 template <
class InputIt>
591 Compare
const& comp);
593 template <
class InputIt>
598 Allocator
const& alloc);
600 template <
class InputIt>
606 Allocator
const& alloc);
612 Allocator
const& alloc);
618 Allocator
const& alloc);
627 Compare
const& comp);
632 Allocator
const& alloc);
638 Allocator
const& alloc);
677 bool maybe_multi = IsMulti,
678 bool maybe_map = IsMap,
685 bool maybe_multi = IsMulti,
686 bool maybe_map = IsMap,
689 at(K
const& k)
const;
692 bool maybe_multi = IsMulti,
693 bool maybe_map = IsMap,
699 bool maybe_multi = IsMulti,
700 bool maybe_map = IsMap,
789 reinterpret_cast<uint8_t*
>(&value) -
799 reinterpret_cast<uint8_t const*
>(&value) -
837 template <
bool maybe_multi = IsMulti>
843 template <
bool maybe_multi = IsMulti>
849 template <
bool maybe_multi = IsMulti,
bool maybe_map = IsMap>
852 !maybe_multi && !maybe_map,
856 template <
bool maybe_multi = IsMulti,
bool maybe_map = IsMap>
864 template <
bool maybe_multi = IsMulti>
870 template <
bool maybe_multi = IsMulti>
879 template <
bool maybe_multi = IsMulti>
885 template <
bool maybe_multi = IsMulti>
890 return insert(std::move(value));
894 template <
class P,
bool maybe_map = IsMap>
898 conditional<IsMulti, iterator, std::pair<iterator, bool>>::type>::
902 return emplace(std::forward<P>(value));
906 template <
class P,
bool maybe_map = IsMap>
910 conditional<IsMulti, iterator, std::pair<iterator, bool>>::type>::
917 template <
class InputIt>
921 for (; first != last; ++first)
932 template <
bool maybe_multi = IsMulti,
class... Args>
938 template <
bool maybe_multi = IsMulti,
class... Args>
944 template <
bool maybe_multi = IsMulti,
class... Args>
950 template <
bool maybe_multi = IsMulti,
class... Args>
955 return emplace<maybe_multi>(std::forward<Args>(args)...);
1120 class OtherDuration,
1121 class OtherAllocator>
1130 OtherAllocator>
const& other)
const;
1136 class OtherDuration,
1137 class OtherAllocator>
1146 OtherAllocator>
const& other)
const
1155 class OtherDuration,
1156 class OtherAllocator>
1165 OtherAllocator>
const& other)
const
1169 cbegin(),
cend(), other.cbegin(), other.cend(), comp);
1176 class OtherDuration,
1177 class OtherAllocator>
1186 OtherAllocator>
const& other)
const
1188 return !(other < *
this);
1195 class OtherDuration,
1196 class OtherAllocator>
1205 OtherAllocator>
const& other)
const
1207 return other < *
this;
1214 class OtherDuration,
1215 class OtherAllocator>
1224 OtherAllocator>
const& other)
const
1226 return !(*
this < other);
1242 Allocator>::propagate_on_container_swap::value>
1248 Allocator>::propagate_on_container_swap::value>
1283 : m_config(clock, comp), m_cont(comp)
1297 : m_config(clock, alloc)
1312 Compare
const& comp,
1313 Allocator
const& alloc)
1314 : m_config(clock, comp, alloc), m_cont(comp)
1326template <
class InputIt>
1342template <
class InputIt>
1348 Compare
const& comp)
1349 : m_config(clock, comp), m_cont(comp)
1362template <
class InputIt>
1368 Allocator
const& alloc)
1369 : m_config(clock, alloc)
1382template <
class InputIt>
1388 Compare
const& comp,
1389 Allocator
const& alloc)
1390 : m_config(clock, comp, alloc), m_cont(comp)
1405 : m_config(other.m_config)
1406#if BOOST_VERSION >= 108000
1407 , m_cont(other.m_cont.get_comp())
1409 , m_cont(other.m_cont.comp())
1426 Allocator
const& alloc)
1427 : m_config(other.m_config, alloc)
1428#if BOOST_VERSION >= 108000
1429 , m_cont(other.m_cont.get_comp())
1431 , m_cont(other.m_cont.comp())
1447 : m_config(
std::move(other.m_config)), m_cont(
std::move(other.m_cont))
1463 Allocator
const& alloc)
1464 : m_config(
std::move(other.m_config), alloc)
1465#if BOOST_VERSION >= 108000
1466 , m_cont(
std::move(other.m_cont.get_comp()))
1468 , m_cont(
std::move(other.m_cont.comp()))
1472 insert(other.cbegin(), other.cend());
1505 Compare
const& comp)
1506 : m_config(clock, comp), m_cont(comp)
1523 Allocator
const& alloc)
1524 : m_config(clock, alloc)
1541 Compare
const& comp,
1542 Allocator
const& alloc)
1543 : m_config(clock, comp, alloc), m_cont(comp)
1577 this->m_config = other.m_config;
1578 insert(other.begin(), other.end());
1596 this->m_config = std::move(other.m_config);
1597 insert(other.begin(), other.end());
1629template <
class K,
bool maybe_multi,
bool maybe_map,
class>
1634 auto const iter(m_cont.find(k,
std::cref(m_config.key_compare())));
1635 if (iter == m_cont.end())
1637 return iter->value.second;
1648template <
class K,
bool maybe_multi,
bool maybe_map,
class>
1653 auto const iter(m_cont.find(k,
std::cref(m_config.key_compare())));
1654 if (iter == m_cont.end())
1656 return iter->value.second;
1667template <
bool maybe_multi,
bool maybe_map,
class>
1672 typename cont_type::insert_commit_data d;
1674 m_cont.insert_check(key,
std::cref(m_config.key_compare()), d));
1681 m_cont.insert_commit(*p, d);
1682 chronological.list.push_back(*p);
1683 return p->
value.second;
1685 return result.first->value.second;
1696template <
bool maybe_multi,
bool maybe_map,
class>
1701 typename cont_type::insert_commit_data d;
1703 m_cont.insert_check(key,
std::cref(m_config.key_compare()), d));
1710 m_cont.insert_commit(*p, d);
1711 chronological.list.push_back(*p);
1712 return p->
value.second;
1714 return result.first->value.second;
1731 for (
auto iter(chronological.list.begin());
1732 iter != chronological.list.end();)
1733 delete_element(&*iter++);
1734 chronological.list.clear();
1747template <
bool maybe_multi>
1753 typename cont_type::insert_commit_data d;
1754 auto const result(m_cont.insert_check(
1755 extract(value),
std::cref(m_config.key_compare()), d));
1758 element*
const p(new_element(value));
1759 auto const iter(m_cont.insert_commit(*p, d));
1760 chronological.list.push_back(*p);
1775template <
bool maybe_multi>
1778 insert(value_type
const& value) ->
1782 m_cont.upper_bound(extract(value),
std::cref(m_config.key_compare())));
1783 element*
const p(new_element(value));
1784 chronological.list.push_back(*p);
1785 auto const iter(m_cont.insert_before(before, *p));
1786 return iterator(iter);
1798template <
bool maybe_multi,
bool maybe_map>
1803 enable_if<!maybe_multi && !maybe_map, std::pair<iterator, bool>>::type
1805 typename cont_type::insert_commit_data d;
1806 auto const result(m_cont.insert_check(
1807 extract(value),
std::cref(m_config.key_compare()), d));
1810 element*
const p(new_element(std::move(value)));
1811 auto const iter(m_cont.insert_commit(*p, d));
1812 chronological.list.push_back(*p);
1827template <
bool maybe_multi,
bool maybe_map>
1830 insert(value_type&& value) ->
1834 m_cont.upper_bound(extract(value),
std::cref(m_config.key_compare())));
1835 element*
const p(new_element(std::move(value)));
1836 chronological.list.push_back(*p);
1837 auto const iter(m_cont.insert_before(before, *p));
1838 return iterator(iter);
1852template <
bool maybe_multi>
1858 typename cont_type::insert_commit_data d;
1859 auto const result(m_cont.insert_check(
1860 hint.iterator(), extract(value),
std::cref(m_config.key_compare()), d));
1863 element*
const p(new_element(value));
1864 auto const iter(m_cont.insert_commit(*p, d));
1865 chronological.list.push_back(*p);
1880template <
bool maybe_multi>
1886 typename cont_type::insert_commit_data d;
1887 auto const result(m_cont.insert_check(
1888 hint.iterator(), extract(value),
std::cref(m_config.key_compare()), d));
1891 element*
const p(new_element(std::move(value)));
1892 auto const iter(m_cont.insert_commit(*p, d));
1893 chronological.list.push_back(*p);
1908template <
bool maybe_multi,
class... Args>
1916 element*
const p(new_element(std::forward<Args>(args)...));
1917 typename cont_type::insert_commit_data d;
1918 auto const result(m_cont.insert_check(
1922 auto const iter(m_cont.insert_commit(*p, d));
1923 chronological.list.push_back(*p);
1939template <
bool maybe_multi,
class... Args>
1945 element*
const p(new_element(std::forward<Args>(args)...));
1946 auto const before(m_cont.upper_bound(
1947 extract(p->value),
std::cref(m_config.key_compare())));
1948 chronological.list.push_back(*p);
1949 auto const iter(m_cont.insert_before(before, *p));
1950 return iterator(iter);
1962template <
bool maybe_multi,
class... Args>
1970 element*
const p(new_element(std::forward<Args>(args)...));
1971 typename cont_type::insert_commit_data d;
1972 auto const result(m_cont.insert_check(
1979 auto const iter(m_cont.insert_commit(*p, d));
1980 chronological.list.push_back(*p);
1995template <
bool is_const,
class Iterator,
class>
2000 unlink_and_delete_element(&*((pos++).
iterator()));
2013template <
bool is_const,
class Iterator,
class>
2020 for (; first != last;)
2021 unlink_and_delete_element(&*((first++).
iterator()));
2040 auto iter(m_cont.find(k,
std::cref(m_config.key_compare())));
2041 if (iter == m_cont.end())
2047 bool const done(m_config(*p, extract(iter->value)));
2048 unlink_and_delete_element(p);
2069 std::swap(chronological, other.chronological);
2088 auto const now(clock().now());
2090 auto const range(equal_range(k));
2091 for (
auto iter : range)
2113 class OtherDuration,
2114 class OtherAllocator>
2124 OtherAllocator>
const& other)
const
2134 if (size() != other.size())
2143 value_type const& lhs,
typename Other::value_type
const& rhs) {
2144 return eq(extract(lhs), other.extract(rhs));
2158template <
bool is_const,
class Iterator,
class>
2167 chronological.list.erase(chronological.list.iterator_to(e));
2168 chronological.list.push_back(e);
2179template <
bool maybe_propagate>
2184 std::swap(m_config.key_compare(), other.m_config.key_compare());
2185 std::swap(m_config.alloc(), other.m_config.alloc());
2186 std::swap(m_config.clock, other.m_config.clock);
2197template <
bool maybe_propagate>
2202 std::swap(m_config.key_compare(), other.m_config.key_compare());
2203 std::swap(m_config.clock, other.m_config.clock);
2257 Allocator>& rhs)
noexcept
2286 auto const expired(c.clock().now() - age);
2287 for (
auto iter(c.chronological.cbegin());
2288 iter != c.chronological.cend() && iter.when() <= expired;)
2290 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