Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions benches/fastpfor_benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use core::ops::Range;
use std::hint::black_box;
use std::io::Cursor;

use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use fastpfor::rust::{FastPFOR, Integer, BLOCK_SIZE_128, BLOCK_SIZE_256, DEFAULT_PAGE_SIZE};
use rand::rngs::StdRng;
use rand::{RngExt as _, SeedableRng};
use std::hint::black_box;
use std::io::Cursor;

const SIZES: &[usize; 2] = &[1024, 4096];
const SEED: u64 = 456;
Expand Down
13 changes: 8 additions & 5 deletions src/rust/integer_compression/fastpfor.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
use std::io::Cursor;
use std::num::NonZeroU32;

use crate::rust::cursor::IncrementCursor;
use crate::rust::integer_compression::{bitpacking, helpers};
use crate::rust::{bytebuffer, FastPForResult, Integer, Skippable};

/// Block size constant for 256 integers per block
pub const BLOCK_SIZE_256: u32 = 256;
pub const BLOCK_SIZE_256: NonZeroU32 = NonZeroU32::new(256).unwrap();

/// Block size constant for 128 integers per block
pub const BLOCK_SIZE_128: u32 = 128;
pub const BLOCK_SIZE_128: NonZeroU32 = NonZeroU32::new(128).unwrap();

/// Overhead cost (in bits) for storing each exception's position in the block
const OVERHEAD_OF_EACH_EXCEPT: u32 = 8;

/// Default page size in number of integers
pub const DEFAULT_PAGE_SIZE: u32 = 65536;
pub const DEFAULT_PAGE_SIZE: NonZeroU32 = NonZeroU32::new(65536).unwrap();
Comment thread
CommanderStorm marked this conversation as resolved.

/// Fast Patched Frame-of-Reference ([`FastPFOR`](https://github.com/lemire/FastPFor)) integer compression codec.
///
Expand Down Expand Up @@ -73,7 +74,7 @@ impl Skippable for FastPFOR {
output_offset: &mut Cursor<u32>,
num: u32,
) -> FastPForResult<()> {
if inlength == 0 && self.block_size == BLOCK_SIZE_128 {
if inlength == 0 && self.block_size == BLOCK_SIZE_128.get() {
// Return early if there is no data to uncompress and block size is 128
return Ok(());
}
Expand Down Expand Up @@ -142,7 +143,9 @@ impl FastPFOR {
/// Creates codec with specified page and block sizes.
///
/// Pre-allocates buffers for metadata and exception storage.
pub fn new(page_size: u32, block_size: u32) -> FastPFOR {
pub fn new(page_size: NonZeroU32, block_size: NonZeroU32) -> FastPFOR {
let page_size = page_size.get();
let block_size = block_size.get();
FastPFOR {
page_size,
block_size,
Expand Down
Loading