| 33 | constexpr SelectionVector::Mode SelectionVector::kAllModes[kNumModes]; |
| 34 | |
| 35 | Status SelectionVector::PopulateFromBitMap(const uint8_t* bitmap, int64_t bitmap_size, |
| 36 | int64_t max_bitmap_index) { |
| 37 | const uint64_t max_idx = static_cast<uint64_t>(max_bitmap_index); |
| 38 | ARROW_RETURN_IF(bitmap_size % 8, Status::Invalid("Bitmap size ", bitmap_size, |
| 39 | " must be aligned to 64-bit size")); |
| 40 | ARROW_RETURN_IF(max_bitmap_index < 0, |
| 41 | Status::Invalid("Max bitmap index must be positive")); |
| 42 | ARROW_RETURN_IF( |
| 43 | max_idx > GetMaxSupportedValue(), |
| 44 | Status::Invalid("max_bitmap_index ", max_idx, " must be <= maxSupportedValue ", |
| 45 | GetMaxSupportedValue(), " in selection vector")); |
| 46 | |
| 47 | int64_t max_slots = GetMaxSlots(); |
| 48 | |
| 49 | // jump 8-bytes at a time, add the index corresponding to each valid bit to the |
| 50 | // the selection vector. |
| 51 | int64_t selection_idx = 0; |
| 52 | const uint64_t* bitmap_64 = reinterpret_cast<const uint64_t*>(bitmap); |
| 53 | for (int64_t bitmap_idx = 0; bitmap_idx < bitmap_size / 8; ++bitmap_idx) { |
| 54 | uint64_t current_word = arrow::bit_util::ToLittleEndian(bitmap_64[bitmap_idx]); |
| 55 | |
| 56 | while (current_word != 0) { |
| 57 | #if defined(_MSC_VER) |
| 58 | # pragma warning(push) |
| 59 | # pragma warning(disable : 4146) |
| 60 | #endif |
| 61 | // MSVC warns about negating an unsigned type. We suppress it for now |
| 62 | uint64_t highest_only = current_word & -current_word; |
| 63 | |
| 64 | #if defined(_MSC_VER) |
| 65 | # pragma warning(pop) |
| 66 | #endif |
| 67 | |
| 68 | int pos_in_word = std::countr_zero(highest_only); |
| 69 | |
| 70 | int64_t pos_in_bitmap = bitmap_idx * 64 + pos_in_word; |
| 71 | if (pos_in_bitmap > max_bitmap_index) { |
| 72 | // the bitmap may be slightly larger for alignment/padding. |
| 73 | break; |
| 74 | } |
| 75 | |
| 76 | ARROW_RETURN_IF(selection_idx >= max_slots, |
| 77 | Status::Invalid("selection vector has no remaining slots")); |
| 78 | |
| 79 | SetIndex(selection_idx, pos_in_bitmap); |
| 80 | ++selection_idx; |
| 81 | |
| 82 | current_word ^= highest_only; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | SetNumSlots(selection_idx); |
| 87 | return Status::OK(); |
| 88 | } |
| 89 | |
| 90 | Status SelectionVector::MakeInt16(int64_t max_slots, |
| 91 | std::shared_ptr<arrow::Buffer> buffer, |