Skip to content

Commit

Permalink
docrs features support
Browse files Browse the repository at this point in the history
  • Loading branch information
tower120 authored Jan 22, 2024
1 parent b19da46 commit 2b81bb4
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 70 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: cargo build --no-default-features
- run: RUSTFLAGS="--deny warnings" cargo build
- run: RUSTFLAGS="--deny warnings" cargo build --all-features

tests:
name: careful tests
Expand Down Expand Up @@ -86,4 +88,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: RUSTFLAGS="--deny warnings" cargo doc --lib --all-features
- run: RUSTFLAGS="--deny warnings" cargo doc --lib --all-features

docrs:
name: docrs build
runs-on: ubuntu-latest
steps:
- uses: dtolnay/rust-toolchain@nightly
- uses: actions/checkout@v4
- run:
RUSTFLAGS="--deny warnings"
RUSTDOCFLAGS="--cfg docsrs"
cargo +nightly doc --lib --all-features
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
### Changed
- `BitSetInterface` now have default implementation.
- `BitSet` no longer implements `BitSetInterface`.
But `&BitSet` still does. This prevents accidental sending container by value.
But `&BitSet` still does. This prevents accidental sending container by value.
- `config::with_cache::*` moved to `config::*` with additional default generic argument.

### Added
- `BitBlock::first_u64()`.
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ roaring = "0.10.2"

[package.metadata.docs.rs]
features = ["impl"]
rustdoc-args = ["--cfg", "docsrs"]

[[example]]
name = "custom_bitset"
Expand Down
5 changes: 5 additions & 0 deletions doc.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@echo off
setlocal
set RUSTDOCFLAGS=--cfg docsrs
cargo +nightly doc --lib --all-features %1
endlocal
111 changes: 49 additions & 62 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//!
//! [BitSet]: crate::BitSet

use std::marker::PhantomData;
use crate::bit_block::BitBlock;
use crate::{cache, PREALLOCATED_EMPTY_BLOCK, Primitive};
use crate::cache::ReduceCache;
Expand Down Expand Up @@ -96,73 +97,59 @@ pub trait Config: 'static {
}
}

/// Specify the default cache type.
pub mod with_cache{
use std::marker::PhantomData;
use crate::cache::ReduceCache;
use crate::config::Config;

/// MAX = 262_144
#[derive(Default)]
pub struct _64bit<DefaultCache: ReduceCache>(PhantomData<DefaultCache>);
impl<DefaultCache: ReduceCache> Config for _64bit<DefaultCache> {
type Level0BitBlock = u64;
type Level0BlockIndices = [u8; 64];

type Level1BitBlock = u64;
type Level1BlockIndex = u8;
type Level1BlockIndices = [u16; 64];

type DataBitBlock = u64;
type DataBlockIndex = u16;

type DefaultCache = DefaultCache;
}

/// MAX = 2_097_152
#[cfg(feature = "simd")]
#[derive(Default)]
pub struct _128bit<DefaultCache: ReduceCache>(PhantomData<DefaultCache>);
#[cfg(feature = "simd")]
impl<DefaultCache: ReduceCache> Config for _128bit<DefaultCache> {
type Level0BitBlock = wide::u64x2;
type Level0BlockIndices = [u8; 128];
/// MAX = 262_144
#[derive(Default)]
pub struct _64bit<DefaultCache: ReduceCache = self::DefaultCache>(PhantomData<DefaultCache>);
impl<DefaultCache: ReduceCache> Config for _64bit<DefaultCache> {
type Level0BitBlock = u64;
type Level0BlockIndices = [u8; 64];

type Level1BitBlock = wide::u64x2;
type Level1BlockIndex = u8;
type Level1BlockIndices = [u16; 128];
type Level1BitBlock = u64;
type Level1BlockIndex = u8;
type Level1BlockIndices = [u16; 64];

type DataBitBlock = wide::u64x2;
type DataBlockIndex = u16;
type DataBitBlock = u64;
type DataBlockIndex = u16;

type DefaultCache = DefaultCache;
}

/// MAX = 16_777_216
#[cfg(feature = "simd")]
#[derive(Default)]
pub struct _256bit<DefaultCache: ReduceCache>(PhantomData<DefaultCache>);
#[cfg(feature = "simd")]
impl<DefaultCache: ReduceCache> Config for _256bit<DefaultCache> {
type Level0BitBlock = wide::u64x4;
type Level0BlockIndices = [u8; 256];

type Level1BitBlock = wide::u64x4;
type Level1BlockIndex = u8;
type Level1BlockIndices = [u16; 256];

type DataBitBlock = wide::u64x4;
type DataBlockIndex = u16;

type DefaultCache = DefaultCache;
}
type DefaultCache = DefaultCache;
}

/// MAX = 262_144
pub type _64bit = with_cache::_64bit<DefaultCache>;

/// MAX = 2_097_152
pub type _128bit = with_cache::_128bit<DefaultCache>;
#[cfg(feature = "simd")]
#[cfg_attr(docsrs, doc(cfg(feature = "simd")))]
#[derive(Default)]
pub struct _128bit<DefaultCache: ReduceCache = self::DefaultCache>(PhantomData<DefaultCache>);
#[cfg(feature = "simd")]
impl<DefaultCache: ReduceCache> Config for _128bit<DefaultCache> {
type Level0BitBlock = wide::u64x2;
type Level0BlockIndices = [u8; 128];

type Level1BitBlock = wide::u64x2;
type Level1BlockIndex = u8;
type Level1BlockIndices = [u16; 128];

type DataBitBlock = wide::u64x2;
type DataBlockIndex = u16;

type DefaultCache = DefaultCache;
}

/// MAX = 16_777_216
pub type _256bit = with_cache::_256bit<DefaultCache>;
#[cfg(feature = "simd")]
#[cfg_attr(docsrs, doc(cfg(feature = "simd")))]
#[derive(Default)]
pub struct _256bit<DefaultCache: ReduceCache = self::DefaultCache>(PhantomData<DefaultCache>);
#[cfg(feature = "simd")]
impl<DefaultCache: ReduceCache> Config for _256bit<DefaultCache> {
type Level0BitBlock = wide::u64x4;
type Level0BlockIndices = [u8; 256];

type Level1BitBlock = wide::u64x4;
type Level1BlockIndex = u8;
type Level1BlockIndices = [u16; 256];

type DataBitBlock = wide::u64x4;
type DataBlockIndex = u16;

type DefaultCache = DefaultCache;
}
4 changes: 2 additions & 2 deletions src/implement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

use crate::bitset_interface::{bitset_is_empty, bitsets_eq, bitset_contains};
use crate::config::{DefaultBlockIterator, DefaultIndexIterator};
pub use crate::bitset_interface::BitSetInterface;
use crate::bitset_interface::BitSetInterface;
pub use crate::bitset_interface::LevelMasks;
pub use crate::bitset_interface::LevelMasksIterExt;

Expand Down Expand Up @@ -143,7 +143,7 @@ pub fn contains<S: LevelMasks>(bitset: S, index: usize) -> bool {
///
/// # Safety
///
/// **DO NOT** implement [BitSetInterface] for `$t`, since `impl_simple_bitset`s
/// **DO NOT** implement [BitSetInterface] for `$t`, since `impl_bitset_simple`'s
/// [LevelMasksIterExt] implementation stores pointer to Self in [Level1BlockData].
/// If "drain iterator" will move during iteration - that will invalidate
/// [Level1BlockData].
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg_attr(miri, feature(alloc_layout_extra) )]
#![cfg_attr(docsrs, feature(doc_cfg))]
//! Hierarchical sparse bitset.
//!
//! Memory consumption does not depends on max index inserted.
Expand Down Expand Up @@ -135,6 +136,7 @@ pub mod iter;
pub mod cache;

#[cfg(feature = "impl")]
#[cfg_attr(docsrs, doc(cfg(feature = "impl")))]
pub mod implement;
#[cfg(not(feature = "impl"))]
mod implement;
Expand Down
8 changes: 4 additions & 4 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ cfg_if::cfg_if! {

cfg_if::cfg_if! {
if #[cfg(hisparsebitset_test_64)] {
type Conf = config::with_cache::_64bit<DefaultCache>;
type Conf = config::_64bit<DefaultCache>;
} else if #[cfg(hisparsebitset_test_128)] {
type Conf = config::with_cache::_128bit<DefaultCache>;
type Conf = config::_128bit<DefaultCache>;
} else if #[cfg(hisparsebitset_test_256)] {
type Conf = config::with_cache::_256bit<DefaultCache>;
type Conf = config::_256bit<DefaultCache>;
} else {
type Conf = config::with_cache::_128bit<DefaultCache>;
type Conf = config::_128bit<DefaultCache>;
}
}

Expand Down

0 comments on commit 2b81bb4

Please sign in to comment.