Skip to content

Commit

Permalink
Decoder can take byte buffer instead of mmap + offset (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyb0807 authored Jan 2, 2025
1 parent f811b4c commit f919dde
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 10 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion rs/compression/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ anyhow.workspace = true
bitvec = "1"
env_logger.workspace = true
log.workspace = true
memmap2.workspace = true
tempdir.workspace = true
utils.workspace = true
3 changes: 1 addition & 2 deletions rs/compression/src/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::fs::File;
use std::io::BufWriter;

use anyhow::Result;
use memmap2::Mmap;

pub trait IntSeqEncoder {
/// Creates an encoder
Expand All @@ -23,7 +22,7 @@ pub trait IntSeqEncoder {

pub trait IntSeqDecoderIterator: Iterator {
/// Creates a decoder
fn new_decoder(mmap: &Mmap, offset: usize, size: usize) -> Self
fn new_decoder(encoded_data: &[u8]) -> Self
where
Self: Sized;

Expand Down
9 changes: 3 additions & 6 deletions rs/compression/src/noc/noc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use std::fs::File;
use std::io::{BufWriter, Write};

use anyhow::Result;
use memmap2::Mmap;
use utils::io::wrap_write;
use utils::mem::{get_ith_val_from_raw_ptr, transmute_u8_to_slice};
use utils::mem::get_ith_val_from_raw_ptr;

use crate::compression::{IntSeqDecoderIterator, IntSeqEncoder};

Expand Down Expand Up @@ -56,11 +55,9 @@ pub struct PlainDecoderIterator {
}

impl IntSeqDecoderIterator for PlainDecoderIterator {
fn new_decoder(mmap: &Mmap, offset: usize, size: usize) -> Self {
let slice = &mmap[offset..offset + size * size_of::<u64>()];
let encoded_data = transmute_u8_to_slice::<u64>(slice);
fn new_decoder(encoded_data: &[u8]) -> Self {
Self {
size,
size: encoded_data.len(),
cur_index: 0,
encoded_data_ptr: encoded_data.as_ptr() as *const u64,
}
Expand Down

0 comments on commit f919dde

Please sign in to comment.