1
use crate::{
2
    id::SegmentId,
3
    persy::PersyImpl,
4
    segment::SegmentPageIterator,
5
    snapshot::SnapshotId,
6
    transaction::{Transaction, TransactionInsertIterator},
7
    PRes, PersyId,
8
};
9

10
pub struct SegmentRawIter {
11
    segment_id: SegmentId,
12
    iterator: SegmentPageIterator,
13
    snapshot_id: SnapshotId,
14
}
15

16
impl SegmentRawIter {
17 1
    pub fn new(segment_id: SegmentId, iterator: SegmentPageIterator, snapshot_id: SnapshotId) -> SegmentRawIter {
18 1
        SegmentRawIter {
19
            segment_id,
20 1
            iterator,
21
            snapshot_id,
22
        }
23 1
    }
24 1
    pub fn next(&mut self, persy_impl: &PersyImpl) -> Option<(PersyId, Vec<u8>)> {
25 1
        while let Some(id) = self.iterator.next(persy_impl.address()) {
26 1
            if let Ok(Some(val)) = persy_impl.read(self.segment_id, &id) {
27 1
                return Some((PersyId(id), val));
28
            }
29 1
        }
30 1
        None
31 1
    }
32 1
    pub fn release(&self, persy_impl: &PersyImpl) -> PRes<()> {
33 1
        persy_impl.release_snapshot(self.snapshot_id)?;
34 1
        Ok(())
35 1
    }
36
}
37

38
pub struct SegmentSnapshotRawIter {
39
    segment_id: SegmentId,
40
    iterator: SegmentPageIterator,
41
    snapshot_id: SnapshotId,
42
}
43

44
impl SegmentSnapshotRawIter {
45 1
    pub fn new(
46
        segment_id: SegmentId,
47
        iterator: SegmentPageIterator,
48
        snapshot_id: SnapshotId,
49
    ) -> SegmentSnapshotRawIter {
50 1
        SegmentSnapshotRawIter {
51
            segment_id,
52 1
            iterator,
53
            snapshot_id,
54
        }
55 1
    }
56 1
    pub fn next(&mut self, persy_impl: &PersyImpl) -> Option<(PersyId, Vec<u8>)> {
57 1
        while let Some(id) = self.iterator.next(persy_impl.address()) {
58 1
            if let Ok(Some(val)) = persy_impl.read_snap(self.segment_id, &id, self.snapshot_id) {
59 1
                return Some((PersyId(id), val));
60
            }
61 1
        }
62 0
        None
63 1
    }
64
}
65

66
pub struct TxSegmentRawIter {
67
    segment_id: SegmentId,
68
    tx_iterator: TransactionInsertIterator,
69
    iterator: SegmentPageIterator,
70
    snapshot_id: SnapshotId,
71
}
72

73
impl TxSegmentRawIter {
74 1
    pub fn new(
75
        tx: &Transaction,
76
        segment_id: SegmentId,
77
        iterator: SegmentPageIterator,
78
        snapshot_id: SnapshotId,
79
    ) -> TxSegmentRawIter {
80 1
        let iter = tx.scan_insert(segment_id).into_iter();
81 1
        TxSegmentRawIter {
82
            segment_id,
83 1
            tx_iterator: iter,
84 1
            iterator,
85
            snapshot_id,
86
        }
87 1
    }
88 1
    pub fn next(&mut self, persy_impl: &PersyImpl, tx: &Transaction) -> Option<(PersyId, Vec<u8>, u16)> {
89 1
        while let Some(id) = self
90
            .iterator
91 1
            .next(persy_impl.address())
92 1
            .or_else(|| self.tx_iterator.next())
93
        {
94 1
            if let Ok(Some((val, version))) = persy_impl.read_tx_internal(tx, self.segment_id, &id) {
95 1
                return Some((PersyId(id), val, version));
96
            }
97 1
        }
98 1
        None
99 1
    }
100 1
    pub fn release(&self, persy_impl: &PersyImpl) -> PRes<()> {
101 1
        persy_impl.release_snapshot(self.snapshot_id)?;
102 1
        Ok(())
103 1
    }
104
}

Read our documentation on viewing source code .

Loading