13#ifndef CXXUTILS_CONCURRENTRANGEMAP_H
14#define CXXUTILS_CONCURRENTRANGEMAP_H
42template <
class T,
class CONTEXT>
100template <
class COMPARE,
class RANGE,
class KEY,
class CONTEXT>
108 { c(k, r2) } -> std::same_as<bool>;
109 { c(r1, r2) } -> std::same_as<bool>;
110 { c.inRange (k, r2) } -> std::same_as<bool>;
111 { c.overlap (ctx, r1, r_nc) } -> std::same_as<int>;
112 { c.extendRange (r_nc, r2) } -> std::same_as<int>;
208template <
class RANGE,
class KEY,
class T,
class COMPARE,
209 template <
class>
class UPDATER>
248 delete reinterpret_cast<const U*
>(p);
257 void operator() (
const T* p)
const
349 std::shared_ptr<IPayloadDeleter> payloadDeleter,
351 const COMPARE& compare = COMPARE());
424 bool tryExtend =
false,
494 size_t trim (
const std::vector<key_query_type>& keys,
bool trimall =
false);
587 const std::vector<key_query_type>& keys)
const;
615 const RANGE& extendedRange,
Concept check for Updater class used by concurrent classes.
static const Context_t & defaultContext()
Return the current event context.
EventContext Context_t
Execution context type.
Impl(size_t capacity=10)
Constructor.
~Impl()=default
Destructor.
value_type * data()
Return a pointer to the start of the data vector.
std::vector< value_type > m_data
Vector holding the map data.
size_t capacity() const
Return the size of the current data vector.
int extendLastRange(const RANGE &newRange, const typename Updater_t::Context_t &ctx=Updater_t::defaultContext())
Extend the range of the last entry of the map.
std::pair< RangeKey, const void * > value_type
void clear()
Remove all entries in the container.
std::unique_ptr< void, DeletePayload > payload_unique_ptr
Athena::RCUUpdater< Impl > Updater_t
std::ranges::subrange< const_iterator > const_iterator_range
void quiescent(const typename Updater_t::Context_t &ctx=Updater_t::defaultContext())
Called when this thread is no longer referencing anything from this container.
size_t maxSize() const
Return the maximum size of the map.
EmplaceResult
Results returned from emplace().
@ DUPLICATE
New object duplicates an existing range, and was not added.
@ OVERLAP
New object was added, but overlaps with an existing range.
std::shared_ptr< IPayloadDeleter > m_payloadDeleter
const value_type & const_reference
size_t trim(const std::vector< key_query_type > &keys, bool trimall=false)
Remove unused entries from the front of the list.
void updatePointers(value_type *new_begin, value_type *new_end)
Consistently update both the begin and last pointers.
std::atomic< value_type * > m_last
const_iterator_range range() const
bool empty() const
Test if the map is empty.
std::lock_guard< mutex_t > lock_t
const_iterator getBegin(const_iterator &last) const
Return the begin/last pointers.
IPayloadDeleter & deleter()
Return a reference to the payload deleter object.
int extendImpl(lock_t &lock, const RANGE &extendedRange, const typename Updater_t::Context_t &ctx)
Extend the range of the last entry of the map.
const value_type * const_iterator
EmplaceResult emplace(const RANGE &range, payload_unique_ptr ptr, bool tryExtend=false, const typename Updater_t::Context_t &ctx=Updater_t::defaultContext())
Add a new element to the map.
const_iterator find(const key_query_type &key) const
Search for the first item less than or equal to KEY.
void delete_function(const T *)
Function to delete a T*.
~ConcurrentRangeMap()
Destructor.
void erase(const key_query_type &key, const typename Updater_t::Context_t &ctx=Updater_t::defaultContext())
Erase the first item less than or equal to KEY.
void updateRanges(std::function< void(RANGE &)> rangeUpdater, const typename Updater_t::Context_t &ctx=Updater_t::defaultContext())
Update all range objects.
const IPayloadDeleter & deleter() const
Return a reference to the payload deleter object.
void installImpl(std::unique_ptr< Impl > new_impl, value_type *new_begin, value_type *new_end, const typename Updater_t::Context_t &ctx)
Install a new implementation instance and make it visible.
CxxUtils::IRangeMapPayloadDeleter< void, typename Updater_t::Context_t > IPayloadDeleter
std::atomic< value_type * > m_begin
bool anyInRange(const key_type &r, const std::vector< key_query_type > &keys) const
Test to see if any keys within keys match r.
ConcurrentRangeMap(Updater_t &&updater, std::shared_ptr< IPayloadDeleter > payloadDeleter, size_t capacity=16, const COMPARE &compare=COMPARE())
Constructor.
const value_type * const_pointer
size_t size() const
Return the current number of elements in the map.
size_t nInserts() const
Return the number times an item was inserted into the map.
Helper to delete payload objects for ConcurrentRangeMap.
IRangeMapPayloadDeleter(delete_function *delfcn)
Constructor.
virtual void discard(const T *p)=0
Queue an object for deletion.
virtual void quiescent(const CONTEXT &ctx)=0
Mark a slot as quiescent.
delete_function * delfcn() const
delete_function * m_delfcn
void delete_function(const T *)
Type of a function to delete a payload object immediately.
virtual ~IRangeMapPayloadDeleter()=default
Virtual destructor.
Concept for comparison template argument.
Concept check for Updater class used by concurrent classes.
Emit stall instruction for use in a spin loop.
delete_function * m_delete
The deletion function.
DeletePayload(const std::default_delete< U > &)
static void delfcn(const T *p)
Allow initializing a payload_unique_ptr from a std::unique_ptr.
DeletePayload(delete_function *delfcn)
Initialize with an explicit deletion function.