1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use crate::index::TransactionList;
use crate::object::{AEADReader, DeserializeStream, Pool};
pub trait Depth: sealed::Sealed {
fn resolve(
index: Pool<AEADReader>,
transactions: TransactionList,
) -> Box<dyn Iterator<Item = DeserializeStream> + Sync + Send>;
}
mod sealed {
pub trait Sealed {}
impl Sealed for super::Incremental {}
impl Sealed for super::Snapshot {}
}
pub struct Incremental;
pub struct Snapshot;
#[inline(always)]
fn full_history(
pool: Pool<AEADReader>,
transactions: TransactionList,
) -> impl Iterator<Item = DeserializeStream> {
transactions
.into_iter()
.filter_map(move |(_gen, _field, stream)| {
pool.lease()
.ok()
.map(|r| DeserializeStream::new(stream.open_reader(r)))
})
}
impl Depth for Incremental {
#[inline(always)]
fn resolve(
index: Pool<AEADReader>,
transactions: TransactionList,
) -> Box<dyn Iterator<Item = DeserializeStream> + Sync + Send> {
Box::new(full_history(index, transactions))
}
}
impl Depth for Snapshot {
#[inline(always)]
fn resolve(
index: Pool<AEADReader>,
transactions: TransactionList,
) -> Box<dyn Iterator<Item = DeserializeStream> + Sync + Send> {
Box::new(full_history(index, transactions).take(1))
}
}