25#ifndef __BITPIT_PIERCED_KERNEL_HPP__
26#define __BITPIT_PIERCED_KERNEL_HPP__
31#include <unordered_map>
35#include "bitpit_common.hpp"
37#include "piercedSync.hpp"
38#include "piercedKernelIterator.hpp"
39#include "piercedKernelRange.hpp"
43template<
typename id_t>
44class PiercedStorageSyncSlave;
105template<
typename id_t =
long>
108static_assert(std::is_integral<id_t>::value,
"Signed integer required for id.");
109static_assert(std::numeric_limits<id_t>::is_signed,
"Signed integer required for id.");
112template<
typename PSI_value_t,
typename PSI_
id_t,
typename PSI_value_no_cv_t>
115template<
typename PKI_
id_t>
118template<
typename PKR_
id_t>
121template<
typename BPS_
id_t>
124template<
typename PS_value_t,
typename PS_
id_t>
163 bool operator()(id_t id_1, id_t id_2)
const
181 bool operator()(id_t id_1, id_t id_2)
const
195 enum FillActionType {
196 TYPE_UNDEFINED = PiercedSyncAction::TYPE_UNDEFINED,
197 TYPE_OVERWRITE = PiercedSyncAction::TYPE_OVERWRITE,
198 TYPE_INSERT = PiercedSyncAction::TYPE_INSERT,
199 TYPE_APPEND = PiercedSyncAction::TYPE_APPEND
214 enum MoveActionType {
215 TYPE_UNDEFINED = PiercedSyncAction::TYPE_UNDEFINED,
216 TYPE_OVERWRITE = PiercedSyncAction::TYPE_MOVE_OVERWRITE,
217 TYPE_INSERT = PiercedSyncAction::TYPE_MOVE_INSERT,
218 TYPE_APPEND = PiercedSyncAction::TYPE_MOVE_APPEND
233 enum SwapActionType {
234 TYPE_UNDEFINED = PiercedSyncAction::TYPE_UNDEFINED,
235 TYPE_SWAP = PiercedSyncAction::TYPE_SWAP
250 enum EraseActionType {
251 TYPE_UNDEFINED = PiercedSyncAction::TYPE_UNDEFINED,
252 TYPE_PIERCE = PiercedSyncAction::TYPE_PIERCE,
253 TYPE_SHRINK = PiercedSyncAction::TYPE_RESIZE
292 enum ResizeActionType {
293 TYPE_NOOP = PiercedSyncAction::TYPE_NOOP,
294 TYPE_RESERVE = PiercedSyncAction::TYPE_RESERVE,
295 TYPE_CLEAR = PiercedSyncAction::TYPE_CLEAR,
296 TYPE_RESIZE = PiercedSyncAction::TYPE_RESIZE
371 std::size_t
size()
const;
376 std::size_t
count(id_t
id)
const;
380 std::vector<id_t>
getIds(
bool ordered =
true)
const;
381 id_t
getSizeMarker(std::size_t targetSize,
const id_t &fallback = -1);
397 void updateId(const id_t ¤tId, const id_t &updatedId);
416 std::
size_t back() const;
417 std::
size_t front() const;
424 void restore(std::istream &stream);
425 void dump(std::ostream &stream) const;
450 std::
size_t getPos(id_t
id) const;
482 struct PiercedHasher {
492 constexpr std::size_t operator()(U&& value)
const noexcept
494 return static_cast<std::size_t
>(std::forward<U>(value));
509 const std::vector<id_t> &m_ids;
511 idLess(
const std::vector<id_t> &ids)
516 inline bool operator() (std::size_t pos_x, std::size_t pos_y)
518 id_t id_x = m_ids[pos_x];
519 id_t id_y = m_ids[pos_y];
521 if (id_x >= 0 && id_y < 0) {
523 }
else if (id_x < 0 && id_y >= 0) {
525 }
else if (id_x >= 0) {
526 return (id_x < id_y);
528 return (id_x > id_y);
536 static const std::size_t MAX_PENDING_HOLES;
541 std::vector<id_t> m_ids;
547 std::unordered_map<id_t, std::size_t, PiercedHasher> m_pos;
552 std::size_t m_begin_pos;
557 std::size_t m_end_pos;
566 std::size_t m_dirty_begin_pos;
577 std::size_t m_holes_regular_begin;
582 std::size_t m_holes_regular_end;
587 std::size_t m_holes_pending_begin;
592 std::size_t m_holes_pending_end;
597 bool m_holes_regular_sorted;
602 bool m_holes_pending_sorted;
604 void pierce(std::size_t pos,
bool flush =
true);
606 void holesClear(
bool release =
false);
607 void holesClearRegular(
bool release =
false);
608 void holesClearPending(
bool release =
false);
609 void holesResize(std::size_t offset, std::size_t nRegulars, std::size_t nPendings,
bool release =
true);
610 std::size_t holesCount()
const;
611 std::size_t holesCountPending()
const;
612 std::size_t holesCountRegular()
const;
614 void holesSortPending();
615 void holesSortRegular();
617 bool validateId(id_t
id);
619 void setBeginPos(std::size_t pos);
620 void setEndPos(std::size_t pos);
622 void setPosId(std::size_t pos, id_t
id);
623 void setPosEmptyId(std::size_t pos, std::size_t nextUsedPos);
624 void swapPosIds(std::size_t pos_1, id_t id_1, std::size_t pos_2, id_t id_2);
626 void rawShrink(std::size_t n);
633#include "piercedKernel.tpp"
Base class for the pierced kernel.
Iterator for the class PiercedKernel.
The PiercedKernelRange allow to iterate using range-based loops over a PiercedStorage.
Metafunction for generating a pierced kernel.
ResizeAction resize(std::size_t n)
std::size_t getPos(id_t id) const
const_iterator rawFind(std::size_t pos) const noexcept
PiercedKernelIterator< id_t > const_iterator
FillAction fillHole(std::size_t hole, id_t id)
bool isPosEmpty(std::size_t pos) const
std::vector< id_t > getIds(bool ordered=true) const
std::size_t rawSize() const
PiercedKernelRange< id_t > const_range
std::size_t findNextUsedPos(std::size_t pos) const
std::size_t findPrevUsedPos(std::size_t pos) const
SortAction sortBefore(id_t referenceId, bool inclusive)
ResizeAction _resize(std::size_t n)
void updateId(const id_t ¤tId, const id_t &updatedId)
const_iterator cend() const noexcept
EraseAction erase(id_t id, bool flush=false)
const_iterator find(const id_t &id) const noexcept
FillAction fillAppend(id_t id)
bool contains(id_t id) const
ClearAction _clear(bool release=true)
std::size_t getRawIndex(id_t id) const
const_iterator begin() const noexcept
MoveAction moveAfter(id_t referenceId, id_t id, bool flush=false)
ClearAction clear(bool release=true)
ReserveAction reserve(std::size_t n)
std::size_t getFirstUsedPos() const
SortAction _sort(std::size_t begin, std::size_t end)
id_t getSizeMarker(std::size_t targetSize, const id_t &fallback=-1)
FillAction fillAfter(id_t referenceId, id_t id)
~PiercedKernel() override
FillAction fillBefore(id_t referenceId, id_t id)
FillAction fillInsert(std::size_t pos, id_t id)
std::size_t count(id_t id) const
std::size_t front() const
ShrinkToFitAction _shrinkToFit()
const_iterator cbegin() const noexcept
void swap(PiercedKernel &other) noexcept
holes_container::const_iterator holes_const_iterator
std::size_t evalFlatIndex(id_t id) const
void checkIntegrity() const
FillAction fillHead(id_t id)
std::size_t maxSize() const
void restore(std::istream &stream)
SortAction sortAfter(id_t referenceId, bool inclusive)
std::vector< id_t >::const_iterator raw_const_iterator
const_iterator end() const noexcept
ShrinkToFitAction shrinkToFit()
std::size_t capacity() const
std::size_t getLastUsedPos() const
FillAction fillTail(id_t id)
std::vector< std::size_t > holes_container
MoveAction moveBefore(id_t referenceId, id_t id, bool flush=false)
ReserveAction _reserve(std::size_t n)
std::vector< PiercedStorageSyncSlave< id_t > * > getStorages()
holes_container::iterator holes_iterator
Iterator for the class PiercedStorage.
Base class for defining storages that acts like a slave in pierced synchronization.
Metafunction for generating a pierced storage.
Action for pierced synchronization.
PiercedSyncAction(ActionType _type=TYPE_UNDEFINED)
Base class for defining an object that acts like a master in pierced synchronization.