Skip to content

Commit

Permalink
chore: Remove unused functions (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuyukitanimura authored Apr 23, 2024
1 parent 646f9a0 commit 4a0631b
Showing 1 changed file with 0 additions and 39 deletions.
39 changes: 0 additions & 39 deletions core/src/common/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,6 @@ macro_rules! read_num_be_bytes {
}};
}

/// Converts value `val` of type `T` to a byte vector, by reading `num_bytes` from `val`.
/// NOTE: if `val` is less than the size of `T` then it can be truncated.
#[inline]
pub fn convert_to_bytes<T>(val: &T, num_bytes: usize) -> Vec<u8>
where
T: ?Sized + AsBytes,
{
let mut bytes: Vec<u8> = vec![0; num_bytes];
memcpy_value(val.as_bytes(), num_bytes, &mut bytes);
bytes
}

#[inline]
pub fn memcpy(source: &[u8], target: &mut [u8]) {
debug_assert!(target.len() >= source.len(), "Copying from source to target is not possible. Source has {} bytes but target has {} bytes", source.len(), target.len());
Expand Down Expand Up @@ -203,10 +191,6 @@ pub fn trailing_bits(v: u64, num_bits: usize) -> u64 {
(v << n) >> n
}

pub fn set_bit_value(bits: &mut [u8], i: usize, val: bool) {
bits[i / 8] |= (val as u8) << (i % 8);
}

#[inline]
pub fn set_bit(bits: &mut [u8], i: usize) {
bits[i / 8] |= 1 << (i % 8);
Expand Down Expand Up @@ -257,17 +241,6 @@ pub fn set_bits(bits: &mut [u8], offset: usize, length: usize) {
}
}

/// Returns the minimum number of bits needed to represent the value 'x'
#[inline]
pub fn num_required_bits(x: u64) -> usize {
for i in (0..64).rev() {
if x & (1u64 << i) != 0 {
return i + 1;
}
}
0
}

#[inline(always)]
pub fn mix_hash(lower: u64, upper: u64) -> u64 {
let hash = (17 * 37u64).wrapping_add(lower);
Expand Down Expand Up @@ -1170,18 +1143,6 @@ mod tests {
}
}

#[test]
fn test_num_required_bits() {
assert_eq!(num_required_bits(0), 0);
assert_eq!(num_required_bits(1), 1);
assert_eq!(num_required_bits(2), 2);
assert_eq!(num_required_bits(4), 3);
assert_eq!(num_required_bits(8), 4);
assert_eq!(num_required_bits(10), 4);
assert_eq!(num_required_bits(12), 4);
assert_eq!(num_required_bits(16), 5);
}

#[test]
fn test_get_bit() {
// 00001101
Expand Down

0 comments on commit 4a0631b

Please sign in to comment.