Skip to content

Commit 7721b5f

Browse files
committed
Use InOrderIter from git-features (#293)
1 parent cb7e4e7 commit 7721b5f

File tree

8 files changed

+17
-158
lines changed

8 files changed

+17
-158
lines changed

git-features/src/parallel/in_order.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{cmp::Ordering, collections::BTreeMap};
22

3-
/// A counter for chunks to be able to put them back into original order later.
4-
pub type ChunkId = usize;
3+
/// A counter for items that are in sequence, to be able to put them back into original order later.
4+
pub type SequenceId = usize;
55

66
/// An iterator which olds iterated items with a **sequential** ID starting at 0 long enough to dispense them in order.
77
///
@@ -10,14 +10,14 @@ pub type ChunkId = usize;
1010
pub struct InOrderIter<T, I> {
1111
/// The iterator yielding the out-of-order elements we are to yield in order.
1212
pub inner: I,
13-
store: BTreeMap<ChunkId, T>,
14-
next_chunk: ChunkId,
13+
store: BTreeMap<SequenceId, T>,
14+
next_chunk: SequenceId,
1515
is_done: bool,
1616
}
1717

1818
impl<T, E, I> From<I> for InOrderIter<T, I>
1919
where
20-
I: Iterator<Item = Result<(ChunkId, T), E>>,
20+
I: Iterator<Item = Result<(SequenceId, T), E>>,
2121
{
2222
fn from(iter: I) -> Self {
2323
InOrderIter {
@@ -31,7 +31,7 @@ where
3131

3232
impl<T, E, I> Iterator for InOrderIter<T, I>
3333
where
34-
I: Iterator<Item = Result<(ChunkId, T), E>>,
34+
I: Iterator<Item = Result<(SequenceId, T), E>>,
3535
{
3636
type Item = Result<T, E>;
3737

git-features/src/parallel/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ mod serial;
4242
pub use serial::{in_parallel, join, threads};
4343

4444
mod in_order;
45-
pub use in_order::InOrderIter;
45+
pub use in_order::{InOrderIter, SequenceId};
4646

4747
mod eager_iter;
4848
pub use eager_iter::{EagerIter, EagerIterIf};

git-pack/src/data/output/entry/iter_from_counts.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use std::{cmp::Ordering, sync::Arc};
22

3+
use git_features::parallel::SequenceId;
34
use git_features::{parallel, progress::Progress};
45

5-
use crate::data::{output, output::ChunkId};
6+
use crate::data::output;
67

78
/// Given a known list of object `counts`, calculate entries ready to be put into a data pack.
89
///
@@ -44,7 +45,7 @@ pub fn iter_from_counts<Find>(
4445
thread_limit,
4546
chunk_size,
4647
}: Options,
47-
) -> impl Iterator<Item = Result<(ChunkId, Vec<output::Entry>), Error<Find::Error>>>
48+
) -> impl Iterator<Item = Result<(SequenceId, Vec<output::Entry>), Error<Find::Error>>>
4849
+ parallel::reduce::Finalize<Reduce = reduce::Statistics<Error<Find::Error>>>
4950
where
5051
Find: crate::Find + Send + Clone + 'static,
@@ -152,7 +153,7 @@ where
152153
},
153154
{
154155
let counts = Arc::clone(&counts);
155-
move |(chunk_id, chunk_range): (ChunkId, std::ops::Range<usize>), (buf, progress)| {
156+
move |(chunk_id, chunk_range): (SequenceId, std::ops::Range<usize>), (buf, progress)| {
156157
let mut out = Vec::new();
157158
let chunk = &counts[chunk_range];
158159
let mut stats = Outcome::default();
@@ -277,8 +278,9 @@ mod reduce {
277278
use std::marker::PhantomData;
278279

279280
use git_features::parallel;
281+
use git_features::parallel::SequenceId;
280282

281-
use super::{ChunkId, Outcome};
283+
use super::Outcome;
282284
use crate::data::output;
283285

284286
pub struct Statistics<E> {
@@ -296,8 +298,8 @@ mod reduce {
296298
}
297299

298300
impl<Error> parallel::Reduce for Statistics<Error> {
299-
type Input = Result<(ChunkId, Vec<output::Entry>, Outcome), Error>;
300-
type FeedProduce = (ChunkId, Vec<output::Entry>);
301+
type Input = Result<(SequenceId, Vec<output::Entry>, Outcome), Error>;
302+
type FeedProduce = (SequenceId, Vec<output::Entry>);
301303
type Output = Outcome;
302304
type Error = Error;
303305

git-pack/src/data/output/in_order.rs

-86
This file was deleted.

git-pack/src/data/output/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,3 @@ pub mod entry;
3939

4040
///
4141
pub mod bytes;
42-
43-
mod in_order;
44-
pub use in_order::{ChunkId, InOrderIter};

git-pack/tests/pack/data/output/count_and_entries.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{convert::Infallible, sync::atomic::AtomicBool};
22

3+
use git_features::parallel::InOrderIter;
34
use git_features::{parallel::reduce::Finalize, progress};
45
use git_odb::{compound, pack, pack::FindExt};
56
use git_pack::data::{
@@ -291,7 +292,7 @@ fn traversals() -> crate::Result {
291292
..Default::default()
292293
},
293294
);
294-
let entries: Vec<_> = output::InOrderIter::from(entries_iter.by_ref())
295+
let entries: Vec<_> = InOrderIter::from(entries_iter.by_ref())
295296
.collect::<Result<Vec<_>, _>>()?
296297
.into_iter()
297298
.flatten()

git-pack/tests/pack/data/output/in_order_iter.rs

-54
This file was deleted.

git-pack/tests/pack/data/output/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,3 @@ fn db(kind: DbKind) -> crate::Result<git_odb::HandleArc> {
4444
}
4545

4646
mod count_and_entries;
47-
mod in_order_iter;

0 commit comments

Comments
 (0)