Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ proptest = "1.6.0"
serde = "1.0.217"
serde_json = "1.0.138"
zip = { version = "0.6", default-features = false }
allocative = { version = "0.3" }

[profile.test]
opt-level = 2
2 changes: 2 additions & 0 deletions roaring/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ license = "MIT OR Apache-2.0"
bytemuck = { workspace = true, optional = true }
byteorder = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
allocative = { workspace = true, optional = true }

[features]
default = ["std"]
serde = ["dep:serde", "std"]
simd = []
std = ["dep:bytemuck", "dep:byteorder"]
allocative = ["dep:allocative"]

[dev-dependencies]
proptest = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions roaring/src/bitmap/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub const RUN_MAX_SIZE: u64 = 2048;
use alloc::vec::Vec;

#[derive(PartialEq, Clone)]
#[cfg_attr(feature = "allocative", derive(allocative::Allocative))]
pub(crate) struct Container {
pub key: u16,
pub store: Store,
Expand Down
1 change: 1 addition & 0 deletions roaring/src/bitmap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use alloc::vec::Vec;
/// println!("total bits set to true: {}", rb.len());
/// ```
#[derive(PartialEq)]
#[cfg_attr(feature = "allocative", derive(allocative::Allocative))]
pub struct RoaringBitmap {
containers: Vec<container::Container>,
}
1 change: 1 addition & 0 deletions roaring/src/bitmap/store/array_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use super::Interval;
pub(crate) const ARRAY_ELEMENT_BYTES: usize = 2;

#[derive(Clone, Eq, PartialEq)]
#[cfg_attr(feature = "allocative", derive(allocative::Allocative))]
pub(crate) struct ArrayStore {
vec: Vec<u16>,
}
Expand Down
1 change: 1 addition & 0 deletions roaring/src/bitmap/store/bitmap_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub const BITMAP_LENGTH: usize = 1024;
pub const BITMAP_BYTES: usize = BITMAP_LENGTH * 8;

#[derive(Clone, Eq, PartialEq)]
#[cfg_attr(feature = "allocative", derive(allocative::Allocative))]
pub struct BitmapStore {
len: u64,
bits: Box<[u64; BITMAP_LENGTH]>,
Expand Down
2 changes: 2 additions & 0 deletions roaring/src/bitmap/store/interval_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use core::{cmp::Ordering, ops::ControlFlow};
use super::{ArrayStore, BitmapStore};

#[derive(PartialEq, Eq, Clone, Debug)]
#[cfg_attr(feature = "allocative", derive(allocative::Allocative))]
pub(crate) struct IntervalStore(Vec<Interval>);

pub(crate) const RUN_NUM_BYTES: usize = 2;
Expand Down Expand Up @@ -897,6 +898,7 @@ impl<I: SliceIterator<Interval>> ExactSizeIterator for RunIter<I> {}

/// This interval is inclusive to end.
#[derive(PartialEq, Eq, PartialOrd, Ord, Copy, Clone, Debug)]
#[cfg_attr(feature = "allocative", derive(allocative::Allocative))]
pub(crate) struct Interval {
start: u16,
end: u16,
Expand Down
1 change: 1 addition & 0 deletions roaring/src/bitmap/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::bitmap::container::ARRAY_LIMIT;
use alloc::boxed::Box;

#[derive(Clone)]
#[cfg_attr(feature = "allocative", derive(allocative::Allocative))]
pub(crate) enum Store {
Array(ArrayStore),
Bitmap(BitmapStore),
Expand Down
1 change: 1 addition & 0 deletions roaring/src/treemap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub use self::iter::{BitmapIter, IntoIter, Iter};
/// println!("total bits set to true: {}", rb.len());
/// ```
#[derive(PartialEq)]
#[cfg_attr(feature = "allocative", derive(allocative::Allocative))]
pub struct RoaringTreemap {
map: BTreeMap<u32, RoaringBitmap>,
}
50 changes: 50 additions & 0 deletions roaring/tests/allocative.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#![cfg(feature = "allocative")]

use std::fs::File;
use std::io::Write;

use allocative::FlameGraphBuilder;
use roaring::RoaringBitmap;
use roaring::RoaringTreemap;

#[test]
fn flamegraph_bitmap() {
let mut foo1 = RoaringBitmap::new();
foo1.insert_range(0..1_000_000);
foo1.insert(2_000_000);
foo1.insert(9_000_000);

let mut flamegraph = FlameGraphBuilder::default();
flamegraph.visit_root(&foo1);
let flamegraph_src = flamegraph.finish().flamegraph().write();
let mut f = File::create("../target/bitmap.folded").unwrap();
write!(f, "{}", flamegraph_src).unwrap();

/*
cargo test -p roaring --features allocative --test allocative
inferno-flamegraph target/bitmap.folded > target/bitmap.flamegraph.svg
open target/bitmap.flamegraph.svg
*/
}

#[test]
fn flamegraph_treemap() {
let mut foo1 = RoaringTreemap::new();
foo1.insert_range(0..1_000_000);
foo1.insert(2_000_000);
foo1.insert(9_000_000);
foo1.insert((1 << 32) + 9000);
foo1.insert((2 << 32) + 9000);

let mut flamegraph = FlameGraphBuilder::default();
flamegraph.visit_root(&foo1);
let flamegraph_src = flamegraph.finish().flamegraph().write();
let mut f = File::create("../target/treemap.folded").unwrap();
write!(f, "{}", flamegraph_src).unwrap();

/*
cargo test -p roaring --features allocative --test allocative
inferno-flamegraph target/treemap.folded > target/treemap.flamegraph.svg
open target/treemap.flamegraph.svg
*/
}