loro_internal/delta/
movable_list.rs

1use fxhash::FxHashMap;
2use loro_common::{CompactIdLp, IdFull, IdLp, LoroValue};
3use smallvec::SmallVec;
4
5use super::{Delta, DeltaValue};
6
7#[derive(Clone, Debug)]
8pub(crate) struct MovableListInnerDelta {
9    pub list: Delta<SmallVec<[IdFull; 1]>, ()>,
10    pub elements: FxHashMap<CompactIdLp, ElementDelta>,
11}
12
13impl DeltaValue for SmallVec<[IdFull; 1]> {
14    fn value_extend(&mut self, other: Self) -> Result<(), Self> {
15        for v in other {
16            self.push(v)
17        }
18
19        Ok(())
20    }
21
22    fn take(&mut self, length: usize) -> Self {
23        self.drain(..length).collect()
24    }
25
26    fn length(&self) -> usize {
27        self.len()
28    }
29}
30
31impl MovableListInnerDelta {
32    pub(crate) fn is_empty(&self) -> bool {
33        self.list.is_empty() && self.elements.is_empty()
34    }
35}
36
37#[derive(Clone, Debug)]
38pub struct ElementDelta {
39    /// This must be Some if it's in checkout mode (not fast-forward mode)
40    pub pos: Option<IdLp>,
41    pub value: LoroValue,
42    pub value_updated: bool,
43    /// This must be Some if it's in checkout mode (not fast-forward mode)
44    pub value_id: Option<IdLp>,
45}
46
47impl ElementDelta {
48    pub fn placeholder() -> Self {
49        Self {
50            pos: None,
51            value: LoroValue::Null,
52            value_updated: false,
53            value_id: None,
54        }
55    }
56}