Skip to content

Commit c588ad6

Browse files
committed
f - Use u16 values in look-up table
1 parent bbdcb6a commit c588ad6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lightning/src/routing/scoring.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ mod approx {
806806

807807
/// Look-up table for `log10(x) * 1000` where row `i` is used for each `x` having `i` as the
808808
/// most significant bit. The next 4 bits of `x`, if applicable, are used for the second index.
809-
const LOG10_TIMES_1K: [[u64; LOWER_BITS_BOUND as usize]; BITS as usize] = [
809+
const LOG10_TIMES_1K: [[u16; LOWER_BITS_BOUND as usize]; BITS as usize] = [
810810
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
811811
[301, 301, 301, 301, 301, 301, 301, 301, 477, 477, 477, 477, 477, 477, 477, 477],
812812
[602, 602, 602, 602, 699, 699, 699, 699, 778, 778, 778, 778, 845, 845, 845, 845],
@@ -877,11 +877,11 @@ mod approx {
877877
#[inline]
878878
pub fn negative_log10_times_1k(numerator: u64, denominator: u64) -> u64 {
879879
// Multiply the -1 through to avoid needing to use signed numbers.
880-
log10_times_1k(denominator) - log10_times_1k(numerator)
880+
(log10_times_1k(denominator) - log10_times_1k(numerator)) as u64
881881
}
882882

883883
#[inline]
884-
fn log10_times_1k(x: u64) -> u64 {
884+
fn log10_times_1k(x: u64) -> u16 {
885885
debug_assert_ne!(x, 0);
886886
let most_significant_bit = HIGHEST_BIT - x.leading_zeros();
887887
let lower_bits = (x >> most_significant_bit.saturating_sub(LOWER_BITS)) & LOWER_BITMASK;
@@ -897,7 +897,7 @@ mod approx {
897897
for msb in 0..BITS {
898898
for i in 0..LOWER_BITS_BOUND {
899899
let x = ((LOWER_BITS_BOUND + i) << (HIGHEST_BIT - LOWER_BITS)) >> (HIGHEST_BIT - msb);
900-
let log10_times_1k = ((x as f64).log10() * 1000.0).round() as u64;
900+
let log10_times_1k = ((x as f64).log10() * 1000.0).round() as u16;
901901
assert_eq!(log10_times_1k, LOG10_TIMES_1K[msb as usize][i as usize]);
902902

903903
if i % LOWER_BITS_BOUND == 0 {

0 commit comments

Comments
 (0)