Skip to content

Commit

Permalink
remove redundant eval functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jirigav committed May 13, 2024
1 parent a7c5a7a commit 0468d27
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 65 deletions.
6 changes: 3 additions & 3 deletions src/bottomup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::time::{Duration, Instant};
use itertools::Itertools;
use rayon::iter::*;

use crate::common::{_multi_eval, bits_block_eval, transform_data, z_score, Data};
use crate::common::{multi_eval, bits_block_eval, transform_data, z_score, Data};

#[derive(Clone)]
pub(crate) struct Histogram {
Expand Down Expand Up @@ -139,7 +139,7 @@ fn compute_bins(
block_size: usize,
t: &mut Duration,
) {
let ones = _multi_eval(bits, data, t);
let ones = multi_eval(bits, data, t);

let value = 2_usize.pow(d as u32) - 1;

Expand Down Expand Up @@ -167,7 +167,7 @@ fn brute_force(data: &Data, block_size: usize, deg: usize, k: usize) -> Vec<Hist

let mut hists: Vec<Vec<usize>> = Vec::new();
for i in 0..block_size {
let ones = _multi_eval(&[i], data, &mut t);
let ones = multi_eval(&[i], data, &mut t);
hists.push(vec![(data._num_of_blocks as usize) - ones, ones])
}

Expand Down
63 changes: 1 addition & 62 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,37 +63,7 @@ pub(crate) struct Data {
pub(crate) _num_of_blocks: u32,
}

fn _rec_eval<'a>(bits: &[usize], data: &'a Data) -> Box<dyn Iterator<Item = u128> + 'a> {
if bits.len() == 1 {
Box::new(data.data[bits[0]].iter().copied())
} else if bits.len() == 2 {
Box::new(
data.data[bits[0]]
.iter()
.zip(data.data[bits[1]].iter())
.map(|(a, b)| a & b),
)
} else {
let (bits1, bits2) = bits.split_at(bits.len() / 2);
Box::new(
_rec_eval(bits1, data)
.zip(_rec_eval(bits2, data))
.map(|(a, b)| a & b),
)
}
}

// lower the number of stream combinations
pub(crate) fn _multi_eval3(bits: &[usize], data: &Data, t: &mut Duration) -> usize {
let start = Instant::now();
let r = _rec_eval(bits, data)
.map(|x| x.count_ones() as usize)
.sum::<usize>();
*t += start.elapsed();
r
}

pub(crate) fn _multi_eval(bits: &[usize], data: &Data, t: &mut Duration) -> usize {
pub(crate) fn multi_eval(bits: &[usize], data: &Data, t: &mut Duration) -> usize {
let start = Instant::now();
let mut result = vec![u128::MAX; data.data[0].len()];

Expand All @@ -113,37 +83,6 @@ pub(crate) fn _multi_eval(bits: &[usize], data: &Data, t: &mut Duration) -> usiz
r
}

// try to fit in cache
pub(crate) fn _multi_eval2(bits: &[usize], data: &Data, t: &mut Duration) -> usize {
let start = Instant::now();

let mut r = 0;
let mut i = 0;

loop {
let l = std::cmp::min(data.data[0].len() - i, 16000);
if i == data.data[0].len() {
break;
}
let mut result = vec![u128::MAX; l];
for b in bits.iter() {
result = result
.iter()
.zip(&data.data[*b][i..(i + l)])
.map(|(a, b)| a & b)
.collect();
}
i += l;
r += result
.iter()
.map(|x| x.count_ones() as usize)
.sum::<usize>();
}

*t += start.elapsed();
r
}

fn load_data(path: &str, block_size: usize) -> Vec<Vec<u8>> {
let len_of_block_in_bytes = block_size / 8;
let mut data: Vec<_> = fs::read(path)
Expand Down

0 comments on commit 0468d27

Please sign in to comment.