Skip to content

Commit

Permalink
fix riff
Browse files Browse the repository at this point in the history
  • Loading branch information
ngtkana committed Dec 10, 2024
1 parent decbccf commit d55931e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
12 changes: 6 additions & 6 deletions libs/riff/src/bitmask_iterators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn bitmask_combinations<T: Unsigned>(n: u32, k: u32) -> BitmaskCombinations<
assert!(k < T::bit_length() && k < T::bit_length());
BitmaskCombinations {
n,
bs: (T::one() << k) - T::one(),
bs: (T::ONE << k) - T::ONE,
}
}

Expand All @@ -29,12 +29,12 @@ impl<T: Unsigned> Iterator for BitmaskCombinations<T> {
type Item = T;

fn next(&mut self) -> Option<Self::Item> {
if (T::one() << self.n) <= self.bs {
if (T::ONE << self.n) <= self.bs {
return None;
}
let res = Some(self.bs);
self.bs = if self.bs == T::zero() {
T::one() << self.n
self.bs = if self.bs == T::ZERO {
T::ONE << self.n
} else {
let x = self.bs & self.bs.wrapping_neg();
let y = self.bs + x;
Expand Down Expand Up @@ -78,10 +78,10 @@ impl<T: Unsigned> Iterator for BitmaskSubsets<T> {
return None;
}
let res = Some(self.bs ^ self.full);
if self.bs == T::zero() {
if self.bs == T::ZERO {
self.finished = true;
} else {
self.bs -= T::one();
self.bs -= T::ONE;
self.bs &= self.full;
}
res
Expand Down
10 changes: 8 additions & 2 deletions libs/riff/src/bitmask_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ use crate::Unsigned;
///
/// # Examples
/// ```
/// use crate::i2powm1;
/// use riff::i2powm1;
/// assert_eq!(i2powm1::<u32>(0), 0);
/// assert_eq!(i2powm1::<u32>(1), 1);
/// assert_eq!(i2powm1::<u32>(2), 3);
/// assert_eq!(i2powm1::<u32>(3), 7);
/// assert_eq!(i2powm1::<u32>(31), 0x7FFF_FFFF);
/// assert_eq!(i2powm1::<u32>(32), 0xFFFF_FFFF);
/// ```
pub fn i2powm1<T: Unsigned>(n: u32) -> T {
T::MAX >> (T::BITS - n)
if n == T::bit_length() {
T::MAX
} else {
(T::ONE << n) - T::ONE
}
}
8 changes: 4 additions & 4 deletions libs/riff/src/numeric_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ pub trait Unsigned:
{
const BITS: u32;
const MAX: Self;
fn zero() -> Self;
fn one() -> Self;
const ZERO: Self;
const ONE: Self;
fn wrapping_neg(self) -> Self;
fn bit_length() -> u32 {
size_of::<Self>() as u32 * 8
Expand All @@ -63,8 +63,8 @@ macro_rules! impl_unsigned {
impl Unsigned for $T {
const BITS: u32 = <$T>::BITS;
const MAX: Self = <$T>::MAX;
fn zero() -> Self { 0 }
fn one() -> Self { 1 }
const ZERO: Self = 0;
const ONE: Self = 1;
fn wrapping_neg(self) -> Self { self.wrapping_neg() }
}
)*}
Expand Down

0 comments on commit d55931e

Please sign in to comment.