From bd36f82770a46320ee765c6bb9b822bee1968b48 Mon Sep 17 00:00:00 2001 From: qy3u Date: Thu, 16 May 2024 15:04:36 +0800 Subject: [PATCH] refactor: num_matches to has_match --- crates/subspace-proof-of-space/src/chiapos/table.rs | 9 ++++----- crates/subspace-proof-of-space/src/chiapos/tables.rs | 8 +++----- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/crates/subspace-proof-of-space/src/chiapos/table.rs b/crates/subspace-proof-of-space/src/chiapos/table.rs index 4ecec6b6aa..93362c80de 100644 --- a/crates/subspace-proof-of-space/src/chiapos/table.rs +++ b/crates/subspace-proof-of-space/src/chiapos/table.rs @@ -259,7 +259,7 @@ pub(super) fn compute_f1_simd( /// `rmap_scratch` is just an optimization to reuse allocations between calls. /// -/// For verification purposes use [`num_matches`] instead. +/// For verification purposes use [`has_match`] instead. /// /// Returns `None` if either of buckets is empty. fn find_matches<'a>( @@ -326,20 +326,19 @@ fn find_matches<'a>( } /// Simplified version of [`find_matches`] for verification purposes. -pub(super) fn num_matches(left_y: Y, right_y: Y) -> usize { +pub(super) fn has_match(left_y: Y, right_y: Y) -> bool { let right_r = usize::from(right_y) % usize::from(PARAM_BC); let parity = (usize::from(left_y) / usize::from(PARAM_BC)) % 2; let left_r = usize::from(left_y) % usize::from(PARAM_BC); - let mut matches = 0; for m in 0..usize::from(PARAM_M) { let r_target = calculate_left_target_on_demand(parity, left_r, m); if r_target == right_r { - matches += 1; + return true; } } - matches + false } pub(super) fn compute_fn( diff --git a/crates/subspace-proof-of-space/src/chiapos/tables.rs b/crates/subspace-proof-of-space/src/chiapos/tables.rs index b38a52cb72..2980ca985f 100644 --- a/crates/subspace-proof-of-space/src/chiapos/tables.rs +++ b/crates/subspace-proof-of-space/src/chiapos/tables.rs @@ -7,7 +7,7 @@ extern crate alloc; use crate::chiapos::table::types::{Metadata, Position, X, Y}; pub use crate::chiapos::table::TablesCache; use crate::chiapos::table::{ - compute_f1, compute_fn, metadata_size_bytes, num_matches, partial_y, Table, + compute_f1, compute_fn, has_match, metadata_size_bytes, partial_y, Table, COMPUTE_F1_SIMD_FACTOR, }; use crate::chiapos::utils::EvaluatableUsize; @@ -375,14 +375,12 @@ where ys_and_metadata .array_chunks::<2>() .map(|&[(left_y, left_metadata), (right_y, right_metadata)]| { - (num_matches(left_y, right_y) == 1).then_some(compute_fn::< + has_match(left_y, right_y).then_some(compute_fn::< K, TABLE_NUMBER, PARENT_TABLE_NUMBER, >( - left_y, - left_metadata, - right_metadata, + left_y, left_metadata, right_metadata )) }) .collect()