use core::hash::Hash;
use core::ops::{BitAnd, BitAndAssign, BitOrAssign, Not};
macro_rules! impl_storage_for {
($primitive:ty) => {
impl $crate::storage::Storage for $primitive {
const ZERO: $primitive = 0;
#[inline(always)]
fn from_usize(x: usize) -> $primitive {
x as $primitive
}
#[inline(always)]
fn num_of_high_bits(self) -> usize {
self.count_ones() as usize
}
}
};
}
impl_storage_for!(u8);
impl_storage_for!(u16);
impl_storage_for!(u32);
impl_storage_for!(u64);
impl_storage_for!(u128);
pub trait Storage:
Sized
+ Hash
+ PartialOrd
+ Ord
+ PartialEq
+ Eq
+ Copy
+ PartialEq<Self>
+ BitAnd<Output = Self>
+ BitAndAssign
+ BitOrAssign
+ Not<Output = Self>
{
const ZERO: Self;
const WIDTH: usize = ::core::mem::size_of::<Self>();
fn from_usize(x: usize) -> Self;
fn num_of_high_bits(self) -> usize;
}