Skip to content

Commit

Permalink
Merge pull request #487 from RCasatta/map_with_u128
Browse files Browse the repository at this point in the history
use u128 in map_to_range
  • Loading branch information
elichai committed Nov 15, 2020
2 parents ac7bf80 + 8ac3af6 commit 7c05673
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions src/util/bip158.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,20 +324,7 @@ impl GCSFilterReader {

// fast reduction of hash to [0, nm) range
fn map_to_range(hash: u64, nm: u64) -> u64 {
// Use this once we upgrade to rustc >= 1.26
// ((hash as u128 * nm as u128) >> 64) as u64

#[inline]
fn l(n: u64) -> u64 { n & 0xffffffff }
#[inline]
fn h(n: u64) -> u64 { n >> 32 }

let a = h(hash);
let b = l(hash);
let c = h(nm);
let d = l(nm);

a * c + h(a * d + c * b + h(b * d))
((hash as u128 * nm as u128) >> 64) as u64
}

/// Colomb-Rice encoded filter writer
Expand Down

0 comments on commit 7c05673

Please sign in to comment.