util/Intrusive*: move constant_time_size to an options struct
This makes it easier to add more options later.
This commit is contained in:
committed by
Max Kellermann
parent
1f495efb46
commit
f01793ad4a
@@ -14,6 +14,10 @@
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
struct IntrusiveForwardListOptions {
|
||||
bool constant_time_size = false;
|
||||
};
|
||||
|
||||
struct IntrusiveForwardListNode {
|
||||
IntrusiveForwardListNode *next;
|
||||
};
|
||||
@@ -93,8 +97,10 @@ struct IntrusiveForwardListMemberHookTraits {
|
||||
*/
|
||||
template<typename T,
|
||||
typename HookTraits=IntrusiveForwardListBaseHookTraits<T>,
|
||||
bool constant_time_size=false>
|
||||
IntrusiveForwardListOptions options=IntrusiveForwardListOptions{}>
|
||||
class IntrusiveForwardList {
|
||||
static constexpr bool constant_time_size = options.constant_time_size;
|
||||
|
||||
IntrusiveForwardListNode head{nullptr};
|
||||
|
||||
[[no_unique_address]]
|
||||
@@ -145,7 +151,7 @@ public:
|
||||
:head(src.head)
|
||||
{
|
||||
// shallow copies mess with the counter
|
||||
static_assert(!constant_time_size);
|
||||
static_assert(!options.constant_time_size);
|
||||
}
|
||||
|
||||
IntrusiveForwardList &operator=(IntrusiveForwardList &&src) noexcept {
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
#include <array>
|
||||
#include <numeric> // for std::accumulate()
|
||||
|
||||
struct IntrusiveHashSetOptions {
|
||||
bool constant_time_size = false;
|
||||
};
|
||||
|
||||
template<IntrusiveHookMode mode=IntrusiveHookMode::NORMAL>
|
||||
struct IntrusiveHashSetHook {
|
||||
using SiblingsHook = IntrusiveListHook<mode>;
|
||||
@@ -106,8 +110,10 @@ struct IntrusiveHashSetOperators {
|
||||
template<typename T, std::size_t table_size,
|
||||
typename Operators,
|
||||
typename HookTraits=IntrusiveHashSetBaseHookTraits<T>,
|
||||
bool constant_time_size=false>
|
||||
IntrusiveHashSetOptions options=IntrusiveHashSetOptions{}>
|
||||
class IntrusiveHashSet {
|
||||
static constexpr bool constant_time_size = options.constant_time_size;
|
||||
|
||||
[[no_unique_address]]
|
||||
OptionalCounter<constant_time_size> counter;
|
||||
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
struct IntrusiveListOptions {
|
||||
bool constant_time_size = false;
|
||||
};
|
||||
|
||||
struct IntrusiveListNode {
|
||||
IntrusiveListNode *next, *prev;
|
||||
|
||||
@@ -27,7 +31,7 @@ template<IntrusiveHookMode _mode=IntrusiveHookMode::NORMAL>
|
||||
class IntrusiveListHook {
|
||||
template<typename T> friend struct IntrusiveListBaseHookTraits;
|
||||
template<auto member> friend struct IntrusiveListMemberHookTraits;
|
||||
template<typename T, typename HookTraits, bool> friend class IntrusiveList;
|
||||
template<typename T, typename HookTraits, IntrusiveListOptions> friend class IntrusiveList;
|
||||
|
||||
protected:
|
||||
IntrusiveListNode siblings;
|
||||
@@ -135,8 +139,10 @@ struct IntrusiveListMemberHookTraits {
|
||||
*/
|
||||
template<typename T,
|
||||
typename HookTraits=IntrusiveListBaseHookTraits<T>,
|
||||
bool constant_time_size=false>
|
||||
IntrusiveListOptions options=IntrusiveListOptions{}>
|
||||
class IntrusiveList {
|
||||
static constexpr bool constant_time_size = options.constant_time_size;
|
||||
|
||||
IntrusiveListNode head{&head, &head};
|
||||
|
||||
[[no_unique_address]]
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
*/
|
||||
template<typename T, typename Compare=typename T::Compare,
|
||||
typename HookTraits=IntrusiveListBaseHookTraits<T>,
|
||||
bool constant_time_size=false>
|
||||
IntrusiveListOptions options=IntrusiveListOptions{}>
|
||||
class IntrusiveSortedList
|
||||
: public IntrusiveList<T, HookTraits, constant_time_size>
|
||||
: public IntrusiveList<T, HookTraits, options>
|
||||
{
|
||||
using Base = IntrusiveList<T, HookTraits, constant_time_size>;
|
||||
using Base = IntrusiveList<T, HookTraits, options>;
|
||||
|
||||
[[no_unique_address]]
|
||||
Compare compare;
|
||||
|
||||
Reference in New Issue
Block a user