Skip to content

Commit

Permalink
Simpler TimelyStackQueue
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Hoffmann <[email protected]>
  • Loading branch information
antiguru committed Nov 20, 2023
1 parent 5169516 commit 8fb8e61
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/trace/implementations/merge_batcher_col.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,12 @@ struct TimelyStackQueue<T: Columnation> {

impl<T: Columnation> Default for TimelyStackQueue<T> {
fn default() -> Self {
Self::empty()
Self::from(Default::default())
}
}

impl<T: Columnation> TimelyStackQueue<T> {

fn empty() -> Self { TimelyStackQueue::from(Default::default()) }

fn pop(&mut self) -> &T {
self.head += 1;
&self.list[self.head - 1]
Expand All @@ -145,7 +143,6 @@ impl<T: Columnation> TimelyStackQueue<T> {
}

fn done(mut self) -> TimelyStack<T> {
self.list.clear();
self.list
}

Expand Down Expand Up @@ -285,8 +282,8 @@ impl<D: Ord+Clone+Columnation+'static, T: Ord+Clone+Columnation+'static, R: Semi
let mut list1 = list1.into_iter();
let mut list2 = list2.into_iter();

let mut head1 = list1.next().map(TimelyStackQueue::from).unwrap_or_default();
let mut head2 = list2.next().map(TimelyStackQueue::from).unwrap_or_default();
let mut head1 = TimelyStackQueue::from(list1.next().unwrap_or_default());
let mut head2 = TimelyStackQueue::from(list2.next().unwrap_or_default());

// while we have valid data in each input, merge.
while !head1.is_empty() && !head2.is_empty() {
Expand Down Expand Up @@ -320,11 +317,11 @@ impl<D: Ord+Clone+Columnation+'static, T: Ord+Clone+Columnation+'static, R: Semi

if head1.is_empty() {
self.recycle(head1.done());
head1 = list1.next().map(TimelyStackQueue::from).unwrap_or_default();
head1 = TimelyStackQueue::from(list1.next().unwrap_or_default());
}
if head2.is_empty() {
self.recycle(head2.done());
head2 = list2.next().map(TimelyStackQueue::from).unwrap_or_default();
head2 = TimelyStackQueue::from(list2.next().unwrap_or_default());
}
}

Expand Down

0 comments on commit 8fb8e61

Please sign in to comment.