Skip to content

Commit

Permalink
Fixed bitpacking zero values (#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
norberttech authored Nov 5, 2023
1 parent e6077b3 commit 3fef49f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public function decodeBitPacked(BinaryReader $reader, int $bitWidth, int $varInt
return;
}

if ($bitWidth === 0) {
$output = \array_merge($output, \array_fill(0, \min($numGroups * 8, $maxItems), 0));

return;
}

$count = $numGroups * 8;
$totalByteCount = (int) (($bitWidth * $count) / 8);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ public function test_bit_packing_with_two_sequences() : void
);
}

public function test_bit_packing_zeroes() : void
{
$values = [0, 0, 0, 0];

$buffer = '';
(new RLEBitPackedHybrid())->encodeHybrid(new BinaryBufferWriter($buffer), $values);

$this->assertSame(
$values,
(new RLEBitPackedHybrid())->decodeHybrid(
new BinaryBufferReader($buffer),
BitWidth::fromArray($values),
\count($values)
)
);
}

public function test_bit_rle_reading_with_extra_bytes_in_the_buffer() : void
{
$values = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3];
Expand Down

0 comments on commit 3fef49f

Please sign in to comment.