NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
bitmap.hpp
浏览该文件的文档.
1#ifndef NEFORCE_CORE_CONTAINER_BITMAP_HPP__
2#define NEFORCE_CORE_CONTAINER_BITMAP_HPP__
3
12
15NEFORCE_BEGIN_NAMESPACE__
16
22
24NEFORCE_INLINE17 constexpr uint32_t BITMAP_WORD_SIZE = 8 * sizeof(uint32_t);
25
33struct bit_reference : icommon<bit_reference>, istringify<bit_reference> {
34private:
35 uint32_t* ptr_ = nullptr;
36 uint32_t mask_ = 0;
37
38public:
42 NEFORCE_CONSTEXPR20 bit_reference() = default;
43
49 NEFORCE_CONSTEXPR20 bit_reference(uint32_t* ptr, const uint32_t mask) noexcept :
50 ptr_(ptr),
51 mask_(mask) {}
52
57 NEFORCE_CONSTEXPR20 bit_reference(const bit_reference& other) noexcept :
58 ptr_(other.ptr_),
59 mask_(other.mask_) {}
60
66 NEFORCE_CONSTEXPR20 bit_reference& operator=(const bit_reference& other) noexcept {
67 return *this = static_cast<bool>(other);
68 }
69
74 NEFORCE_CONSTEXPR20 bit_reference(bit_reference&& other) noexcept :
75 ptr_(other.ptr_),
76 mask_(other.mask_) {
77 other.ptr_ = nullptr;
78 other.mask_ = 0;
79 }
80
86 NEFORCE_CONSTEXPR20 bit_reference& operator=(bit_reference&& other) noexcept {
87 *this = static_cast<bool>(other);
88 other.ptr_ = nullptr;
89 other.mask_ = 0;
90 return *this;
91 }
92
98 NEFORCE_CONSTEXPR20 bit_reference& operator=(const bool value) noexcept {
99 if (value) {
100 *ptr_ |= mask_;
101 } else {
102 *ptr_ &= ~mask_;
103 }
104 return *this;
105 }
106
111 NEFORCE_CONSTEXPR20 explicit operator bool() const noexcept { return *ptr_ & mask_; }
112
116 NEFORCE_CONSTEXPR20 void flip() const noexcept { *ptr_ ^= mask_; }
117
122 NEFORCE_CONSTEXPR20 void swap(bit_reference& other) noexcept {
123 if (_NEFORCE addressof(other) == this) {
124 return;
125 }
126 const bool tmp = static_cast<bool>(other);
127 other = *this;
128 *this = tmp;
129 }
130
136 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 bool operator==(const bit_reference& rhs) const noexcept {
137 return static_cast<bool>(*this) == static_cast<bool>(rhs);
138 }
139
145 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 bool operator<(const bit_reference& rhs) const noexcept {
146 return static_cast<bool>(*this) < static_cast<bool>(rhs);
147 }
148
153 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 size_t to_hash() const noexcept {
154 return hash<bool>()(static_cast<bool>(*this));
155 }
156
161 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 string to_string() const { return static_cast<bool>(*this) ? "1"_s : "0"_s; }
162};
163
164
173template <bool IsConst, typename BitMap>
174struct bitmap_iterator : iiterator<bitmap_iterator<IsConst, BitMap>> {
175public:
176 using container_type = BitMap;
177 using value_type = typename container_type::value_type;
178 using size_type = typename container_type::size_type;
179 using difference_type = typename container_type::difference_type;
181 using reference = conditional_t<IsConst, typename container_type::const_reference,
182 typename container_type::reference>;
183 using pointer = conditional_t<IsConst, typename container_type::const_pointer,
184 typename container_type::pointer>;
185
186private:
187 uint32_t* ptr_ = nullptr;
188 uint32_t off_ = 0;
189 const container_type* container_ = nullptr;
190
191 friend class bitmap;
192 template <bool, typename>
193 friend struct bitmap_iterator;
194
195private:
196 template <typename Ref>
197 NEFORCE_CONSTEXPR20 enable_if_t<is_boolean_v<Ref>, Ref> reference_dispatch() const noexcept {
198 return (*ptr_ & (1U << off_)) != 0;
199 }
200
201 template <typename Ref>
202 NEFORCE_CONSTEXPR20 enable_if_t<!is_boolean_v<Ref>, Ref> reference_dispatch() const noexcept {
203 return Ref(ptr_, 1U << off_);
204 }
205
206public:
207 NEFORCE_CONSTEXPR20 bitmap_iterator() noexcept = default;
208 NEFORCE_CONSTEXPR20 ~bitmap_iterator() = default;
209
210 NEFORCE_CONSTEXPR20 bitmap_iterator(const bitmap_iterator&) noexcept = default;
211 NEFORCE_CONSTEXPR20 bitmap_iterator& operator=(const bitmap_iterator&) noexcept = default;
212 NEFORCE_CONSTEXPR20 bitmap_iterator(bitmap_iterator&&) noexcept = default;
213 NEFORCE_CONSTEXPR20 bitmap_iterator& operator=(bitmap_iterator&&) noexcept = default;
214
221 NEFORCE_CONSTEXPR20 bitmap_iterator(uint32_t* ptr, const uint32_t offset, const container_type* bm) noexcept :
222 ptr_(ptr),
223 off_(offset),
224 container_(bm) {}
225
231 template <bool IsConst2>
232 NEFORCE_CONSTEXPR20 explicit bitmap_iterator(const bitmap_iterator<IsConst2, BitMap>& other) noexcept :
233 ptr_(other.ptr_),
234 off_(other.off_),
235 container_(other.container_) {}
236
241 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 reference dereference() const noexcept {
242 NEFORCE_DEBUG_VERIFY(ptr_ && container_, "Attempting to dereference on a null pointer");
243 return reference_dispatch<reference>();
244 }
245
249 NEFORCE_CONSTEXPR20 void increment() noexcept {
250 NEFORCE_DEBUG_VERIFY(ptr_ && container_, "Attempting to increment a null pointer");
251 if (off_++ == BITMAP_WORD_SIZE - 1) {
252 off_ = 0;
253 ++ptr_;
254 }
255 }
256
260 NEFORCE_CONSTEXPR20 void decrement() noexcept {
261 NEFORCE_DEBUG_VERIFY(ptr_ && container_, "Attempting to increment a null pointer");
262 if (off_-- == 0) {
263 off_ = BITMAP_WORD_SIZE - 1;
264 --ptr_;
265 }
266 }
267
272 NEFORCE_CONSTEXPR20 void advance(difference_type off) noexcept {
273 NEFORCE_DEBUG_VERIFY((ptr_ && container_) || off == 0, "Attempting to advance a null pointer");
274 difference_type n = off + off_;
275 ptr_ += n / BITMAP_WORD_SIZE;
276 n = n % BITMAP_WORD_SIZE;
277 if (n < 0) {
278 off_ = static_cast<uint32_t>(n) + BITMAP_WORD_SIZE;
279 --ptr_;
280 } else {
281 off_ = static_cast<uint32_t>(n);
282 }
283 }
284
290 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 difference_type distance_to(const bitmap_iterator& other) const noexcept {
291 NEFORCE_DEBUG_VERIFY(container_ == other.container_, "Attempting to distance to a different container");
292 return BITMAP_WORD_SIZE * (ptr_ - other.ptr_) + off_ - other.off_;
293 }
294
300 NEFORCE_CONSTEXPR20 reference operator[](const difference_type n) const noexcept { return *(*this + n); }
301
307 NEFORCE_CONSTEXPR20 bool equal(const bitmap_iterator& rhs) const noexcept {
308 NEFORCE_DEBUG_VERIFY(container_ == rhs.container_, "Attempting to equal to a different container");
309 return ptr_ == rhs.ptr_ && off_ == rhs.off_;
310 }
311
317 NEFORCE_CONSTEXPR20 bool less_than(const bitmap_iterator& rhs) const noexcept {
318 NEFORCE_DEBUG_VERIFY(container_ == rhs.container_, "Attempting to equal to a different container");
319 return ptr_ < rhs.ptr_ || (ptr_ == rhs.ptr_ && off_ < rhs.off_);
320 }
321
326 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 pointer base() const noexcept { return ptr_; }
327
332 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const container_type* container() const noexcept { return container_; }
333};
334
335
343class bitmap : public icollector<bitmap> {
344public:
345 using value_type = bool;
348 using const_pointer = const bool*;
349 using const_reference = const bool;
357
358private:
365 struct bit_storage {
366 uint32_t* ptr = nullptr;
368
372 NEFORCE_CONSTEXPR20 bit_storage() noexcept = default;
373
378 explicit NEFORCE_CONSTEXPR20 bit_storage(const size_t word) {
379 if (word == 0) {
380 return;
381 }
382 ptr = cpair.get_base().allocate(word);
383 cpair.value = word;
384 }
385
389 NEFORCE_CONSTEXPR20 ~bit_storage() {
390 if (ptr) {
391 cpair.get_base().deallocate(ptr, cpair.value);
392 }
393 }
394
395 bit_storage(const bit_storage&) = delete;
396 bit_storage& operator=(const bit_storage&) = delete;
397
402 NEFORCE_CONSTEXPR20 bit_storage(bit_storage&& other) noexcept :
403 ptr(other.ptr),
404 cpair(_NEFORCE move(other.cpair)) {
405 other.ptr = nullptr;
406 other.cpair.value = 0;
407 }
408
414 NEFORCE_CONSTEXPR20 bit_storage& operator=(bit_storage&& other) noexcept {
415 if (addressof(other) == this) {
416 return *this;
417 }
418
419 reset();
420 cpair = _NEFORCE move(other.cpair);
421 other.ptr = nullptr;
422 other.cpair.value = 0;
423
424 return *this;
425 }
426
432 NEFORCE_CONSTEXPR20 void reset(uint32_t* new_ptr = nullptr, const size_t cap = 0) {
433 if (ptr) {
434 cpair.get_base().deallocate(ptr, cpair.value);
435 }
436 ptr = new_ptr;
437 cpair.value = cap;
438 }
439
444 NEFORCE_CONSTEXPR20 void allocate(const size_t word) { reset(cpair.get_base().allocate(word), word); }
445
450 NEFORCE_CONSTEXPR20 uint32_t* get() const noexcept { return ptr; }
451
456 NEFORCE_CONSTEXPR20 size_t capacity() const noexcept { return cpair.value; }
457 };
458
459 iterator start_{};
460 iterator finish_{};
461 bit_storage storage_{};
462
463private:
469 static constexpr size_t word_count(const size_type word) noexcept {
470 return (word + BITMAP_WORD_SIZE - 1) / BITMAP_WORD_SIZE;
471 }
472
477 NEFORCE_CONSTEXPR20 void allocate_storage(const size_type word) {
478 if (word == 0) {
479 return;
480 }
481 storage_.allocate(word_count(word));
482 }
483
488 NEFORCE_CONSTEXPR20 void set_iterators(const size_type word) noexcept {
489 start_ = iterator(storage_.get(), 0, this);
490 finish_ = start_ + static_cast<difference_type>(word);
491 }
492
502 template <typename Iterator1, typename Iterator2>
503 NEFORCE_CONSTEXPR20 Iterator2 bit_copy(Iterator1 first, Iterator1 last, Iterator2 result) {
504 iter_difference_t<Iterator1> n = _NEFORCE distance(first, last);
505 for (; n > 0; --n, ++first, ++result) {
506 *result = *first;
507 }
508 return result;
509 }
510
520 template <typename Iterator1, typename Iterator2>
521 NEFORCE_CONSTEXPR20 Iterator2 bit_copy_backward(Iterator1 first, Iterator1 last, Iterator2 result) {
522 iter_difference_t<Iterator1> n = _NEFORCE distance(first, last);
523 for (; n > 0; --n) {
524 *--result = *--last;
525 }
526 return result;
527 }
528
535 void reallocate_insert(const iterator& position, const size_type extra_len, const bool value) {
536 const size_type old_size = size();
537 const size_type new_size = old_size + extra_len;
538 const size_type new_words = word_count(new_size);
539 bit_storage new_storage(new_words);
540
541 const iterator new_start(new_storage.get(), 0, this);
542 auto new_finish = bitmap::bit_copy(begin(), position, new_start);
543 _NEFORCE fill_n(new_finish, extra_len, value);
544 new_finish += static_cast<difference_type>(extra_len);
545 bitmap::bit_copy(position, end(), new_finish);
546 new_finish += (end() - position);
547
548 storage_ = _NEFORCE move(new_storage);
549 start_ = new_start;
550 finish_ = new_finish;
551 }
552
561 template <typename Iterator>
562 void reallocate_insert_range(const iterator position, Iterator first, Iterator last, const size_type extra_len) {
563 const size_type old_size = size();
564 const size_type new_size = old_size + extra_len;
565 const size_type new_words = word_count(new_size);
566 bit_storage new_storage(new_words);
567
568 const iterator new_start(new_storage.get(), 0, this);
569 auto new_finish = bitmap::bit_copy(begin(), position, new_start);
570 new_finish = bitmap::bit_copy(first, last, new_finish);
571 new_finish = bitmap::bit_copy(position, end(), new_finish);
572
573 storage_ = _NEFORCE move(new_storage);
574 start_ = new_start;
575 finish_ = new_finish;
576 }
577
583 void insert_aux(const iterator& position, const bool value) {
584 if (finish_.ptr_ != storage_.get() + storage_.capacity()) {
585 bit_copy_backward(position, finish_, finish_ + 1);
586 *position = value;
587 ++finish_;
588 } else {
589 const size_type len = size() ? 2 * size() : BITMAP_WORD_SIZE;
590 reallocate_insert(position, 1, value);
591 }
592 }
593
600 template <typename Iterator>
601 enable_if_t<!is_ranges_fwd_iter_v<Iterator>> range_init(Iterator first, Iterator last) {
602 if (first == last) {
603 return;
604 }
605
606 bitmap tmp{};
607 while (first != last) {
608 tmp.push_back(*first);
609 ++first;
610 }
611
612 bitmap::swap(tmp);
613 return;
614 }
615
622 template <typename Iterator>
623 enable_if_t<is_ranges_fwd_iter_v<Iterator>> range_init(Iterator first, Iterator last) {
624 if (first == last) {
625 return;
626 }
627
628 const size_type n = _NEFORCE distance(first, last);
629 bit_storage tmp_storage(word_count(n));
630 iterator tmp_start(tmp_storage.get(), 0, this);
631 const iterator tmp_finish = bitmap::bit_copy(first, last, tmp_start);
632
633 storage_ = _NEFORCE move(tmp_storage);
634 start_ = tmp_start;
635 finish_ = tmp_finish;
636 return;
637 }
638
646 template <typename Iterator>
647 enable_if_t<!is_ranges_fwd_iter_v<Iterator>> insert_range(iterator position, Iterator first, Iterator last) {
648 if (first == last) {
649 return;
650 }
651 bitmap tmp(first, last);
652 insert_range(position, tmp.begin(), tmp.end());
653 return;
654 }
655
663 template <typename Iterator>
664 enable_if_t<is_ranges_fwd_iter_v<Iterator>> insert_range(iterator position, Iterator first, Iterator last) {
665 if (first == last) {
666 return;
667 }
668 const size_type n = _NEFORCE distance(first, last);
669 if (capacity() - size() >= n) {
670 bitmap::bit_copy_backward(position, end(), finish_ + static_cast<difference_type>(n));
671 bitmap::bit_copy(first, last, position);
672 finish_ += static_cast<difference_type>(n);
673 } else {
674 bitmap::reallocate_insert_range(position, first, last, n);
675 }
676 return;
677 }
678
679public:
685 NEFORCE_CONSTEXPR20 bitmap() noexcept = default;
686
693 NEFORCE_CONSTEXPR20 explicit bitmap(const size_type word) {
694 if (word == 0) {
695 return;
696 }
697 allocate_storage(word);
698 set_iterators(word);
699 _NEFORCE fill(storage_.get(), storage_.get() + storage_.capacity(), 0);
700 }
701
707 NEFORCE_CONSTEXPR20 explicit bitmap(const size_type word, const bool value) {
708 if (word == 0) {
709 return;
710 }
711 allocate_storage(word);
712 set_iterators(word);
713 _NEFORCE fill(storage_.get(), storage_.get() + storage_.capacity(), value ? ~0U : 0U);
714 }
715
721 NEFORCE_CONSTEXPR20 explicit bitmap(const int32_t word, const bool value) :
722 bitmap(static_cast<size_type>(word), value) {}
723
729 NEFORCE_CONSTEXPR20 explicit bitmap(const int64_t word, const bool value) :
730 bitmap(static_cast<size_type>(word), value) {}
731
736 NEFORCE_CONSTEXPR20 bitmap(const bitmap& other) {
737 if (other.empty()) {
738 return;
739 }
740
741 const size_type n = other.size();
742 bit_storage tmp(word_count(n));
743 const iterator tmp_start(tmp.get(), 0, this);
744 const auto tmp_finish = bit_copy(other.cbegin(), other.cend(), tmp_start);
745
746 storage_ = _NEFORCE move(tmp);
747 start_ = tmp_start;
748 finish_ = tmp_finish;
749 }
750
756 NEFORCE_CONSTEXPR20 bitmap& operator=(const bitmap& other) {
757 if (_NEFORCE addressof(other) == this) {
758 return *this;
759 }
760 bitmap tmp(other);
761 bitmap::swap(tmp);
762 return *this;
763 }
764
769 NEFORCE_CONSTEXPR20 bitmap(bitmap&& other) noexcept :
770 start_(other.start_.ptr_, other.start_.off_, this),
771 finish_(other.finish_.ptr_, other.finish_.off_, this),
772 storage_(_NEFORCE move(other.storage_)) {
773 other.start_ = iterator();
774 other.finish_ = iterator();
775 }
776
782 NEFORCE_CONSTEXPR20 bitmap& operator=(bitmap&& other) noexcept {
783 if (_NEFORCE addressof(other) == this) {
784 return *this;
785 }
786 bitmap::swap(other);
787 return *this;
788 }
789
796 template <typename Iterator, enable_if_t<is_iter_v<Iterator>, int> = 0>
797 NEFORCE_CONSTEXPR20 bitmap(Iterator first, Iterator last) {
798 bitmap::range_init(first, last);
799 }
800
804 NEFORCE_CONSTEXPR20 ~bitmap() = default;
805
810 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 iterator begin() noexcept { return start_; }
811
816 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 iterator end() noexcept { return finish_; }
817
822 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const_iterator begin() const noexcept { return cbegin(); }
823
828 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const_iterator end() const noexcept { return cend(); }
829
834 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const_iterator cbegin() const noexcept { return const_iterator{start_}; }
835
840 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const_iterator cend() const noexcept { return const_iterator{finish_}; }
841
846 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 reverse_iterator rbegin() noexcept { return reverse_iterator(end()); }
847
852 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 reverse_iterator rend() noexcept { return reverse_iterator(begin()); }
853
858 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const_reverse_iterator rbegin() const noexcept { return crbegin(); }
859
864 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const_reverse_iterator rend() const noexcept { return crend(); }
865
870 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const_reverse_iterator crbegin() const noexcept {
872 }
873
878 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const_reverse_iterator crend() const noexcept {
880 }
881
886 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 size_type size() const noexcept { return cend() - cbegin(); }
887
892 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 size_type max_size() const noexcept { return static_cast<size_type>(-1); }
893
898 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 bool empty() const noexcept { return start_ == finish_; }
899
904 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 size_type capacity() const noexcept {
905 return storage_.capacity() * BITMAP_WORD_SIZE;
906 }
907
913 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 reference operator[](const size_type n) {
914 return *(begin() + static_cast<difference_type>(n));
915 }
916
922 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const_reference operator[](const size_type n) const {
923 return *(cbegin() + static_cast<difference_type>(n));
924 }
925
930 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 reference front() { return *begin(); }
931
936 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const_reference front() const { return *cbegin(); }
937
942 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 reference back() { return *(end() - 1); }
943
948 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const_reference back() const { return *(cend() - 1); }
949
956 NEFORCE_CONSTEXPR20 void reserve(const size_type n) {
957 if (capacity() < n) {
958 const size_type new_words = word_count(n);
959 bit_storage new_storage(new_words);
960 const iterator new_start(new_storage.get(), 0, this);
961 const auto new_finish = bit_copy(begin(), end(), new_start);
962
963 storage_ = _NEFORCE move(new_storage);
964 start_ = new_start;
965 finish_ = new_finish;
966 }
967 }
968
973 NEFORCE_CONSTEXPR20 void push_back(const bool value) {
974 if (finish_.ptr_ != storage_.get() + storage_.capacity()) {
975 *finish_++ = value;
976 } else {
977 insert_aux(end(), value);
978 }
979 }
980
987 NEFORCE_CONSTEXPR20 iterator insert(const iterator& position, const bool value) {
988 const difference_type n = position - begin();
989 if (finish_.ptr_ != storage_.get() + storage_.capacity() && position == end()) {
990 *finish_++ = value;
991 } else {
992 insert_aux(position, value);
993 }
994 return begin() + n;
995 }
996
1004 template <typename Iterator>
1005 NEFORCE_CONSTEXPR20 void insert(iterator position, Iterator first, Iterator last) {
1006 bitmap::insert_range(position, first, last);
1007 }
1008
1015 NEFORCE_CONSTEXPR20 void insert(const iterator& position, const bool* first, const bool* last) {
1016 if (first == last) {
1017 return;
1018 }
1019 const size_type n = _NEFORCE distance(first, last);
1020 if (capacity() - size() >= n) {
1021 bitmap::bit_copy_backward(position, end(), finish_ + static_cast<difference_type>(n));
1022 bitmap::bit_copy(first, last, position);
1023 finish_ += static_cast<difference_type>(n);
1024 } else {
1025 bitmap::reallocate_insert_range(position, first, last, n);
1026 }
1027 }
1028
1035 NEFORCE_CONSTEXPR20 void insert(const iterator& position, const size_type n, const bool value) {
1036 if (n == 0) {
1037 return;
1038 }
1039 if (capacity() - size() >= n) {
1040 bitmap::bit_copy_backward(position, end(), finish_ + static_cast<difference_type>(n));
1041 _NEFORCE fill(position, position + static_cast<difference_type>(n), value);
1042 finish_ += static_cast<difference_type>(n);
1043 } else {
1044 bitmap::reallocate_insert(position, n, value);
1045 }
1046 }
1047
1054 NEFORCE_CONSTEXPR20 void insert(const iterator& pos, const int32_t n, const bool value) {
1055 bitmap::insert(pos, static_cast<size_type>(n), value);
1056 }
1057
1064 NEFORCE_CONSTEXPR20 void insert(const iterator& pos, const int64_t n, const bool value) {
1065 bitmap::insert(pos, static_cast<size_type>(n), value);
1066 }
1067
1071 NEFORCE_CONSTEXPR20 void pop_back() { --finish_; }
1072
1078 NEFORCE_CONSTEXPR20 iterator erase(const iterator& position) {
1079 if (position + 1 != end()) {
1080 bitmap::bit_copy(position + 1, end(), position);
1081 }
1082 --finish_;
1083 return position;
1084 }
1085
1092 NEFORCE_CONSTEXPR20 iterator erase(const iterator& first, const iterator& last) {
1093 finish_ = bitmap::bit_copy(last, end(), first);
1094 return first;
1095 }
1096
1102 NEFORCE_CONSTEXPR20 void resize(const size_type n, const bool value = bool()) {
1103 if (n < size()) {
1104 bitmap::erase(begin() + static_cast<difference_type>(n), end());
1105 } else {
1106 bitmap::insert(end(), n - size(), value);
1107 }
1108 }
1109
1113 NEFORCE_CONSTEXPR20 void clear() { bitmap::erase(begin(), end()); }
1114
1119 NEFORCE_CONSTEXPR20 void swap(bitmap& other) noexcept {
1120 if (_NEFORCE addressof(other) == this) {
1121 return;
1122 }
1123 _NEFORCE swap(start_, other.start_);
1124 _NEFORCE swap(finish_, other.finish_);
1125 _NEFORCE swap(storage_, other.storage_);
1126 start_.container_ = this;
1127 finish_.container_ = this;
1128 other.start_.container_ = &other;
1129 other.finish_.container_ = &other;
1130 }
1131
1137 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 bool operator==(const bitmap& rhs) const
1138 noexcept(noexcept(_NEFORCE equal(this->cbegin(), this->cend(), rhs.cbegin()))) {
1139 return this->size() == rhs.size() && _NEFORCE equal(this->cbegin(), this->cend(), rhs.cbegin());
1140 }
1141
1147 NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 bool operator<(const bitmap& rhs) const
1148 noexcept(noexcept(_NEFORCE lexicographical_compare(this->cbegin(), this->cend(), rhs.cbegin(),
1149 rhs.cend()))) {
1150 return _NEFORCE lexicographical_compare(this->cbegin(), this->cend(), rhs.cbegin(), rhs.cend());
1151 }
1152};
1153 // BitManipulation
1155
1156NEFORCE_END_NAMESPACE__
1157#endif // NEFORCE_CORE_CONTAINER_BITMAP_HPP__
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const_reference front() const
常量版本,访问第一个位
NEFORCE_CONSTEXPR20 bitmap & operator=(const bitmap &other)
拷贝赋值运算符
_NEFORCE reverse_iterator< const_iterator > const_reverse_iterator
常量反向迭代器类型
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 reference operator[](const size_type n)
下标访问操作符
NEFORCE_CONSTEXPR20 void resize(const size_type n, const bool value=bool())
调整大小
bit_reference reference
引用类型
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const_reference operator[](const size_type n) const
常量下标访问操作符
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const_reverse_iterator crend() const noexcept
获取常量反向结束迭代器
bitmap_iterator< false, bitmap > iterator
迭代器类型
NEFORCE_CONSTEXPR20 bitmap(const size_type word, const bool value)
构造函数,指定大小和初始值
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 reference front()
访问第一个位
NEFORCE_CONSTEXPR20 void insert(iterator position, Iterator first, Iterator last)
范围插入
allocator< uint32_t > allocator_type
分配器类型
NEFORCE_CONSTEXPR20 void insert(const iterator &pos, const int32_t n, const bool value)
插入n个相同的位
ptrdiff_t difference_type
差值类型
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const_reverse_iterator crbegin() const noexcept
获取常量反向起始迭代器
NEFORCE_CONSTEXPR20 iterator erase(const iterator &first, const iterator &last)
删除指定范围内的位
NEFORCE_CONSTEXPR20 bitmap(const bitmap &other)
拷贝构造函数
bool value_type
值类型
NEFORCE_CONSTEXPR20 bitmap() noexcept=default
默认构造函数
bitmap_iterator< true, bitmap > const_iterator
常量迭代器类型
_NEFORCE reverse_iterator< iterator > reverse_iterator
反向迭代器类型
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 bool operator==(const bitmap &rhs) const noexcept(noexcept(_NEFORCE equal(this->cbegin(), this->cend(), rhs.cbegin())))
相等比较操作符
bit_reference * pointer
指针类型
NEFORCE_CONSTEXPR20 void reserve(const size_type n)
预留容量
NEFORCE_CONSTEXPR20 void clear()
清空位图
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 size_type max_size() const noexcept
获取最大可能位数
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 reverse_iterator rend() noexcept
获取反向结束迭代器
const bool const_reference
常量引用类型
NEFORCE_CONSTEXPR20 ~bitmap()=default
析构函数
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const_iterator end() const noexcept
获取常量结束迭代器
NEFORCE_CONSTEXPR20 void insert(const iterator &pos, const int64_t n, const bool value)
插入n个相同的位
NEFORCE_CONSTEXPR20 bitmap & operator=(bitmap &&other) noexcept
移动赋值运算符
const bool * const_pointer
常量指针类型
NEFORCE_CONSTEXPR20 iterator insert(const iterator &position, const bool value)
在指定位置插入位
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 reverse_iterator rbegin() noexcept
获取反向起始迭代器
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 bool operator<(const bitmap &rhs) const noexcept(noexcept(_NEFORCE lexicographical_compare(this->cbegin(), this->cend(), rhs.cbegin(), rhs.cend())))
小于比较操作符
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 size_type capacity() const noexcept
获取容量(位数)
NEFORCE_CONSTEXPR20 bitmap(const int64_t word, const bool value)
64位整数构造函数
NEFORCE_CONSTEXPR20 void insert(const iterator &position, const bool *first, const bool *last)
插入布尔数组范围
NEFORCE_CONSTEXPR20 iterator erase(const iterator &position)
删除指定位置的位
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const_iterator cend() const noexcept
获取常量结束迭代器
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 iterator begin() noexcept
获取起始迭代器
size_t size_type
大小类型
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 iterator end() noexcept
获取结束迭代器
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 reference back()
访问最后一个位
NEFORCE_CONSTEXPR20 void swap(bitmap &other) noexcept
交换两个位图的内容
NEFORCE_CONSTEXPR20 bitmap(bitmap &&other) noexcept
移动构造函数
NEFORCE_CONSTEXPR20 void insert(const iterator &position, const size_type n, const bool value)
插入n个相同的位
NEFORCE_CONSTEXPR20 bitmap(const int32_t word, const bool value)
32位整数构造函数
NEFORCE_CONSTEXPR20 void pop_back()
删除末尾位
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const_reference back() const
常量版本,访问最后一个位
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const_reverse_iterator rbegin() const noexcept
获取常量反向起始迭代器
NEFORCE_CONSTEXPR20 void push_back(const bool value)
在末尾插入位
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const_iterator cbegin() const noexcept
获取常量起始迭代器
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const_reverse_iterator rend() const noexcept
获取常量反向结束迭代器
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const_iterator begin() const noexcept
获取常量起始迭代器
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 size_type size() const noexcept
获取位数
NEFORCE_CONSTEXPR20 bitmap(Iterator first, Iterator last)
范围构造函数
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 bool empty() const noexcept
检查是否为空
NEFORCE_NODISCARD constexpr T * addressof(T &x) noexcept
获取对象的地址
NEFORCE_ALWAYS_INLINE enable_if_t< is_void_v< T >, future_result_t< T > > get(future< T > &f)
通用future结果获取函数
NEFORCE_INLINE17 constexpr uint32_t BITMAP_WORD_SIZE
每个字的位数
NEFORCE_NODISCARD constexpr bool equal(Iterator1 first1, Iterator1 last1, Iterator2 first2, BinaryPredicate binary_pred) noexcept(noexcept(++first1) &&noexcept(++first2) &&noexcept(binary_pred(*first1, *first2)))
比较两个范围是否相等
NEFORCE_NODISCARD constexpr bool lexicographical_compare(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, Compare comp) noexcept(noexcept(++first1) &&noexcept(++first2) &&noexcept(comp(*first1, *first2)) &&noexcept(first1==last1 &&first2 !=last2))
字典序比较两个范围
unsigned int uint32_t
32位无符号整数类型
long long int64_t
64位有符号整数类型
int int32_t
32位有符号整数类型
#define NEFORCE_DEBUG_VERIFY(CON, MESG)
调试模式断言
constexpr iter_difference_t< Iterator > distance(Iterator first, Iterator last)
计算两个迭代器之间的距离
typename iterator_traits< Iterator >::difference_type iter_difference_t
获取迭代器的差值类型
standard_allocator< T > allocator
标准分配器别名
NEFORCE_ALLOC_OPTIMIZE NEFORCE_CONSTEXPR20 void * allocate(const inner::alloc_size_t bytes)
内存分配函数
uint64_t size_t
无符号大小类型
int64_t ptrdiff_t
指针差类型
constexpr void fill(Iterator first, Iterator last, const T &value) noexcept(is_nothrow_assignable_v< iter_value_t< Iterator >, T >)
填充范围元素
constexpr Iterator2 move(Iterator1 first, Iterator1 last, Iterator2 result) noexcept(noexcept(inner::__move_aux(first, last, result)))
移动范围元素
constexpr Iterator fill_n(Iterator first, iter_difference_t< Iterator > n, const T &value) noexcept(is_nothrow_assignable_v< iter_value_t< Iterator >, T >)
填充指定数量的元素
void swap()=delete
删除无参数的swap重载
typename conditional< Test, T1, T2 >::type conditional_t
conditional的便捷别名
typename enable_if< Test, T >::type enable_if_t
enable_if的便捷别名
迭代器接口
可字符串化接口
位引用类
NEFORCE_CONSTEXPR20 bit_reference & operator=(const bit_reference &other) noexcept
拷贝赋值运算符
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 bool operator<(const bit_reference &rhs) const noexcept
小于比较操作符
NEFORCE_CONSTEXPR20 bit_reference()=default
默认构造函数
NEFORCE_CONSTEXPR20 bit_reference(uint32_t *ptr, const uint32_t mask) noexcept
构造函数
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 size_t to_hash() const noexcept
计算哈希值
NEFORCE_CONSTEXPR20 bit_reference(bit_reference &&other) noexcept
移动构造函数
NEFORCE_CONSTEXPR20 bit_reference & operator=(bit_reference &&other) noexcept
移动赋值运算符
NEFORCE_CONSTEXPR20 bit_reference & operator=(const bool value) noexcept
赋值布尔值
NEFORCE_CONSTEXPR20 bit_reference(const bit_reference &other) noexcept
拷贝构造函数
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 string to_string() const
转换为字符串
NEFORCE_CONSTEXPR20 void swap(bit_reference &other) noexcept
交换两个位引用
NEFORCE_CONSTEXPR20 void flip() const noexcept
翻转位值
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 bool operator==(const bit_reference &rhs) const noexcept
相等比较操作符
位图迭代器
typename container_type::value_type value_type
值类型
BitMap container_type
容器类型
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 pointer base() const noexcept
获取底层指针
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 const container_type * container() const noexcept
获取关联容器
random_access_iterator_tag iterator_category
迭代器类别
NEFORCE_CONSTEXPR20 bitmap_iterator(const bitmap_iterator< IsConst2, BitMap > &other) noexcept
从另一个迭代器转换构造
conditional_t< IsConst, typename container_type::const_reference, typename container_type::reference > reference
引用类型
conditional_t< IsConst, typename container_type::const_pointer, typename container_type::pointer > pointer
指针类型
NEFORCE_CONSTEXPR20 void increment() noexcept
递增操作
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 reference dereference() const noexcept
解引用操作
NEFORCE_CONSTEXPR20 void decrement() noexcept
递减操作
NEFORCE_NODISCARD NEFORCE_CONSTEXPR20 difference_type distance_to(const bitmap_iterator &other) const noexcept
计算距离操作
typename container_type::size_type size_type
大小类型
NEFORCE_CONSTEXPR20 bool less_than(const bitmap_iterator &rhs) const noexcept
小于比较
NEFORCE_CONSTEXPR20 reference operator[](const difference_type n) const noexcept
下标访问操作符
NEFORCE_CONSTEXPR20 void advance(difference_type off) noexcept
前进操作
NEFORCE_CONSTEXPR20 bool equal(const bitmap_iterator &rhs) const noexcept
相等比较
typename container_type::difference_type difference_type
差值类型
压缩对主模板,使用EBCO优化
constexpr compressed_pair & get_base() noexcept
获取基类引用
默认构造标签
哈希函数的主模板
集合器接口模板
通用接口,同时具备可比较和可哈希功能
迭代器接口模板
可字符串化接口
随机访问迭代器标签