Skip to content

Commit

Permalink
fix: Allow BitSet size to be larger than int32 (#11986)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #11986

Reviewed By: darrenfu

Differential Revision: D67718846

fbshipit-source-id: 610a0198bde9e74e3cc80b297d653bd67dd5237e
  • Loading branch information
Yuhta authored and facebook-github-bot committed Dec 30, 2024
1 parent c44e45b commit dcccd90
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions velox/common/base/BitSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class BitSet {
bits::setBit(bits_.data(), bit, true);
}

bool contains(uint32_t index) const {
uint64_t bit = index - min_;
bool contains(int64_t index) const {
auto bit = index - min_;
if (bit >= bits_.size() * 64) {
// If index was < min_, bit will have wrapped around and will be >
// size * 64.
Expand Down
12 changes: 6 additions & 6 deletions velox/common/base/BitUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace velox {
namespace bits {

template <typename T>
inline bool isBitSet(const T* bits, int32_t idx) {
inline bool isBitSet(const T* bits, uint64_t idx) {
return bits[idx / (sizeof(bits[0]) * 8)] &
(static_cast<T>(1) << (idx & ((sizeof(bits[0]) * 8) - 1)));
}
Expand All @@ -76,19 +76,19 @@ static constexpr uint8_t kZeroBitmasks[] = {
};

template <typename T>
inline void setBit(T* bits, uint32_t idx) {
inline void setBit(T* bits, uint64_t idx) {
auto bitsAs8Bit = reinterpret_cast<uint8_t*>(bits);
bitsAs8Bit[idx / 8] |= (1 << (idx % 8));
}

template <typename T>
inline void clearBit(T* bits, uint32_t idx) {
inline void clearBit(T* bits, uint64_t idx) {
auto bitsAs8Bit = reinterpret_cast<uint8_t*>(bits);
bitsAs8Bit[idx / 8] &= kZeroBitmasks[idx % 8];
}

template <typename T>
inline void setBit(T* bits, uint32_t idx, bool value) {
inline void setBit(T* bits, uint64_t idx, bool value) {
value ? setBit(bits, idx) : clearBit(bits, idx);
}

Expand Down Expand Up @@ -124,11 +124,11 @@ constexpr inline uint64_t highMask(int32_t bits) {
return lowMask(bits) << (64 - bits);
}

constexpr inline uint64_t nbytes(int32_t bits) {
constexpr inline uint64_t nbytes(uint64_t bits) {
return roundUp(bits, 8) / 8;
}

constexpr inline uint64_t nwords(int32_t bits) {
constexpr inline uint64_t nwords(uint64_t bits) {
return roundUp(bits, 64) / 64;
}

Expand Down

0 comments on commit dcccd90

Please sign in to comment.