From 79f43bca731711ee237be6da5f9888dc1d1fecf5 Mon Sep 17 00:00:00 2001 From: GZTime Date: Fri, 17 Nov 2023 03:07:26 +0800 Subject: [PATCH 1/7] feat: support `no_std` --- Cargo.toml | 4 +++- README.md | 2 +- benchmarks/benches/datasets.rs | 16 ++++++++-------- benchmarks/benches/lib.rs | 4 ++-- src/bitmap/arbitrary.rs | 10 ++++++---- src/bitmap/cmp.rs | 6 +++--- src/bitmap/container.rs | 6 ++++-- src/bitmap/fmt.rs | 4 +++- src/bitmap/inherent.rs | 6 ++++-- src/bitmap/iter.rs | 7 ++++--- src/bitmap/mod.rs | 3 +++ src/bitmap/multiops.rs | 5 +++-- src/bitmap/ops.rs | 8 +++++--- src/bitmap/serde.rs | 2 +- src/bitmap/serialization.rs | 4 ++-- src/bitmap/store/array_store/mod.rs | 20 ++++++++++++-------- src/bitmap/store/array_store/scalar.rs | 2 +- src/bitmap/store/array_store/vector.rs | 4 ++-- src/bitmap/store/array_store/visitor.rs | 2 ++ src/bitmap/store/bitmap_store.rs | 14 +++++++++----- src/bitmap/store/mod.rs | 7 ++++--- src/bitmap/util.rs | 4 ++-- src/lib.rs | 10 +++++++--- src/treemap/cmp.rs | 4 ++-- src/treemap/fmt.rs | 4 +++- src/treemap/inherent.rs | 7 ++++--- src/treemap/iter.rs | 11 +++++------ src/treemap/mod.rs | 3 ++- src/treemap/multiops.rs | 24 ++++++++++++------------ src/treemap/ops.rs | 7 ++++--- src/treemap/serde.rs | 2 +- src/treemap/util.rs | 2 +- tests/iter.rs | 2 +- tests/push.rs | 2 +- tests/serialization.rs | 22 +++++++++++++++++++++- tests/treemap_iter.rs | 2 +- tests/treemap_rank.rs | 2 +- tests/treemap_serialization.rs | 9 ++++++++- 38 files changed, 158 insertions(+), 95 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 90fa6a874..6acfbfaad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,11 +17,13 @@ license = "MIT OR Apache-2.0" [dependencies] bytemuck = "1.7.3" -byteorder = "1.4.3" +byteorder = { version = "1.4.3", default-features = false } serde = { version = "1.0.139", optional = true } [features] +default = ["std"] simd = [] +std = ["byteorder/std"] [dev-dependencies] proptest = "1.2.0" diff --git a/README.md b/README.md index 2d0c259aa..9a6a3112f 100644 --- a/README.md +++ b/README.md @@ -72,4 +72,4 @@ https://github.com/RoaringBitmap/roaring-rs/actions/workflows/test.yml/badge.svg ## Experimental features The `simd` feature is in active development. It has not been tested. If you would like to build with `simd` note that -`std::simd` is only available in Rust nightly. +`core::simd` is only available in Rust nightly. diff --git a/benchmarks/benches/datasets.rs b/benchmarks/benches/datasets.rs index afd2288e4..653bc574f 100644 --- a/benchmarks/benches/datasets.rs +++ b/benchmarks/benches/datasets.rs @@ -1,7 +1,7 @@ -use std::env; -use std::fs::File; -use std::io::BufReader; -use std::path::{Path, PathBuf}; +use core::env; +use core::fs::File; +use core::io::BufReader; +use core::path::{Path, PathBuf}; use git2::FetchOptions; use once_cell::sync::OnceCell as SyncOnceCell; @@ -13,7 +13,7 @@ static INSTANCE: SyncOnceCell> = SyncOnceCell::new(); pub struct Datasets; pub struct DatasetsIter { - iter: std::slice::Iter<'static, Dataset>, + iter: core::slice::Iter<'static, Dataset>, } impl Iterator for DatasetsIter { @@ -44,7 +44,7 @@ pub struct Dataset { pub bitmaps: Vec, } -fn init_datasets() -> Result> { +fn init_datasets() -> Result> { let out_dir = env::var_os("CARGO_MANIFEST_DIR").ok_or(env::VarError::NotPresent)?; let out_path = Path::new(&out_dir); @@ -122,7 +122,7 @@ fn init_datasets() -> Result> { Ok(repo_path) } -fn parse_datasets>(path: P) -> Result, Box> { +fn parse_datasets>(path: P) -> Result, Box> { const DATASET_FILENAME_WHITELIST: &[&str] = &[ "census-income.zip", "census-income_srt.zip", @@ -135,7 +135,7 @@ fn parse_datasets>(path: P) -> Result, Box) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { if self.len() < 16 { write!(f, "BitmapStore<{:?}>", self.iter().collect::>()) } else { @@ -82,7 +84,7 @@ mod test { } impl Debug for ArrayStore { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { if self.len() < 16 { write!(f, "ArrayStore<{:?}>", self.as_slice()) } else { @@ -151,7 +153,7 @@ mod test { } impl Debug for Store { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { match self { Store::Array(a) => write!(f, "Store({:?})", a), Store::Bitmap(b) => write!(f, "Store({:?})", b), diff --git a/src/bitmap/cmp.rs b/src/bitmap/cmp.rs index ad4a7d0a1..366ff0907 100644 --- a/src/bitmap/cmp.rs +++ b/src/bitmap/cmp.rs @@ -1,6 +1,6 @@ -use std::borrow::Borrow; -use std::cmp::Ordering; -use std::iter::Peekable; +use core::borrow::Borrow; +use core::cmp::Ordering; +use core::iter::Peekable; use super::container::Container; use crate::RoaringBitmap; diff --git a/src/bitmap/container.rs b/src/bitmap/container.rs index 773f90993..9116863a2 100644 --- a/src/bitmap/container.rs +++ b/src/bitmap/container.rs @@ -1,8 +1,10 @@ -use std::fmt; -use std::ops::{ +use core::fmt; +use core::ops::{ BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, RangeInclusive, Sub, SubAssign, }; +use alloc::vec::Vec; + use super::store::{self, Store}; use super::util; diff --git a/src/bitmap/fmt.rs b/src/bitmap/fmt.rs index 7dca81705..a3a6a95a3 100644 --- a/src/bitmap/fmt.rs +++ b/src/bitmap/fmt.rs @@ -1,4 +1,6 @@ -use std::fmt; +use core::fmt; + +use alloc::vec::Vec; use crate::RoaringBitmap; diff --git a/src/bitmap/inherent.rs b/src/bitmap/inherent.rs index 540ef0d3e..abb5acbbd 100644 --- a/src/bitmap/inherent.rs +++ b/src/bitmap/inherent.rs @@ -1,5 +1,7 @@ -use std::cmp::Ordering; -use std::ops::RangeBounds; +use core::cmp::Ordering; +use core::ops::RangeBounds; + +use alloc::vec::Vec; use crate::RoaringBitmap; diff --git a/src/bitmap/iter.rs b/src/bitmap/iter.rs index 35eddc820..65e8e36fe 100644 --- a/src/bitmap/iter.rs +++ b/src/bitmap/iter.rs @@ -1,5 +1,6 @@ -use std::iter::{self, FromIterator}; -use std::{slice, vec}; +use core::iter::{self, FromIterator}; +use core::slice; +use alloc::vec::{self, Vec}; use super::container::Container; use crate::{NonSortedIntegers, RoaringBitmap}; @@ -99,7 +100,7 @@ impl RoaringBitmap { /// /// ```rust /// use roaring::RoaringBitmap; - /// use std::iter::FromIterator; + /// use core::iter::FromIterator; /// /// let bitmap = (1..3).collect::(); /// let mut iter = bitmap.iter(); diff --git a/src/bitmap/mod.rs b/src/bitmap/mod.rs index 9b34bdcd3..b3bbd0808 100644 --- a/src/bitmap/mod.rs +++ b/src/bitmap/mod.rs @@ -14,8 +14,11 @@ mod iter; mod ops; #[cfg(feature = "serde")] mod serde; +#[cfg(feature = "std")] mod serialization; +use alloc::vec::Vec; + use self::cmp::Pairs; pub use self::iter::IntoIter; pub use self::iter::Iter; diff --git a/src/bitmap/multiops.rs b/src/bitmap/multiops.rs index 0fd9040a1..72435cc67 100644 --- a/src/bitmap/multiops.rs +++ b/src/bitmap/multiops.rs @@ -1,11 +1,12 @@ -use std::{ - borrow::Cow, +use core::{ cmp::Reverse, convert::Infallible, mem, ops::{BitOrAssign, BitXorAssign}, }; +use alloc::{vec::Vec, borrow::Cow}; + use crate::{MultiOps, RoaringBitmap}; use super::{container::Container, store::Store}; diff --git a/src/bitmap/ops.rs b/src/bitmap/ops.rs index 09c440dbf..f18b0681a 100644 --- a/src/bitmap/ops.rs +++ b/src/bitmap/ops.rs @@ -1,5 +1,7 @@ -use std::mem; -use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Sub, SubAssign}; +use core::mem; +use core::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Sub, SubAssign}; + +use alloc::vec::Vec; use crate::bitmap::container::Container; use crate::bitmap::Pairs; @@ -441,7 +443,7 @@ impl BitXorAssign<&RoaringBitmap> for RoaringBitmap { mod test { use crate::{MultiOps, RoaringBitmap}; use proptest::prelude::*; - use std::convert::Infallible; + use core::convert::Infallible; // fast count tests proptest! { diff --git a/src/bitmap/serde.rs b/src/bitmap/serde.rs index f2d1d5ba0..26c5d6ab6 100644 --- a/src/bitmap/serde.rs +++ b/src/bitmap/serde.rs @@ -16,7 +16,7 @@ impl<'de> Deserialize<'de> for RoaringBitmap { impl<'de> Visitor<'de> for BitmapVisitor { type Value = RoaringBitmap; - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + fn expecting(&self, formatter: &mut core::fmt::Formatter) -> core::fmt::Result { formatter.write_str("roaring bitmap") } diff --git a/src/bitmap/serialization.rs b/src/bitmap/serialization.rs index 6ae84df41..e1564e8c5 100644 --- a/src/bitmap/serialization.rs +++ b/src/bitmap/serialization.rs @@ -1,9 +1,9 @@ use bytemuck::cast_slice_mut; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; -use std::convert::{Infallible, TryFrom}; +use core::convert::{Infallible, TryFrom}; use std::error::Error; use std::io; -use std::ops::RangeInclusive; +use core::ops::RangeInclusive; use crate::bitmap::container::{Container, ARRAY_LIMIT}; use crate::bitmap::store::{ArrayStore, BitmapStore, Store, BITMAP_LENGTH}; diff --git a/src/bitmap/store/array_store/mod.rs b/src/bitmap/store/array_store/mod.rs index a121c1038..b08bc9b66 100644 --- a/src/bitmap/store/array_store/mod.rs +++ b/src/bitmap/store/array_store/mod.rs @@ -2,12 +2,15 @@ mod scalar; mod vector; mod visitor; +use alloc::boxed::Box; +use alloc::vec::Vec; + use crate::bitmap::store::array_store::visitor::{CardinalityCounter, VecWriter}; -use std::cmp::Ordering; -use std::cmp::Ordering::*; -use std::convert::{TryFrom, TryInto}; -use std::fmt::{Display, Formatter}; -use std::ops::{BitAnd, BitAndAssign, BitOr, BitXor, RangeInclusive, Sub, SubAssign}; +use core::cmp::Ordering; +use core::cmp::Ordering::*; +use core::convert::TryFrom; +use core::fmt::{Display, Formatter}; +use core::ops::{BitAnd, BitAndAssign, BitOr, BitXor, RangeInclusive, Sub, SubAssign}; use super::bitmap_store::{bit, key, BitmapStore, BITMAP_LENGTH}; @@ -214,11 +217,11 @@ impl ArrayStore { self.vec.get(n as usize).cloned() } - pub fn iter(&self) -> std::slice::Iter { + pub fn iter(&self) -> core::slice::Iter { self.vec.iter() } - pub fn into_iter(self) -> std::vec::IntoIter { + pub fn into_iter(self) -> alloc::vec::IntoIter { self.vec.into_iter() } @@ -263,7 +266,7 @@ pub enum ErrorKind { } impl Display for Error { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { match self.kind { ErrorKind::Duplicate => { write!(f, "Duplicate element found at index: {}", self.index) @@ -275,6 +278,7 @@ impl Display for Error { } } +#[cfg(feature = "std")] impl std::error::Error for Error {} impl TryFrom> for ArrayStore { diff --git a/src/bitmap/store/array_store/scalar.rs b/src/bitmap/store/array_store/scalar.rs index 455afdae6..d7b699c4e 100644 --- a/src/bitmap/store/array_store/scalar.rs +++ b/src/bitmap/store/array_store/scalar.rs @@ -1,7 +1,7 @@ //! Scalar arithmetic binary set operations on `ArrayStore`'s inner types use crate::bitmap::store::array_store::visitor::BinaryOperationVisitor; -use std::cmp::Ordering::*; +use core::cmp::Ordering::*; #[inline] pub fn or(lhs: &[u16], rhs: &[u16], visitor: &mut impl BinaryOperationVisitor) { diff --git a/src/bitmap/store/array_store/vector.rs b/src/bitmap/store/array_store/vector.rs index 14f3f0359..09e0e9234 100644 --- a/src/bitmap/store/array_store/vector.rs +++ b/src/bitmap/store/array_store/vector.rs @@ -390,7 +390,7 @@ where U: SimdElement + PartialOrd, LaneCount: SupportedLaneCount, { - unsafe { std::ptr::read_unaligned(src as *const _ as *const Simd) } + unsafe { core::ptr::read_unaligned(src as *const _ as *const Simd) } } /// write `v` to slice `out` @@ -416,7 +416,7 @@ where U: SimdElement + PartialOrd, LaneCount: SupportedLaneCount, { - unsafe { std::ptr::write_unaligned(out as *mut _ as *mut Simd, v) } + unsafe { core::ptr::write_unaligned(out as *mut _ as *mut Simd, v) } } /// Compare all lanes in `a` to all lanes in `b` diff --git a/src/bitmap/store/array_store/visitor.rs b/src/bitmap/store/array_store/visitor.rs index 5ee84b324..5b859b8b9 100644 --- a/src/bitmap/store/array_store/visitor.rs +++ b/src/bitmap/store/array_store/visitor.rs @@ -1,3 +1,5 @@ +use alloc::vec::Vec; + #[cfg(feature = "simd")] use crate::bitmap::store::array_store::vector::swizzle_to_front; diff --git a/src/bitmap/store/bitmap_store.rs b/src/bitmap/store/bitmap_store.rs index e1e332bd4..6a8c2b37f 100644 --- a/src/bitmap/store/bitmap_store.rs +++ b/src/bitmap/store/bitmap_store.rs @@ -1,7 +1,10 @@ -use std::borrow::Borrow; -use std::cmp::Ordering; -use std::fmt::{Display, Formatter}; -use std::ops::{BitAndAssign, BitOrAssign, BitXorAssign, RangeInclusive, SubAssign}; +use core::borrow::Borrow; +use core::cmp::Ordering; +use core::fmt::{Display, Formatter}; +use core::ops::{BitAndAssign, BitOrAssign, BitXorAssign, RangeInclusive, SubAssign}; + +use alloc::boxed::Box; +use alloc::vec::Vec; use super::ArrayStore; @@ -382,7 +385,7 @@ pub enum ErrorKind { } impl Display for Error { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { match self.kind { ErrorKind::Cardinality { expected, actual } => { write!(f, "Expected cardinality was {} but was {}", expected, actual) @@ -391,6 +394,7 @@ impl Display for Error { } } +#[cfg(feature = "std")] impl std::error::Error for Error {} pub struct BitmapIter> { diff --git a/src/bitmap/store/mod.rs b/src/bitmap/store/mod.rs index b3ff3e53b..059c8469b 100644 --- a/src/bitmap/store/mod.rs +++ b/src/bitmap/store/mod.rs @@ -1,11 +1,12 @@ mod array_store; mod bitmap_store; -use std::mem; -use std::ops::{ +use core::mem; +use core::ops::{ BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, RangeInclusive, Sub, SubAssign, }; -use std::{slice, vec}; +use core::slice; +use alloc::{vec, boxed::Box}; pub use self::bitmap_store::BITMAP_LENGTH; use self::Store::{Array, Bitmap}; diff --git a/src/bitmap/util.rs b/src/bitmap/util.rs index d6fc7db69..3565c34ad 100644 --- a/src/bitmap/util.rs +++ b/src/bitmap/util.rs @@ -1,4 +1,4 @@ -use std::ops::{Bound, RangeBounds, RangeInclusive}; +use core::ops::{Bound, RangeBounds, RangeInclusive}; /// Returns the container key and the index /// in this container for a given integer. @@ -38,7 +38,7 @@ where #[cfg(test)] mod test { use super::{convert_range_to_inclusive, join, split}; - use std::ops::Bound; + use core::ops::Bound; #[test] fn test_split_u32() { diff --git a/src/lib.rs b/src/lib.rs index e87e4fdda..111d6b227 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,7 @@ //! [roaring-java]: https://github.com/lemire/RoaringBitmap //! [roaring-paper]: https://arxiv.org/pdf/1402.6407v4 +#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(feature = "simd", feature(portable_simd))] #![warn(missing_docs)] #![warn(unsafe_op_in_unsafe_fn)] @@ -15,8 +16,10 @@ extern crate byteorder; -use std::error::Error; -use std::fmt; +#[macro_use] +extern crate alloc; + +use core::fmt; /// A compressed bitmap using the [Roaring bitmap compression scheme](https://roaringbitmap.org/). pub mod bitmap; @@ -46,7 +49,8 @@ impl fmt::Display for NonSortedIntegers { } } -impl Error for NonSortedIntegers {} +#[cfg(feature = "std")] +impl std::error::Error for NonSortedIntegers {} /// A [`Iterator::collect`] blanket implementation that provides extra methods for [`RoaringBitmap`] /// and [`RoaringTreemap`]. diff --git a/src/treemap/cmp.rs b/src/treemap/cmp.rs index c55fd228a..3334f8651 100644 --- a/src/treemap/cmp.rs +++ b/src/treemap/cmp.rs @@ -1,5 +1,5 @@ -use std::collections::btree_map; -use std::iter::Peekable; +use alloc::collections::btree_map; +use core::iter::Peekable; use crate::RoaringBitmap; use crate::RoaringTreemap; diff --git a/src/treemap/fmt.rs b/src/treemap/fmt.rs index 76f6e172c..86840116d 100644 --- a/src/treemap/fmt.rs +++ b/src/treemap/fmt.rs @@ -1,4 +1,6 @@ -use std::fmt; +use core::fmt; + +use alloc::vec::Vec; use crate::RoaringTreemap; diff --git a/src/treemap/inherent.rs b/src/treemap/inherent.rs index aad5f5643..e7bd1d066 100644 --- a/src/treemap/inherent.rs +++ b/src/treemap/inherent.rs @@ -1,6 +1,7 @@ -use std::collections::btree_map::{BTreeMap, Entry}; -use std::iter; -use std::ops::RangeBounds; +use alloc::collections::btree_map::{BTreeMap, Entry}; +use alloc::vec::Vec; +use core::iter; +use core::ops::RangeBounds; use crate::RoaringBitmap; use crate::RoaringTreemap; diff --git a/src/treemap/iter.rs b/src/treemap/iter.rs index 285a0c5ce..a5239bc53 100644 --- a/src/treemap/iter.rs +++ b/src/treemap/iter.rs @@ -1,6 +1,5 @@ -use std::collections::btree_map; -use std::collections::BTreeMap; -use std::iter::{self, FromIterator}; +use alloc::collections::{btree_map, BTreeMap}; +use core::iter::{self, FromIterator}; use super::util; use crate::bitmap::IntoIter as IntoIter32; @@ -160,7 +159,7 @@ impl RoaringTreemap { /// /// ```rust /// use roaring::RoaringTreemap; - /// use std::iter::FromIterator; + /// use core::iter::FromIterator; /// /// let bitmap = (1..3).collect::(); /// let mut iter = bitmap.iter(); @@ -180,7 +179,7 @@ impl RoaringTreemap { /// /// ```rust /// use roaring::{RoaringBitmap, RoaringTreemap}; - /// use std::iter::FromIterator; + /// use core::iter::FromIterator; /// /// let original = (0..6000).collect::(); /// let mut bitmaps = original.bitmaps(); @@ -200,7 +199,7 @@ impl RoaringTreemap { /// /// ```rust /// use roaring::RoaringTreemap; - /// use std::iter::FromIterator; + /// use core::iter::FromIterator; /// /// let original = (0..6000).collect::(); /// let clone = RoaringTreemap::from_bitmaps(original.bitmaps().map(|(p, b)| (p, b.clone()))); diff --git a/src/treemap/mod.rs b/src/treemap/mod.rs index 036b961a7..45eea164b 100644 --- a/src/treemap/mod.rs +++ b/src/treemap/mod.rs @@ -1,5 +1,5 @@ use crate::RoaringBitmap; -use std::collections::BTreeMap; +use alloc::collections::BTreeMap; mod fmt; mod multiops; @@ -14,6 +14,7 @@ mod iter; mod ops; #[cfg(feature = "serde")] mod serde; +#[cfg(feature = "std")] mod serialization; pub use self::iter::{IntoIter, Iter}; diff --git a/src/treemap/multiops.rs b/src/treemap/multiops.rs index 4ad2a8e21..f3edab785 100644 --- a/src/treemap/multiops.rs +++ b/src/treemap/multiops.rs @@ -1,9 +1,9 @@ -use std::{ +use core::{ borrow::Borrow, cmp::Ordering, - collections::{binary_heap::PeekMut, BTreeMap, BinaryHeap}, mem, }; +use alloc::{collections::{binary_heap::PeekMut, BTreeMap, BinaryHeap}, vec::Vec}; use crate::{MultiOps, RoaringBitmap, RoaringTreemap}; @@ -15,28 +15,28 @@ where fn union(self) -> Self::Output { try_simple_multi_op_owned::<_, _, UnionOp>( - self.into_iter().map(Ok::<_, std::convert::Infallible>), + self.into_iter().map(Ok::<_, core::convert::Infallible>), ) .unwrap() } fn intersection(self) -> Self::Output { try_ordered_multi_op_owned::<_, _, IntersectionOp>( - self.into_iter().map(Ok::<_, std::convert::Infallible>), + self.into_iter().map(Ok::<_, core::convert::Infallible>), ) .unwrap() } fn difference(self) -> Self::Output { try_ordered_multi_op_owned::<_, _, DifferenceOp>( - self.into_iter().map(Ok::<_, std::convert::Infallible>), + self.into_iter().map(Ok::<_, core::convert::Infallible>), ) .unwrap() } fn symmetric_difference(self) -> Self::Output { try_simple_multi_op_owned::<_, _, SymmetricDifferenceOp>( - self.into_iter().map(Ok::<_, std::convert::Infallible>), + self.into_iter().map(Ok::<_, core::convert::Infallible>), ) .unwrap() } @@ -140,7 +140,7 @@ where // the unwrap is safe since we're iterating on our keys let current_bitmap = treemap.map.remove(&k).unwrap(); let new_bitmap = - O::op_owned(std::iter::once(current_bitmap).chain( + O::op_owned(core::iter::once(current_bitmap).chain( treemaps.iter_mut().map(|treemap| treemap.map.remove(&k).unwrap_or_default()), )); if !new_bitmap.is_empty() { @@ -172,7 +172,7 @@ where // the unwrap is safe since we're iterating on our keys let current_bitmap = treemap.map.get(&k).unwrap(); let new_bitmap = O::op_ref( - std::iter::once(current_bitmap) + core::iter::once(current_bitmap) .chain(treemaps.iter().map(|treemap| treemap.map.get(&k).unwrap_or(&empty_bitmap))), ); if !new_bitmap.is_empty() { @@ -300,28 +300,28 @@ where fn union(self) -> Self::Output { try_simple_multi_op_ref::<_, _, UnionOp>( - self.into_iter().map(Ok::<_, std::convert::Infallible>), + self.into_iter().map(Ok::<_, core::convert::Infallible>), ) .unwrap() } fn intersection(self) -> Self::Output { try_ordered_multi_op_ref::<_, _, IntersectionOp>( - self.into_iter().map(Ok::<_, std::convert::Infallible>), + self.into_iter().map(Ok::<_, core::convert::Infallible>), ) .unwrap() } fn difference(self) -> Self::Output { try_ordered_multi_op_ref::<_, _, DifferenceOp>( - self.into_iter().map(Ok::<_, std::convert::Infallible>), + self.into_iter().map(Ok::<_, core::convert::Infallible>), ) .unwrap() } fn symmetric_difference(self) -> Self::Output { try_simple_multi_op_ref::<_, _, SymmetricDifferenceOp>( - self.into_iter().map(Ok::<_, std::convert::Infallible>), + self.into_iter().map(Ok::<_, core::convert::Infallible>), ) .unwrap() } diff --git a/src/treemap/ops.rs b/src/treemap/ops.rs index 5961c7cf1..17e1b4a8a 100644 --- a/src/treemap/ops.rs +++ b/src/treemap/ops.rs @@ -1,6 +1,7 @@ -use std::collections::btree_map::Entry; -use std::mem; -use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Sub, SubAssign}; +use alloc::collections::btree_map::Entry; +use alloc::vec::Vec; +use core::mem; +use core::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Sub, SubAssign}; use crate::RoaringTreemap; diff --git a/src/treemap/serde.rs b/src/treemap/serde.rs index 67665779f..46e7c2aa1 100644 --- a/src/treemap/serde.rs +++ b/src/treemap/serde.rs @@ -16,7 +16,7 @@ impl<'de> Deserialize<'de> for RoaringTreemap { impl<'de> Visitor<'de> for TreemapVisitor { type Value = RoaringTreemap; - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + fn expecting(&self, formatter: &mut core::fmt::Formatter) -> core::fmt::Result { formatter.write_str("roaring bitmap") } diff --git a/src/treemap/util.rs b/src/treemap/util.rs index 88c8ccaef..55839c644 100644 --- a/src/treemap/util.rs +++ b/src/treemap/util.rs @@ -1,4 +1,4 @@ -use std::ops::{Bound, RangeBounds, RangeInclusive}; +use core::ops::{Bound, RangeBounds, RangeInclusive}; #[inline] pub fn split(value: u64) -> (u32, u32) { diff --git a/tests/iter.rs b/tests/iter.rs index 14746ea9b..b867f60d8 100644 --- a/tests/iter.rs +++ b/tests/iter.rs @@ -1,7 +1,7 @@ use proptest::arbitrary::any; use proptest::collection::btree_set; use proptest::proptest; -use std::iter::FromIterator; +use core::iter::FromIterator; use roaring::RoaringBitmap; diff --git a/tests/push.rs b/tests/push.rs index e617c493e..ab1993dcc 100644 --- a/tests/push.rs +++ b/tests/push.rs @@ -1,6 +1,6 @@ extern crate roaring; use roaring::{RoaringBitmap, RoaringTreemap}; -use std::iter::FromIterator; +use core::iter::FromIterator; /// macro created to reduce code duplication macro_rules! test_from_sorted_iter { diff --git a/tests/serialization.rs b/tests/serialization.rs index 42efdd439..4aa74db4a 100644 --- a/tests/serialization.rs +++ b/tests/serialization.rs @@ -1,11 +1,15 @@ extern crate roaring; +#[cfg(feature = "std")] use roaring::RoaringBitmap; // Test data from https://github.com/RoaringBitmap/RoaringFormatSpec/tree/master/testdata +#[cfg(feature = "std")] static BITMAP_WITHOUT_RUNS: &[u8] = include_bytes!("bitmapwithoutruns.bin"); +#[cfg(feature = "std")] static BITMAP_WITH_RUNS: &[u8] = include_bytes!("bitmapwithruns.bin"); +#[cfg(feature = "std")] fn test_data_bitmap() -> RoaringBitmap { (0..100) .map(|i| i * 1000) @@ -14,6 +18,7 @@ fn test_data_bitmap() -> RoaringBitmap { .collect::() } +#[cfg(feature = "std")] fn serialize_and_deserialize(bitmap: &RoaringBitmap) -> RoaringBitmap { let mut buffer = vec![]; bitmap.serialize_into(&mut buffer).unwrap(); @@ -22,11 +27,13 @@ fn serialize_and_deserialize(bitmap: &RoaringBitmap) -> RoaringBitmap { } #[test] +#[cfg(feature = "std")] fn test_deserialize_without_runs_from_provided_data() { assert_eq!(RoaringBitmap::deserialize_from(BITMAP_WITHOUT_RUNS).unwrap(), test_data_bitmap()); } #[test] +#[cfg(feature = "std")] fn test_deserialize_with_runs_from_provided_data() { assert_eq!( RoaringBitmap::deserialize_from(&mut &BITMAP_WITH_RUNS[..]).unwrap(), @@ -35,6 +42,7 @@ fn test_deserialize_with_runs_from_provided_data() { } #[test] +#[cfg(feature = "std")] fn test_serialize_into_provided_data() { let bitmap = test_data_bitmap(); let mut buffer = vec![]; @@ -43,6 +51,7 @@ fn test_serialize_into_provided_data() { } #[test] +#[cfg(feature = "std")] fn test_empty() { let original = RoaringBitmap::new(); let new = serialize_and_deserialize(&original); @@ -50,6 +59,7 @@ fn test_empty() { } #[test] +#[cfg(feature = "std")] fn test_one() { let original = (1..2).collect::(); let new = serialize_and_deserialize(&original); @@ -57,6 +67,7 @@ fn test_one() { } #[test] +#[cfg(feature = "std")] fn test_array() { let original = (1000..3000).collect::(); let new = serialize_and_deserialize(&original); @@ -64,6 +75,7 @@ fn test_array() { } #[test] +#[cfg(feature = "std")] fn test_array_boundary() { let original = (1000..5096).collect::(); let new = serialize_and_deserialize(&original); @@ -71,13 +83,16 @@ fn test_array_boundary() { } #[test] +#[cfg(feature = "std")] fn test_bitmap_boundary() { - let original = (1000..5097).collect::(); +#[cfg(feature = "std")] +let original = (1000..5097).collect::(); let new = serialize_and_deserialize(&original); assert_eq!(original, new); } #[test] +#[cfg(feature = "std")] fn test_bitmap_high16bits() { let mut bitmap = RoaringBitmap::new(); for i in 0..1 << 16 { @@ -94,6 +109,7 @@ fn test_bitmap_high16bits() { } #[test] +#[cfg(feature = "std")] fn test_bitmap() { let original = (1000..6000).collect::(); let new = serialize_and_deserialize(&original); @@ -101,6 +117,7 @@ fn test_bitmap() { } #[test] +#[cfg(feature = "std")] fn test_arrays() { let original = (1000..3000).chain(70000..74000).collect::(); let new = serialize_and_deserialize(&original); @@ -108,6 +125,7 @@ fn test_arrays() { } #[test] +#[cfg(feature = "std")] fn test_bitmaps() { let original = (1000..6000).chain(70000..77000).collect::(); let new = serialize_and_deserialize(&original); @@ -115,6 +133,7 @@ fn test_bitmaps() { } #[test] +#[cfg(feature = "std")] fn test_mixed() { let original = (1000..3000).chain(70000..77000).collect::(); let new = serialize_and_deserialize(&original); @@ -122,6 +141,7 @@ fn test_mixed() { } #[test] +#[cfg(feature = "std")] fn test_strange() { const ARRAY: &[u32] = &[ 6619162, 6619180, 6619181, 6619217, 6619218, 6619257, 6619258, 6619259, 6619260, 6619261, diff --git a/tests/treemap_iter.rs b/tests/treemap_iter.rs index ddde2efc3..5c24d61e0 100644 --- a/tests/treemap_iter.rs +++ b/tests/treemap_iter.rs @@ -6,7 +6,7 @@ use iter::outside_in; use proptest::arbitrary::any; use proptest::collection::btree_set; use proptest::proptest; -use std::iter::FromIterator; +use core::iter::FromIterator; #[test] fn range() { diff --git a/tests/treemap_rank.rs b/tests/treemap_rank.rs index c05b4e6ea..aebfbb1ef 100644 --- a/tests/treemap_rank.rs +++ b/tests/treemap_rank.rs @@ -3,7 +3,7 @@ extern crate roaring; use proptest::collection::{btree_set, vec}; use proptest::prelude::*; use roaring::RoaringTreemap; -use std::ops::RangeInclusive; +use core::ops::RangeInclusive; const BITMAP_MAX: u64 = u32::MAX as u64; diff --git a/tests/treemap_serialization.rs b/tests/treemap_serialization.rs index bf38bb3d6..5be715079 100644 --- a/tests/treemap_serialization.rs +++ b/tests/treemap_serialization.rs @@ -1,6 +1,9 @@ +#[cfg(feature = "std")] use roaring::RoaringTreemap; -use std::iter::FromIterator; +#[cfg(feature = "std")] +use core::iter::FromIterator; +#[cfg(feature = "std")] fn serialize_deserialize(dataset: Dataset) where Dataset: IntoIterator, @@ -19,21 +22,25 @@ where } #[test] +#[cfg(feature = "std")] fn empty() { serialize_deserialize(vec![]) } #[test] +#[cfg(feature = "std")] fn basic() { serialize_deserialize(vec![1, 2, 3, 4, 5, 100, 1000]) } #[test] +#[cfg(feature = "std")] fn basic_2() { serialize_deserialize(vec![1, 2, 3, 4, 5, 100, 1000, 10000, 100000, 1000000]) } #[test] +#[cfg(feature = "std")] fn basic_3() { let u32max = u32::MAX as u64; serialize_deserialize( From a8dc5f45ee4c837a3fa68f1909d9b8bc453107a2 Mon Sep 17 00:00:00 2001 From: GZTime Date: Fri, 17 Nov 2023 03:08:30 +0800 Subject: [PATCH 2/7] chore: cargo fmt --- src/bitmap/arbitrary.rs | 2 +- src/bitmap/iter.rs | 2 +- src/bitmap/multiops.rs | 2 +- src/bitmap/ops.rs | 2 +- src/bitmap/serialization.rs | 2 +- src/bitmap/store/mod.rs | 2 +- src/treemap/multiops.rs | 9 ++++----- tests/iter.rs | 2 +- tests/push.rs | 2 +- tests/serialization.rs | 4 ++-- tests/treemap_iter.rs | 2 +- tests/treemap_rank.rs | 2 +- tests/treemap_serialization.rs | 4 ++-- 13 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/bitmap/arbitrary.rs b/src/bitmap/arbitrary.rs index 80ff319e7..de4c4d273 100644 --- a/src/bitmap/arbitrary.rs +++ b/src/bitmap/arbitrary.rs @@ -5,10 +5,10 @@ mod test { use crate::RoaringBitmap; use alloc::boxed::Box; use alloc::vec::Vec; + use core::fmt::{Debug, Formatter}; use proptest::bits::{BitSetLike, BitSetStrategy, SampledBitSetStrategy}; use proptest::collection::{vec, SizeRange}; use proptest::prelude::*; - use core::fmt::{Debug, Formatter}; impl Debug for BitmapStore { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { diff --git a/src/bitmap/iter.rs b/src/bitmap/iter.rs index 65e8e36fe..541c49edd 100644 --- a/src/bitmap/iter.rs +++ b/src/bitmap/iter.rs @@ -1,6 +1,6 @@ +use alloc::vec::{self, Vec}; use core::iter::{self, FromIterator}; use core::slice; -use alloc::vec::{self, Vec}; use super::container::Container; use crate::{NonSortedIntegers, RoaringBitmap}; diff --git a/src/bitmap/multiops.rs b/src/bitmap/multiops.rs index 72435cc67..fd8f52821 100644 --- a/src/bitmap/multiops.rs +++ b/src/bitmap/multiops.rs @@ -5,7 +5,7 @@ use core::{ ops::{BitOrAssign, BitXorAssign}, }; -use alloc::{vec::Vec, borrow::Cow}; +use alloc::{borrow::Cow, vec::Vec}; use crate::{MultiOps, RoaringBitmap}; diff --git a/src/bitmap/ops.rs b/src/bitmap/ops.rs index f18b0681a..bfdd0ce3e 100644 --- a/src/bitmap/ops.rs +++ b/src/bitmap/ops.rs @@ -442,8 +442,8 @@ impl BitXorAssign<&RoaringBitmap> for RoaringBitmap { #[cfg(test)] mod test { use crate::{MultiOps, RoaringBitmap}; - use proptest::prelude::*; use core::convert::Infallible; + use proptest::prelude::*; // fast count tests proptest! { diff --git a/src/bitmap/serialization.rs b/src/bitmap/serialization.rs index e1564e8c5..f60bbad18 100644 --- a/src/bitmap/serialization.rs +++ b/src/bitmap/serialization.rs @@ -1,9 +1,9 @@ use bytemuck::cast_slice_mut; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use core::convert::{Infallible, TryFrom}; +use core::ops::RangeInclusive; use std::error::Error; use std::io; -use core::ops::RangeInclusive; use crate::bitmap::container::{Container, ARRAY_LIMIT}; use crate::bitmap::store::{ArrayStore, BitmapStore, Store, BITMAP_LENGTH}; diff --git a/src/bitmap/store/mod.rs b/src/bitmap/store/mod.rs index 059c8469b..c80b2078b 100644 --- a/src/bitmap/store/mod.rs +++ b/src/bitmap/store/mod.rs @@ -1,12 +1,12 @@ mod array_store; mod bitmap_store; +use alloc::{boxed::Box, vec}; use core::mem; use core::ops::{ BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, RangeInclusive, Sub, SubAssign, }; use core::slice; -use alloc::{vec, boxed::Box}; pub use self::bitmap_store::BITMAP_LENGTH; use self::Store::{Array, Bitmap}; diff --git a/src/treemap/multiops.rs b/src/treemap/multiops.rs index f3edab785..f43bdf710 100644 --- a/src/treemap/multiops.rs +++ b/src/treemap/multiops.rs @@ -1,9 +1,8 @@ -use core::{ - borrow::Borrow, - cmp::Ordering, - mem, +use alloc::{ + collections::{binary_heap::PeekMut, BTreeMap, BinaryHeap}, + vec::Vec, }; -use alloc::{collections::{binary_heap::PeekMut, BTreeMap, BinaryHeap}, vec::Vec}; +use core::{borrow::Borrow, cmp::Ordering, mem}; use crate::{MultiOps, RoaringBitmap, RoaringTreemap}; diff --git a/tests/iter.rs b/tests/iter.rs index b867f60d8..bbffedc95 100644 --- a/tests/iter.rs +++ b/tests/iter.rs @@ -1,7 +1,7 @@ +use core::iter::FromIterator; use proptest::arbitrary::any; use proptest::collection::btree_set; use proptest::proptest; -use core::iter::FromIterator; use roaring::RoaringBitmap; diff --git a/tests/push.rs b/tests/push.rs index ab1993dcc..0919d39ad 100644 --- a/tests/push.rs +++ b/tests/push.rs @@ -1,6 +1,6 @@ extern crate roaring; -use roaring::{RoaringBitmap, RoaringTreemap}; use core::iter::FromIterator; +use roaring::{RoaringBitmap, RoaringTreemap}; /// macro created to reduce code duplication macro_rules! test_from_sorted_iter { diff --git a/tests/serialization.rs b/tests/serialization.rs index 4aa74db4a..ea83440b8 100644 --- a/tests/serialization.rs +++ b/tests/serialization.rs @@ -85,8 +85,8 @@ fn test_array_boundary() { #[test] #[cfg(feature = "std")] fn test_bitmap_boundary() { -#[cfg(feature = "std")] -let original = (1000..5097).collect::(); + #[cfg(feature = "std")] + let original = (1000..5097).collect::(); let new = serialize_and_deserialize(&original); assert_eq!(original, new); } diff --git a/tests/treemap_iter.rs b/tests/treemap_iter.rs index 5c24d61e0..bdb53636e 100644 --- a/tests/treemap_iter.rs +++ b/tests/treemap_iter.rs @@ -2,11 +2,11 @@ extern crate roaring; mod iter; use roaring::RoaringTreemap; +use core::iter::FromIterator; use iter::outside_in; use proptest::arbitrary::any; use proptest::collection::btree_set; use proptest::proptest; -use core::iter::FromIterator; #[test] fn range() { diff --git a/tests/treemap_rank.rs b/tests/treemap_rank.rs index aebfbb1ef..e9c742193 100644 --- a/tests/treemap_rank.rs +++ b/tests/treemap_rank.rs @@ -1,9 +1,9 @@ extern crate roaring; +use core::ops::RangeInclusive; use proptest::collection::{btree_set, vec}; use proptest::prelude::*; use roaring::RoaringTreemap; -use core::ops::RangeInclusive; const BITMAP_MAX: u64 = u32::MAX as u64; diff --git a/tests/treemap_serialization.rs b/tests/treemap_serialization.rs index 5be715079..991b6713c 100644 --- a/tests/treemap_serialization.rs +++ b/tests/treemap_serialization.rs @@ -1,7 +1,7 @@ #[cfg(feature = "std")] -use roaring::RoaringTreemap; -#[cfg(feature = "std")] use core::iter::FromIterator; +#[cfg(feature = "std")] +use roaring::RoaringTreemap; #[cfg(feature = "std")] fn serialize_deserialize(dataset: Dataset) From 5ace732cae2f3b303b75ed003bc360fea4d2036b Mon Sep 17 00:00:00 2001 From: GZTime Date: Fri, 17 Nov 2023 04:38:11 +0800 Subject: [PATCH 3/7] docs: revert unexpected change --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a6a3112f..2d0c259aa 100644 --- a/README.md +++ b/README.md @@ -72,4 +72,4 @@ https://github.com/RoaringBitmap/roaring-rs/actions/workflows/test.yml/badge.svg ## Experimental features The `simd` feature is in active development. It has not been tested. If you would like to build with `simd` note that -`core::simd` is only available in Rust nightly. +`std::simd` is only available in Rust nightly. From 0f10931f00f73ef60ae9dd7030ad7af8fdfad379 Mon Sep 17 00:00:00 2001 From: GZTime Date: Fri, 17 Nov 2023 04:44:03 +0800 Subject: [PATCH 4/7] fix(bench): revert unexpected change --- benchmarks/benches/datasets.rs | 16 ++++++++-------- benchmarks/benches/lib.rs | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/benchmarks/benches/datasets.rs b/benchmarks/benches/datasets.rs index 653bc574f..afd2288e4 100644 --- a/benchmarks/benches/datasets.rs +++ b/benchmarks/benches/datasets.rs @@ -1,7 +1,7 @@ -use core::env; -use core::fs::File; -use core::io::BufReader; -use core::path::{Path, PathBuf}; +use std::env; +use std::fs::File; +use std::io::BufReader; +use std::path::{Path, PathBuf}; use git2::FetchOptions; use once_cell::sync::OnceCell as SyncOnceCell; @@ -13,7 +13,7 @@ static INSTANCE: SyncOnceCell> = SyncOnceCell::new(); pub struct Datasets; pub struct DatasetsIter { - iter: core::slice::Iter<'static, Dataset>, + iter: std::slice::Iter<'static, Dataset>, } impl Iterator for DatasetsIter { @@ -44,7 +44,7 @@ pub struct Dataset { pub bitmaps: Vec, } -fn init_datasets() -> Result> { +fn init_datasets() -> Result> { let out_dir = env::var_os("CARGO_MANIFEST_DIR").ok_or(env::VarError::NotPresent)?; let out_path = Path::new(&out_dir); @@ -122,7 +122,7 @@ fn init_datasets() -> Result> { Ok(repo_path) } -fn parse_datasets>(path: P) -> Result, Box> { +fn parse_datasets>(path: P) -> Result, Box> { const DATASET_FILENAME_WHITELIST: &[&str] = &[ "census-income.zip", "census-income_srt.zip", @@ -135,7 +135,7 @@ fn parse_datasets>(path: P) -> Result, Box Date: Sun, 21 Jan 2024 00:01:37 +0800 Subject: [PATCH 5/7] wip: use `#![cfg(...)]` instead of `#[cfg(...)]` --- Cargo.toml | 15 ++++++++------- tests/serialization.rs | 22 ++-------------------- tests/treemap_serialization.rs | 9 ++------- 3 files changed, 12 insertions(+), 34 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6acfbfaad..74a3fb3d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,19 +16,20 @@ edition = "2021" license = "MIT OR Apache-2.0" [dependencies] -bytemuck = "1.7.3" -byteorder = { version = "1.4.3", default-features = false } -serde = { version = "1.0.139", optional = true } +bytemuck = { version = "1.7", optional = true } +byteorder = { version = "1.4", optional = true } +serde = { version = "1.0", optional = true } [features] default = ["std"] +serde = ["dep:serde", "std"] simd = [] -std = ["byteorder/std"] +std = ["dep:bytemuck", "dep:byteorder"] [dev-dependencies] -proptest = "1.2.0" -serde_json = "1.0.85" -bincode = "1.3.3" +proptest = "1.2" +serde_json = "1.0" +bincode = "1.3" [profile.test] opt-level = 2 diff --git a/tests/serialization.rs b/tests/serialization.rs index ea83440b8..78325017c 100644 --- a/tests/serialization.rs +++ b/tests/serialization.rs @@ -1,15 +1,13 @@ +#![cfg(feature = "std")] + extern crate roaring; -#[cfg(feature = "std")] use roaring::RoaringBitmap; // Test data from https://github.com/RoaringBitmap/RoaringFormatSpec/tree/master/testdata -#[cfg(feature = "std")] static BITMAP_WITHOUT_RUNS: &[u8] = include_bytes!("bitmapwithoutruns.bin"); -#[cfg(feature = "std")] static BITMAP_WITH_RUNS: &[u8] = include_bytes!("bitmapwithruns.bin"); -#[cfg(feature = "std")] fn test_data_bitmap() -> RoaringBitmap { (0..100) .map(|i| i * 1000) @@ -18,7 +16,6 @@ fn test_data_bitmap() -> RoaringBitmap { .collect::() } -#[cfg(feature = "std")] fn serialize_and_deserialize(bitmap: &RoaringBitmap) -> RoaringBitmap { let mut buffer = vec![]; bitmap.serialize_into(&mut buffer).unwrap(); @@ -27,13 +24,11 @@ fn serialize_and_deserialize(bitmap: &RoaringBitmap) -> RoaringBitmap { } #[test] -#[cfg(feature = "std")] fn test_deserialize_without_runs_from_provided_data() { assert_eq!(RoaringBitmap::deserialize_from(BITMAP_WITHOUT_RUNS).unwrap(), test_data_bitmap()); } #[test] -#[cfg(feature = "std")] fn test_deserialize_with_runs_from_provided_data() { assert_eq!( RoaringBitmap::deserialize_from(&mut &BITMAP_WITH_RUNS[..]).unwrap(), @@ -42,7 +37,6 @@ fn test_deserialize_with_runs_from_provided_data() { } #[test] -#[cfg(feature = "std")] fn test_serialize_into_provided_data() { let bitmap = test_data_bitmap(); let mut buffer = vec![]; @@ -51,7 +45,6 @@ fn test_serialize_into_provided_data() { } #[test] -#[cfg(feature = "std")] fn test_empty() { let original = RoaringBitmap::new(); let new = serialize_and_deserialize(&original); @@ -59,7 +52,6 @@ fn test_empty() { } #[test] -#[cfg(feature = "std")] fn test_one() { let original = (1..2).collect::(); let new = serialize_and_deserialize(&original); @@ -67,7 +59,6 @@ fn test_one() { } #[test] -#[cfg(feature = "std")] fn test_array() { let original = (1000..3000).collect::(); let new = serialize_and_deserialize(&original); @@ -75,7 +66,6 @@ fn test_array() { } #[test] -#[cfg(feature = "std")] fn test_array_boundary() { let original = (1000..5096).collect::(); let new = serialize_and_deserialize(&original); @@ -83,16 +73,13 @@ fn test_array_boundary() { } #[test] -#[cfg(feature = "std")] fn test_bitmap_boundary() { - #[cfg(feature = "std")] let original = (1000..5097).collect::(); let new = serialize_and_deserialize(&original); assert_eq!(original, new); } #[test] -#[cfg(feature = "std")] fn test_bitmap_high16bits() { let mut bitmap = RoaringBitmap::new(); for i in 0..1 << 16 { @@ -109,7 +96,6 @@ fn test_bitmap_high16bits() { } #[test] -#[cfg(feature = "std")] fn test_bitmap() { let original = (1000..6000).collect::(); let new = serialize_and_deserialize(&original); @@ -117,7 +103,6 @@ fn test_bitmap() { } #[test] -#[cfg(feature = "std")] fn test_arrays() { let original = (1000..3000).chain(70000..74000).collect::(); let new = serialize_and_deserialize(&original); @@ -125,7 +110,6 @@ fn test_arrays() { } #[test] -#[cfg(feature = "std")] fn test_bitmaps() { let original = (1000..6000).chain(70000..77000).collect::(); let new = serialize_and_deserialize(&original); @@ -133,7 +117,6 @@ fn test_bitmaps() { } #[test] -#[cfg(feature = "std")] fn test_mixed() { let original = (1000..3000).chain(70000..77000).collect::(); let new = serialize_and_deserialize(&original); @@ -141,7 +124,6 @@ fn test_mixed() { } #[test] -#[cfg(feature = "std")] fn test_strange() { const ARRAY: &[u32] = &[ 6619162, 6619180, 6619181, 6619217, 6619218, 6619257, 6619258, 6619259, 6619260, 6619261, diff --git a/tests/treemap_serialization.rs b/tests/treemap_serialization.rs index 991b6713c..4c8f6be9e 100644 --- a/tests/treemap_serialization.rs +++ b/tests/treemap_serialization.rs @@ -1,9 +1,8 @@ -#[cfg(feature = "std")] +#![cfg(feature = "std")] + use core::iter::FromIterator; -#[cfg(feature = "std")] use roaring::RoaringTreemap; -#[cfg(feature = "std")] fn serialize_deserialize(dataset: Dataset) where Dataset: IntoIterator, @@ -22,25 +21,21 @@ where } #[test] -#[cfg(feature = "std")] fn empty() { serialize_deserialize(vec![]) } #[test] -#[cfg(feature = "std")] fn basic() { serialize_deserialize(vec![1, 2, 3, 4, 5, 100, 1000]) } #[test] -#[cfg(feature = "std")] fn basic_2() { serialize_deserialize(vec![1, 2, 3, 4, 5, 100, 1000, 10000, 100000, 1000000]) } #[test] -#[cfg(feature = "std")] fn basic_3() { let u32max = u32::MAX as u64; serialize_deserialize( From d812e909e2dfdce262cdfb77dd7205f60cbc04b4 Mon Sep 17 00:00:00 2001 From: GZTime Date: Sun, 21 Jan 2024 00:11:11 +0800 Subject: [PATCH 6/7] fix: byteorder when no_std --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 111d6b227..b44c19c2b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,7 @@ #![warn(variant_size_differences)] #![allow(unknown_lints)] // For clippy +#[cfg(feature = "std")] extern crate byteorder; #[macro_use] From 842cd16829e9b02f7c145397fc76caad75a99abf Mon Sep 17 00:00:00 2001 From: GZTime Date: Wed, 14 Feb 2024 00:37:30 +0800 Subject: [PATCH 7/7] chore: lock dependency versions note: all tests passed --- Cargo.toml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 74a3fb3d5..726f3d2e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,9 +16,9 @@ edition = "2021" license = "MIT OR Apache-2.0" [dependencies] -bytemuck = { version = "1.7", optional = true } -byteorder = { version = "1.4", optional = true } -serde = { version = "1.0", optional = true } +bytemuck = { version = "1.14.3", optional = true } +byteorder = { version = "1.5.0", optional = true } +serde = { version = "1.0.196", optional = true } [features] default = ["std"] @@ -27,9 +27,9 @@ simd = [] std = ["dep:bytemuck", "dep:byteorder"] [dev-dependencies] -proptest = "1.2" -serde_json = "1.0" -bincode = "1.3" +proptest = "1.4.0" +serde_json = "1.0.113" +bincode = "1.3.3" [profile.test] opt-level = 2