Skip to content

Commit

Permalink
Merge pull request #127 from EchoAlice/log2
Browse files Browse the repository at this point in the history
Replaces `log_2` logic with `checked_ilog2`
  • Loading branch information
ralexstokes authored Feb 29, 2024
2 parents 6329986 + a521d8c commit 61d780b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
coverage:
runs-on: ubuntu-latest
container:
image: xd009642/tarpaulin:develop-nightly
image: xd009642/tarpaulin:latest
options: --security-opt seccomp=unconfined
steps:
- name: Checkout sources
Expand Down
2 changes: 1 addition & 1 deletion ssz-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ mod lib {
pub use std::*;
}

pub use self::core::{any, cmp, fmt, iter, mem, slice};
pub use self::core::{any, cmp, fmt, iter, slice};

pub use self::{
cmp::Ordering,
Expand Down
15 changes: 2 additions & 13 deletions ssz-rs/src/merkleization/multiproofs/generalized_index.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
use crate::{lib::mem, merkleization::MerkleizationError as Error};

const BITS_PER_BYTE: usize = crate::BITS_PER_BYTE as usize;

// From: https://users.rust-lang.org/t/logarithm-of-integers/8506/5
const fn num_bits<T>() -> usize {
mem::size_of::<T>() * BITS_PER_BYTE
}
use crate::merkleization::MerkleizationError as Error;

// Return base 2 logarithm of `x`.
// `None` is returned if `x` is `0` as this logarithm is undefined.
fn log_2(x: usize) -> Option<u32> {
if x == 0 {
None
} else {
Some(num_bits::<usize>() as u32 - x.leading_zeros() - 1)
}
x.checked_ilog2()
}

pub fn get_power_of_two_ceil(x: usize) -> usize {
Expand Down

0 comments on commit 61d780b

Please sign in to comment.