28 template<
typename ALLOC = allocator<
bool>>
42 static constexpr integer BLOCK_MAX_SIZE =
sizeof(underlying_type) * 8;
95 void clearRedundantBits();
154 mutable underlying_type* block_;
211 void next()
const override;
216 void prev()
const override;
253 bool&
get()
override;
271 void set(
const bool &data)
override;
293 bitSet(
const std::initializer_list<bool>&
lst);
432 template<
typename Callback = transform<
bool>>
441 template<
typename ALLOC_>
450 template<
typename ALLOC_>
459 template<
typename ALLOC_>
467 template<
typename ALLOC_>
478 template<
typename ALLOC_>
488 template<
typename ALLOC_>
498 template<
typename ALLOC_>
507 template<
typename ALLOC_>
518 template<
typename ALLOC>
522 template<
typename ALLOC>
525 this->map = array<underlying_type, rebind_alloc_underlying>((size + BLOCK_MAX_SIZE - 1) / BLOCK_MAX_SIZE, rebind_alloc_underlying{});
529 template<
typename ALLOC>
531 return block_value & underlying_type{1} << bit;
534 template<
typename ALLOC>
536 return block_value | underlying_type{1} << bit;
539 template<
typename ALLOC>
541 return block_value & ~(underlying_type{1} << bit);
544 template<
typename ALLOC>
547 return block_value & (underlying_type{1} << (bit + 1)) - underlying_type{1};
550 template<
typename ALLOC>
553 this->map.set(-1, clearHigherBitsFromBlock(this->map.
get(-1), toInnerIdx(this->size() - 1).second()));
556 template<
typename ALLOC>
558 return getBitFromBlock(this->map.
get(block), bit);
561 template<
typename ALLOC>
563 this->map.set(block, setBitFromBlock(this->map.
get(block), bit));
566 template<
typename ALLOC>
568 this->map.set(block, clearBitFromBlock(this->map.
get(block), bit));
571 template<
typename ALLOC>
573 value ? this->setBit(bit, block) : this->clearBit(bit, block);
576 template<
typename ALLOC>
578 return {
static_cast<u_integer
>(index / BLOCK_MAX_SIZE), index % BLOCK_MAX_SIZE};
581 template<
typename ALLOC>
584 return cur_block * BLOCK_MAX_SIZE + cur_bit;
587 template<
typename ALLOC>
589 : cur_bit(bit), cur_block(block), block_(block_p), container_(container) {}
591 template<
typename ALLOC>
593 auto* other_it =
dynamic_cast<const Iterator*
>(other);
594 return other_it !=
nullptr
595 && this->cur_bit == other_it->cur_bit
596 && this->cur_block == other_it->cur_block;
599 template<
typename ALLOC>
604 template<
typename ALLOC>
606 return toOuterIdx(this->cur_block, this->cur_bit) < this->container_->size() - 1;
609 template<
typename ALLOC>
611 return toOuterIdx(this->cur_block, this->cur_bit) > 0;
614 template<
typename ALLOC>
622 template<
typename ALLOC>
630 template<
typename ALLOC>
635 template<
typename ALLOC>
640 template<
typename ALLOC>
643 auto*
it = this->clone();
648 template<
typename ALLOC>
651 auto*
it = this->clone();
656 template<
typename ALLOC>
659 auto new_idx = toInnerIdx(toOuterIdx(this->cur_block, this->cur_bit) +
steps);
660 this->cur_block =
new_idx.first();
661 this->cur_bit =
new_idx.second();
664 template<
typename ALLOC>
667 auto new_idx = toInnerIdx(toOuterIdx(this->cur_block, this->cur_bit) -
steps);
668 this->cur_block =
new_idx.first();
669 this->cur_bit =
new_idx.second();
672 template<
typename ALLOC>
676 return this > &
other ?
677 (std::numeric_limits<integer>::max)() :
678 (std::numeric_limits<integer>::min)();
679 if (this->container_ !=
other_it->container_)
680 return this->container_ >
other_it->container_ ?
681 (std::numeric_limits<integer>::max)() :
682 (std::numeric_limits<integer>::min)();
684 return toOuterIdx(this->cur_block, this->cur_bit) - toOuterIdx(
other_it->cur_block,
other_it->cur_bit);
687 template<
typename ALLOC>
692 template<
typename ALLOC>
694 return "bitSet::Iterator";
697 template<
typename ALLOC>
701 return getBitFromBlock(*this->block_, this->cur_bit);
704 template<
typename ALLOC>
707 *this->block_ = data ?
708 setBitFromBlock(*this->block_, this->cur_bit) : clearBitFromBlock(*this->block_, this->cur_bit);
711 template<
typename ALLOC>
713 const auto outer = toOuterIdx(this->cur_block, this->cur_bit);
714 return outer >= 0 &&
outer < this->container_->size();
717 template<
typename ALLOC>
720 this->bitsetInit(
size);
723 template<
typename ALLOC>
726 for (
const auto&
e :
lst) {
727 auto idx = toInnerIdx(
i);
728 this->writeBit(
idx.second(),
idx.first(),
e);
733 template<
typename ALLOC>
738 template<
typename ALLOC>
740 if (
this == &
other)
return *
this;
741 this->map =
other.map;
742 this->size_ =
other.size_;
743 if constexpr (ALLOC::propagate_on_container_copy_assignment::value){
749 template<
typename ALLOC>
752 this->operator=(std::move(
other));
755 template<
typename ALLOC>
761 this->map = std::move(
other.map);
762 this->size_ =
other.size_;
763 if constexpr (ALLOC::propagate_on_container_move_assignment::value){
770 template <
typename ALLOC>
778 if constexpr (ALLOC::propagate_on_container_swap::value) {
783 template<
typename ALLOC>
786 for (
const auto&
e : this->map) {
796 template<
typename ALLOC>
806 nb.map.set(
i, this->map.
get(
i));
808 nb.clearRedundantBits();
812 template<
typename ALLOC>
818 template<
typename ALLOC>
820 return new Iterator(0, 0, &this->map.data(),
this);
823 template<
typename ALLOC>
825 return new Iterator(toInnerIdx(this->size() - 1).second(), this->map.size() - 1,
826 &
this->map.data() +
this->map.size() - 1,
this);
829 template<
typename ALLOC>
832 index = this->parseNegIndex(index);
833 auto idx = toInnerIdx(index);
834 return this->getBit(
idx.second(),
idx.first());
837 template<
typename ALLOC>
842 template<
typename ALLOC>
845 index = this->parseNegIndex(index);
846 auto idx = toInnerIdx(index);
847 this->writeBit(
idx.second(),
idx.first(),
e);
850 template<
typename ALLOC>
853 if (
auto idx = toInnerIdx(
i);
854 e == this->getBit(
idx.second(),
idx.first())) {
861 template<
typename ALLOC>
863 if (this->size() !=
other.size()) {
876 template<
typename ALLOC>
878 if (this->size() !=
other.size()) {
891 template<
typename ALLOC>
893 if (this->size() !=
other.size()) {
906 template<
typename ALLOC>
911 template<
typename ALLOC_>
918 template<
typename ALLOC_>
919 auto original::operator|(
const bitSet<ALLOC_> &lbs,
const bitSet<ALLOC_> &rbs) -> bitSet<ALLOC_> {
925 template<
typename ALLOC_>
926 auto original::operator^(
const bitSet<ALLOC_> &lbs,
const bitSet<ALLOC_> &rbs) -> bitSet<ALLOC_> {
932 template<
typename ALLOC_>
935 for (u_integer i = 0; i < nbs.map.size(); i++) {
936 nbs.map.set(i, ~nbs.map.get(i));
938 nbs.clearRedundantBits();
942 template <
typename ALLOC>
Provides the array class for a fixed-size container with random access.
Default memory allocator using allocators utilities.
Definition allocator.h:153
void swap(autoPtr &other) noexcept
Swaps the reference counters between two autoPtr instances.
Definition autoPtr.h:703
const TYPE * get() const
Get managed pointer const version.
Definition autoPtr.h:629
Base class for fixed-size serial containers.
Definition baseArray.h:43
A base class for basic iterators.
Definition iterator.h:296
An iterator for traversing the bits in a bitSet.
Definition bitSet.h:151
bool hasPrev() const override
Checks if there is a previous element.
Definition bitSet.h:610
bool hasNext() const override
Checks if there is a next element.
Definition bitSet.h:605
Iterator * getPrev() const override
Gets the previous iterator.
Definition bitSet.h:641
bool atNext(const iterator *other) const override
Checks if the iterator is at the next element.
Definition bitSet.h:623
bool & get() override
Gets the value of the current bit.
Definition bitSet.h:688
void next() const override
Moves the iterator to the next element.
Definition bitSet.h:631
Iterator * clone() const override
Clones the iterator.
Definition bitSet.h:600
bool atPrev(const iterator *other) const override
Checks if the iterator is at the previous element.
Definition bitSet.h:615
std::string className() const override
Returns the class name of this iterator.
Definition bitSet.h:693
void operator+=(integer steps) const override
Advances the iterator by the given number of steps.
Definition bitSet.h:657
void operator-=(integer steps) const override
Moves the iterator backward by the given number of steps.
Definition bitSet.h:665
void set(const bool &data) override
Sets the value of the current bit.
Definition bitSet.h:705
void prev() const override
Moves the iterator to the previous element.
Definition bitSet.h:636
bool isValid() const override
Checks if the iterator is valid.
Definition bitSet.h:712
Iterator * getNext() const override
Gets the next iterator.
Definition bitSet.h:649
A class representing a set of bits, offering functionality to manipulate and query individual bits.
Definition bitSet.h:29
Iterator * begins() const override
Gets the iterator to the beginning of the bitSet.
Definition bitSet.h:819
friend bitSet< ALLOC_ > operator^(const bitSet< ALLOC_ > &lbs, const bitSet< ALLOC_ > &rbs)
Performs a bitwise XOR operation between two bitSets.
bitSet & operator|=(const bitSet &other)
Performs a bitwise OR operation between two bitSets.
Definition bitSet.h:877
u_integer indexOf(const bool &e) const override
Finds the index of the first occurrence of a specific value.
Definition bitSet.h:851
bitSet & operator&=(const bitSet &other)
Performs a bitwise AND operation between two bitSets.
Definition bitSet.h:862
bitSet(u_integer size, ALLOC allocator=ALLOC{})
Constructs a bitSet with the given size.
Definition bitSet.h:718
Iterator * ends() const override
Gets the iterator to the end of the bitSet.
Definition bitSet.h:824
bool & operator[](integer index) override
Gets the reference of a specific bit by index.
Definition bitSet.h:838
void set(integer index, const bool &e) override
Sets the value of a specific bit by index.
Definition bitSet.h:843
bitSet & operator^=(const bitSet &other)
Performs a bitwise XOR operation between two bitSets.
Definition bitSet.h:892
u_integer size() const override
Gets the size of the bitSet.
Definition bitSet.h:813
void swap(bitSet &other) noexcept
Swaps the contents of this bitSet with another.
Definition bitSet.h:771
bitSet resize(u_integer new_size) const
Resizes the bitSet to the given size.
Definition bitSet.h:797
bool get(integer index) const override
Gets the value of a specific bit by index.
Definition bitSet.h:830
friend bitSet< ALLOC_ > operator&(const bitSet< ALLOC_ > &lbs, const bitSet< ALLOC_ > &rbs)
Performs a bitwise AND operation between two bitSets.
void forEach(Callback operation=Callback{})=delete
Deleted forEach method to prevent misuse.
u_integer count() const
Counts the number of bits set to true.
Definition bitSet.h:784
friend bitSet< ALLOC_ > operator~(const bitSet< ALLOC_ > &bs)
Performs a bitwise NOT operation on a bitSet.
friend bitSet< ALLOC_ > operator|(const bitSet< ALLOC_ > &lbs, const bitSet< ALLOC_ > &rbs)
Performs a bitwise OR operation between two bitSets.
std::string className() const override
Gets the class name for the bitSet.
Definition bitSet.h:907
bitSet & operator=(const bitSet &other)
Copy assignment operator.
Definition bitSet.h:739
Abstract base class for containers.
Definition container.h:26
A stream class that allows iteration, comparison, hashing and printing.
Definition iterationStream.h:60
Base iterator interface that supports common operations for iteration.
Definition iterator.h:37
friend iterator< T > * operator-(const iterator< T > &it, integer steps)
Subtracts a number of steps from the iterator's current position and returns a new iterator.
Abstract base class for key-value mapping containers.
Definition map.h:49
Exception for container index out-of-range errors.
Definition error.h:192
Unique ownership smart pointer with move semantics.
Definition ownerPtr.h:37
Abstract base class for unique element containers.
Definition set.h:44
Exception for unimplemented method calls.
Definition error.h:271
Generic pair container implementation.
Provides functionality for an iteration stream with comparison, hashing and printing.
Main namespace for the project Original.
Definition algorithms.h:21
auto operator-(const iterator< T > &it, integer steps) -> iterator< T > *
Subtracts a number of steps from the iterator's current position and returns a new iterator.
bitSet< ALLOC_ > operator^(const bitSet< ALLOC_ > &lbs, const bitSet< ALLOC_ > &rbs)
Bitwise XOR operator for two bitSets.
bitSet< ALLOC_ > operator~(const bitSet< ALLOC_ > &bs)
Bitwise NOT operator for a bitSet.
TYPE minimum(TYPE a, TYPE b)
Returns the smaller of two given values.
bitSet< ALLOC_ > operator&(const bitSet< ALLOC_ > &lbs, const bitSet< ALLOC_ > &rbs)
Bitwise AND operator for two bitSets.
bitSet< ALLOC_ > operator|(const bitSet< ALLOC_ > &lbs, const bitSet< ALLOC_ > &rbs)
Bitwise OR operator for two bitSets.
auto count()
Creates a count pipe operation.
Definition generators.h:957
Standard namespace extensions for original::alternative.
Definition allocator.h:351
void swap(original::objPoolAllocator< TYPE > &lhs, original::objPoolAllocator< TYPE > &rhs) noexcept
Specialization of std::swap for objPoolAllocator.
Definition allocator.h:635