Skip to content

Commit

Permalink
chunking: dedup logic
Browse files Browse the repository at this point in the history
  • Loading branch information
cgwalters committed May 9, 2023
1 parent 5807950 commit 4f32657
Showing 1 changed file with 17 additions and 36 deletions.
53 changes: 17 additions & 36 deletions lib/src/chunking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,84 +490,65 @@ fn get_partitions_with_threshold(
let freq = pkg.meta.change_frequency as f64;

//low frequency, high size
let bucket;
if (freq <= med_freq_low_limit) && (size >= med_size_high_limit) {
partitions
.entry("lf_hs".to_string())
.and_modify(|bin| bin.push(pkg))
.or_insert_with(|| vec![pkg]);
bucket = "lf_hs";
}
//medium frequency, high size
else if (freq < med_freq_high_limit)
&& (freq > med_freq_low_limit)
&& (size >= med_size_high_limit)
{
partitions
.entry("mf_hs".to_string())
.and_modify(|bin| bin.push(pkg))
.or_insert_with(|| vec![pkg]);
bucket = "mf_hs";
}
//high frequency, high size
else if (freq >= med_freq_high_limit) && (size >= med_size_high_limit) {
partitions
.entry("hf_hs".to_string())
.and_modify(|bin| bin.push(pkg))
.or_insert_with(|| vec![pkg]);
bucket = "hf_hs";
}
//low frequency, medium size
else if (freq <= med_freq_low_limit)
&& (size < med_size_high_limit)
&& (size > med_size_low_limit)
{
partitions
.entry("lf_ms".to_string())
.and_modify(|bin| bin.push(pkg))
.or_insert_with(|| vec![pkg]);
bucket = "lf_fs";
}
//medium frequency, medium size
else if (freq < med_freq_high_limit)
&& (freq > med_freq_low_limit)
&& (size < med_size_high_limit)
&& (size > med_size_low_limit)
{
partitions
.entry("mf_ms".to_string())
.and_modify(|bin| bin.push(pkg))
.or_insert_with(|| vec![pkg]);
bucket = "mf_ms";
}
//high frequency, medium size
else if (freq >= med_freq_high_limit)
&& (size < med_size_high_limit)
&& (size > med_size_low_limit)
{
partitions
.entry("hf_ms".to_string())
.and_modify(|bin| bin.push(pkg))
.or_insert_with(|| vec![pkg]);
bucket = "hf_ms";
}
//low frequency, low size
else if (freq <= med_freq_low_limit) && (size <= med_size_low_limit) {
partitions
.entry("lf_ls".to_string())
.and_modify(|bin| bin.push(pkg))
.or_insert_with(|| vec![pkg]);
bucket = "lf_ls";
}
//medium frequency, low size
else if (freq < med_freq_high_limit)
&& (freq > med_freq_low_limit)
&& (size <= med_size_low_limit)
{
partitions
.entry("mf_ls".to_string())
.and_modify(|bin| bin.push(pkg))
.or_insert_with(|| vec![pkg]);
bucket = "mf_ls";
}
//high frequency, low size
else if (freq >= med_freq_high_limit) && (size <= med_size_low_limit) {
partitions
.entry("hf_ls".to_string())
.and_modify(|bin| bin.push(pkg))
.or_insert_with(|| vec![pkg]);
bucket = "hf_ls";
} else {
unreachable!()
}

partitions
.entry(bucket.to_string())
.and_modify(|bin| bin.push(pkg))
.or_insert_with(|| vec![pkg]);
}

for (name, pkgs) in &partitions {
Expand Down

0 comments on commit 4f32657

Please sign in to comment.