Merge rust-bitcoin/rust-bitcoin#3121: bip158: Improve casting
ea9f6e8f97
Cast after calling min (Tobin C. Harding)342fe18ad0
Use From in map_to_range (Tobin C. Harding)d9331794f1
bip158: Fix typo (Tobin C. Harding) Pull request description: Patch 1 is a typo fix, other two are cast improvements. Done as part of #2941. Leaves a cast to `u64` in there, will be removed once we get to the `ToU64` stuff. One other remaining cast in the module is obviously bit twiddling. ACKs for top commit: Kixunil: ACKea9f6e8f97
apoelstra: ACKea9f6e8f97
successfully ran local tests Tree-SHA512: 92fa6225621f6c1eea4864472a5b9c60cb244e62cdfbee4074067da43b8f2bd4e3ed1a249ba40b994cad824e97585f3140747b03677ef1596c80be3007c94a7c
This commit is contained in:
commit
865fdf78dd
|
@ -362,7 +362,7 @@ impl GcsFilterReader {
|
|||
}
|
||||
|
||||
/// Fast reduction of hash to [0, nm) range.
|
||||
fn map_to_range(hash: u64, nm: u64) -> u64 { ((hash as u128 * nm as u128) >> 64) as u64 }
|
||||
fn map_to_range(hash: u64, nm: u64) -> u64 { ((u128::from(hash) * u128::from(nm)) >> 64) as u64 }
|
||||
|
||||
/// Golomb-Rice encoded filter writer.
|
||||
pub struct GcsFilterWriter<'a, W> {
|
||||
|
@ -400,7 +400,7 @@ impl<'a, W: Write> GcsFilterWriter<'a, W> {
|
|||
// write number of elements as varint
|
||||
let mut wrote = VarInt::from(mapped.len()).consensus_encode(self.writer)?;
|
||||
|
||||
// write out deltas of sorted values into a Golonb-Rice coded bit stream
|
||||
// write out deltas of sorted values into a Golomb-Rice coded bit stream
|
||||
let mut writer = BitStreamWriter::new(self.writer);
|
||||
let mut last = 0;
|
||||
for data in mapped {
|
||||
|
@ -435,9 +435,9 @@ impl GcsFilter {
|
|||
let mut wrote = 0;
|
||||
let mut q = n >> self.p;
|
||||
while q > 0 {
|
||||
let nbits = cmp::min(q, 64);
|
||||
wrote += writer.write(!0u64, nbits as u8)?;
|
||||
q -= nbits;
|
||||
let nbits = cmp::min(q, 64) as u8; // cast ok, 64 fits into a `u8`
|
||||
wrote += writer.write(!0u64, nbits)?;
|
||||
q -= u64::from(nbits);
|
||||
}
|
||||
wrote += writer.write(0, 1)?;
|
||||
wrote += writer.write(n, self.p)?;
|
||||
|
|
Loading…
Reference in New Issue