Skip to content

Commit

Permalink
Added default trait derives for ListOfLists
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Feb 17, 2024
1 parent b976351 commit 9335bb3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/instantiation/latency_algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub struct FanInOut {
pub fn convert_fanin_to_fanout(fanins : &ListOfLists<FanInOut>) -> ListOfLists<FanInOut> {
ListOfLists::from_random_access_iterator(
fanins.len(),
fanins.iter_flattened().map(|v| v.other),
fanins.iter_flattened_by_bucket().map(|(bucket, &FanInOut{ other, delta_latency })| (other, FanInOut{other:bucket, delta_latency}))
)
}
Expand Down
12 changes: 8 additions & 4 deletions src/list_of_lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ impl<T> ListOfLists<T> {
Runs through the entire iterator twice.
Once to collect the size for each target group, and once to place all the results
MUST pass an iterator that iterates through the target indices first, then one that passes over the same indices with the data
MUST pass a cloneable iterator that iterates through all elements you wish to add.
A clone of the iterator may not behave differently
*/
pub fn from_random_access_iterator<IndexIterT: Iterator<Item = usize>, IterT: Iterator<Item = (usize, T)>>(num_groups : usize, index_iter : IndexIterT, iter: IterT) -> Self {
pub fn from_random_access_iterator<IterT: Iterator<Item = (usize, T)> + Clone>(num_groups : usize, iter: IterT) -> Self {
// We'll be reusing this vector for the resulting start_ends vector, so already have it at the right size
// First we use the memory to collect group sizes
let mut start_ends : Vec<usize> = vec![0; num_groups + 1];

for to_idx in index_iter {
for (to_idx, _) in iter.clone() {
start_ends[to_idx+1] += 1;
}

Expand Down Expand Up @@ -131,7 +132,7 @@ impl<'a, T> IndexMut<usize> for ListOfLists<T> {
}



#[derive(Debug, Clone)]
pub struct ListOfListsFlatOriginIter<'a, T> {
buf_iter : std::iter::Enumerate<std::slice::Iter<'a, T>>,
ends : &'a [usize],
Expand All @@ -152,6 +153,7 @@ impl<'a, T> Iterator for ListOfListsFlatOriginIter<'a, T> {
}
}

#[derive(Debug)]
pub struct ListOfListsFlatOriginIterMut<'a, T> {
buf_iter : std::iter::Enumerate<std::slice::IterMut<'a, T>>,
ends : &'a [usize],
Expand All @@ -174,6 +176,7 @@ impl<'a, T> Iterator for ListOfListsFlatOriginIterMut<'a, T> {

// Basic iterators

#[derive(Debug, Clone)]
pub struct ListOfListsIter<'a, T> {
buf : &'a [T],
start : usize,
Expand All @@ -191,6 +194,7 @@ impl<'a, T> Iterator for ListOfListsIter<'a, T> {
}
}

#[derive(Debug)]
pub struct ListOfListsIterMut<'a, T> {
buf : &'a mut [T],
start : usize,
Expand Down

0 comments on commit 9335bb3

Please sign in to comment.