Skip to content

Commit

Permalink
refactor: num_matches to has_match
Browse files Browse the repository at this point in the history
  • Loading branch information
qy3u committed May 17, 2024
1 parent d159452 commit bd36f82
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
9 changes: 4 additions & 5 deletions crates/subspace-proof-of-space/src/chiapos/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ pub(super) fn compute_f1_simd<const K: u8>(

/// `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>(
Expand Down Expand Up @@ -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<const K: u8, const TABLE_NUMBER: u8, const PARENT_TABLE_NUMBER: u8>(
Expand Down
8 changes: 3 additions & 5 deletions crates/subspace-proof-of-space/src/chiapos/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit bd36f82

Please sign in to comment.