From 1ddf2d68bc479a888f3eff7fb18676b8a051e6a2 Mon Sep 17 00:00:00 2001 From: Andrii Dmytrenko Date: Mon, 18 Mar 2024 16:52:42 +0000 Subject: [PATCH] Add version where item is self ID --- src/distribute_indexes.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/distribute_indexes.rs b/src/distribute_indexes.rs index 25e366a..2d6736c 100644 --- a/src/distribute_indexes.rs +++ b/src/distribute_indexes.rs @@ -2,10 +2,10 @@ use fnv::FnvHashMap; use indexmap::IndexMap; use std::collections::VecDeque; -pub fn distribute( - data: &[T], +pub fn distribute<'a, T: 'a, ID>( + data: &'a [T], mut spread: usize, - id_func: impl Fn(&T) -> ID + Send + 'static, + id_func: impl Fn(&'a T) -> ID + Send + 'static, ) -> Vec where ID: Eq + std::hash::Hash, @@ -91,6 +91,11 @@ where result } +/// Distribute items that are themselves IDs +pub fn distribute_ids(data: &[T], spread: usize) -> Vec where T: Eq + std::hash::Hash, { + distribute(data, spread, |item| item) +} + fn calculate_spread(queue_per_id: &FnvHashMap>) -> usize { queue_per_id .iter()