Skip to content

Commit 88ae16b

Browse files
authored
Expose internal bytes of Symbol (#131)
1 parent e542ab7 commit 88ae16b

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ impl CompressorBuilder {
632632
let ignored_bits = entry.ignored_bits;
633633

634634
// If the entry is valid, return the code
635-
if !entry.is_unused() && compare_masked(word, entry.symbol.as_u64(), ignored_bits) {
635+
if !entry.is_unused() && compare_masked(word, entry.symbol.to_u64(), ignored_bits) {
636636
return entry.code;
637637
}
638638

src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ impl Symbol {
6565
if len == 0 { 1 } else { len }
6666
}
6767

68+
/// Returns the Symbol's inner representation.
6869
#[inline]
69-
fn as_u64(self) -> u64 {
70+
pub fn to_u64(self) -> u64 {
7071
self.0
7172
}
7273

@@ -303,7 +304,7 @@ impl<'a> Decompressor<'a> {
303304
($code:expr) => {{
304305
out_ptr
305306
.cast::<u64>()
306-
.write_unaligned(self.symbols.get_unchecked($code as usize).as_u64());
307+
.write_unaligned(self.symbols.get_unchecked($code as usize).to_u64());
307308
out_ptr = out_ptr.add(*self.lengths.get_unchecked($code as usize) as usize);
308309
}};
309310
}
@@ -588,7 +589,7 @@ impl Compressor {
588589
// Now, downshift the `word` and the `entry` to see if they align.
589590
let ignored_bits = entry.ignored_bits;
590591
if entry.code != Code::UNUSED
591-
&& compare_masked(word, entry.symbol.as_u64(), ignored_bits)
592+
&& compare_masked(word, entry.symbol.to_u64(), ignored_bits)
592593
{
593594
// Advance the input by the symbol length (variable) and the output by one code byte
594595
// SAFETY: out_ptr is not null.

src/lossy_pht.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl LossyPHT {
7979
///
8080
/// True if the symbol was inserted into the table, false if it was rejected due to collision.
8181
pub(crate) fn insert(&mut self, symbol: Symbol, len: usize, code: u8) -> bool {
82-
let prefix_3bytes = symbol.as_u64() & 0xFF_FF_FF;
82+
let prefix_3bytes = symbol.to_u64() & 0xFF_FF_FF;
8383
let slot = fsst_hash(prefix_3bytes) as usize & (HASH_TABLE_SIZE - 1);
8484
let entry = &mut self.slots[slot];
8585
if !entry.is_unused() {
@@ -106,7 +106,7 @@ impl LossyPHT {
106106

107107
/// Remove the symbol from the hashtable, if it exists.
108108
pub(crate) fn remove(&mut self, symbol: Symbol) {
109-
let prefix_3bytes = symbol.as_u64() & 0xFF_FF_FF;
109+
let prefix_3bytes = symbol.to_u64() & 0xFF_FF_FF;
110110
let slot = fsst_hash(prefix_3bytes) as usize & (HASH_TABLE_SIZE - 1);
111111
self.slots[slot].code = Code::UNUSED;
112112
}

0 commit comments

Comments
 (0)