Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deduplicate unique function
Browse files Browse the repository at this point in the history
alecandido committed May 15, 2023
1 parent 4742d3d commit 8f4aa90
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions pineappl/src/grid.rs
Original file line number Diff line number Diff line change
@@ -937,31 +937,24 @@ impl Grid {
bins: &BinLimits,
entries: &[LumiEntry],
) -> (Vec<Order>, Vec<LumiEntry>) {
let mut new_orders: Vec<Order> = Vec::new();
let new_bins = bins.bins() - self.bin_limits.bins();
let mut new_entries: Vec<LumiEntry> = Vec::new();
fn unique<T: Clone + PartialEq>(current: &[T], update: &[T]) -> Vec<T> {
let mut new = Vec::new();

for order in orders.iter() {
if !self
.orders
.iter()
.chain(new_orders.iter())
.any(|x| x == order)
{
new_orders.push(order.clone());
for el in update.iter() {
if !current
.iter()
.chain(new.iter())
.any(|x| x == el)
{
new.push((*el).clone());
}
}
new
}

for entry in entries.iter() {
if !self
.lumi
.iter()
.chain(new_entries.iter())
.any(|y| y == entry)
{
new_entries.push(entry.clone());
}
}
let mut new_orders = unique(&self.orders, &orders);
let new_bins = bins.bins() - self.bin_limits.bins();
let mut new_entries = unique(&self.lumi, &entries);

if !new_orders.is_empty() || !new_entries.is_empty() || (new_bins != 0) {
self.increase_shape(&(new_orders.len(), new_bins, new_entries.len()));

0 comments on commit 8f4aa90

Please sign in to comment.