Skip to content

Commit

Permalink
add signed bit when self.all_negative is true
Browse files Browse the repository at this point in the history
  • Loading branch information
thinh2 committed Sep 23, 2024
1 parent 214a8b7 commit a3df380
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions rust/lance-encoding/src/encodings/physical/bitpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,8 @@ impl PrimitivePageDecoder for BitpackedPageDecoder {
// the offset within the current destination byte to write to
let mut dst_offset = 0;

let is_negative = if self.all_negative {
true
} else {
is_encoded_item_negative(src, src_idx, src_offset, self.bits_per_value as usize)
};
let is_negative =
is_encoded_item_negative(src, src_idx, src_offset, self.bits_per_value as usize);

while src_bits_written < self.bits_per_value {
// write bits from current source byte into destination
Expand Down Expand Up @@ -456,7 +453,7 @@ impl PrimitivePageDecoder for BitpackedPageDecoder {

// if the type is signed, need to pad out the rest of the byte with 1s
let mut negative_padded_current_byte = false;
if self.signed && is_negative && dst_offset > 0 {
if ((self.signed && is_negative) || self.all_negative) && dst_offset > 0 {
negative_padded_current_byte = true;
while dst_offset < 8 {
dest[dst_idx] |= 1 << dst_offset;
Expand All @@ -481,7 +478,7 @@ impl PrimitivePageDecoder for BitpackedPageDecoder {
dst_idx + byte_len as usize - partial_bytes_written + to_next_byte;

// pad remaining bytes with 1 for negative signed numbers
if self.signed && is_negative {
if (self.signed && is_negative) || self.all_negative {
if !negative_padded_current_byte {
dest[dst_idx] = 0xFF;
}
Expand Down

0 comments on commit a3df380

Please sign in to comment.