Skip to content

Commit

Permalink
Add version where item is self ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Antti committed Mar 18, 2024
1 parent 5b7a039 commit 1ddf2d6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/distribute_indexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use fnv::FnvHashMap;
use indexmap::IndexMap;
use std::collections::VecDeque;

pub fn distribute<T, ID>(
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<usize>
where
ID: Eq + std::hash::Hash,
Expand Down Expand Up @@ -91,6 +91,11 @@ where
result
}

/// Distribute items that are themselves IDs
pub fn distribute_ids<T>(data: &[T], spread: usize) -> Vec<usize> where T: Eq + std::hash::Hash, {
distribute(data, spread, |item| item)
}

fn calculate_spread<T, ID>(queue_per_id: &FnvHashMap<ID, VecDeque<T>>) -> usize {
queue_per_id
.iter()
Expand Down

0 comments on commit 1ddf2d6

Please sign in to comment.