版本比较
兄妹(Ver. 2)
正文
增加 11 行删除 11 行
247 行未改动全部展开24824925025125225225325425525662 行未改动3193203213223233233243253263263273283283293303313323323333343353363373383393393403413423433 行未改动34734834935035135135235335435571 行未改动42742842943043143143243343443543643743843943944044144244344444544644644744844945017 行未改动468469470471472472473474475476135 行未改动全部展开247 行未改动全部展开 uint64_t to_ulong() const noexcept { return array_[0]; } constexpr Bitset(const uint64_t val) noexcept { if constexpr (Bsize_) { __builtin_memset(array_, 0, Bsize_ * sizeof(uint64_t)); array_[0] = val; array_[0] = val; if constexpr (Extrabits_ and Bsize_ == 1) array_[0] &= ~(-1ull << Extrabits_); } } explicit Bitset(const std :: string s, std :: size_t pos = 0, std :: size_t n = -1, char a = '0', char b = '1') noexcept {62 行未改动 res.assign(size_, a); for (uint64_t i = _Find_first(); i < size_; i = _Find_next(i)) res[size_ - i - 1] = b; return res; } constexpr Bitset & reset() noexcept { constexpr Bitset & reset() noexcept { if (__builtin_is_constant_evaluated()) { for (uint64_t& x : array_) x = 0; } else __builtin_memset(array_, 0, Bsize_ * sizeof(uint64_t)); return *this; return *this; } constexpr Bitset & set() noexcept { constexpr Bitset & set() noexcept { if (__builtin_is_constant_evaluated()) { for (uint64_t& x : array_) x = -1; } else __builtin_memset(array_, 255, Bsize_ * sizeof(uint64_t)); if constexpr (Bsize_ and Extrabits_) array_[Bsize_ - 1] = ~(-1ull << Extrabits_); return *this; return *this; } std :: size_t count() const noexcept { std :: size_t res = 0; for (uint64_t i = 0; i < Bsize_; i++) res += __builtin_popcountll(array_[i]); return res; } bool any() const noexcept { bool any() const noexcept { for (uint64_t i = 0; i < Bsize_; i++) { if (array_[i]) return 1; } return 0; } bool none() const noexcept { return !any(); }3 行未改动 if (array_[i] != -1ull) return 0; } return array_[Bsize_ - 1] == ~(-1ull << Extrabits_); } Bitset & set(const std :: size_t pos, const bool val = 1) noexcept { Bitset & set(const std :: size_t pos, const bool val = 1) noexcept { if (val) array_[pos >> 6] |= (1ull << (pos & 63)); else array_[pos >> 6] &= ~(1ull << (pos & 63)); return *this; }71 行未改动 } Bitset operator & (const Bitset& x) const noexcept { Bitset Tmp = *this; Tmp &= x; return Tmp; } Bitset operator | (const Bitset& x) const noexcept { Bitset Tmp = *this; Tmp |= x; return Tmp; } Bitset operator ^ (const Bitset& x) const noexcept { Bitset Tmp = *this; Tmp ^= x; return Tmp; } Bitset & operator <<= (std :: size_t siz_) noexcept { Bitset & operator <<= (std :: size_t siz_) noexcept { if (siz_ == 0) return *this; if (__builtin_expect(siz_ < size_, 1)) { const uint64_t tmp = siz_ >> 6; siz_ &= 63; if (__builtin_expect(siz_, 1)) { for (uint64_t i = Bsize_ - 1; i > tmp; i--) array_[i] = (array_[i - tmp] << siz_) | (array_[i - tmp - 1] >> (63 ^ (siz_ - 1))); array_[tmp] = array_[0] << siz_; } else { else { for (uint64_t i = Bsize_ - 1; i >= tmp; i--) array_[i] = array_[i - tmp]; } if constexpr (Extrabits_) array_[Bsize_ - 1] &= ~(-1ull << Extrabits_); std :: fill(array_, array_ + tmp, 0); } else __builtin_memset(array_, 0, Bsize_ * sizeof(uint64_t)); return *this; return *this; } Bitset operator << (const std :: size_t siz_) const noexcept { Bitset Tmp = *this; Tmp <<= siz_; return Tmp; } Bitset & operator >>= (std :: size_t siz_) noexcept { if (siz_ == 0) return *this;17 行未改动 bool operator [] (const std :: size_t pos) const noexcept { return (array_[pos >> 6] >> (pos & 63)) & 1; } reference operator [] (std :: size_t pos) noexcept { return reference(*this, pos); } friend std :: ostream& operator << (std :: ostream& os, const Bitset& x) { return os << x.to_string(); } friend std :: istream& operator >> (std :: istream& is, Bitset& x) { char ch; uint64_t p = 0, S = size_; char ch; uint64_t p = 0, S = size_; std :: string s; while (p < S) { if (p == 0) is >> ch; else ch = is.get();135 行未改动全部展开