mirror of
https://github.com/loro-dev/loro.git
synced 2025-01-22 21:07:43 +00:00
refactor: add has id
This commit is contained in:
parent
d28fa407ea
commit
d924e9fac8
3 changed files with 36 additions and 2 deletions
|
@ -5,10 +5,10 @@
|
|||
//!
|
||||
//! In future, we may also use [Change] to represent a transaction. But this decision is postponed.
|
||||
|
||||
|
||||
use crate::{
|
||||
id::{Counter, ID},
|
||||
op::Op,
|
||||
span::HasId,
|
||||
};
|
||||
use rle::{HasLength, Mergable, RleVec};
|
||||
use smallvec::SmallVec;
|
||||
|
@ -121,3 +121,9 @@ impl Mergable<ChangeMergeCfg> for Change {
|
|||
&& self.lamport + self.len() as Lamport == other.lamport
|
||||
}
|
||||
}
|
||||
|
||||
impl HasId for Change {
|
||||
fn id_start(&self) -> ID {
|
||||
self.id
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{
|
||||
container::ContainerID,
|
||||
id::{Counter, ID},
|
||||
span::IdSpan,
|
||||
span::{HasId, IdSpan},
|
||||
};
|
||||
use rle::{HasLength, Mergable, RleVec, Sliceable};
|
||||
mod insert_content;
|
||||
|
@ -124,3 +124,9 @@ impl Sliceable for Op {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HasId for Op {
|
||||
fn id_start(&self) -> ID {
|
||||
self.id
|
||||
}
|
||||
}
|
||||
|
|
|
@ -155,6 +155,28 @@ impl Mergable for IdSpan {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait HasId {
|
||||
fn id_start(&self) -> ID;
|
||||
}
|
||||
|
||||
pub trait HasIdSpan: HasId + HasLength {
|
||||
fn id_end(&self) -> ID {
|
||||
self.id_start().inc(self.len() as i32)
|
||||
}
|
||||
|
||||
fn id_last(&self) -> ID {
|
||||
self.id_start().inc(self.len() as i32 - 1)
|
||||
}
|
||||
}
|
||||
impl<T: HasId + HasLength> HasIdSpan for T {}
|
||||
|
||||
impl HasId for IdSpan {
|
||||
#[inline]
|
||||
fn id_start(&self) -> ID {
|
||||
self.min_id()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_id_span {
|
||||
use rle::RleVec;
|
||||
|
|
Loading…
Reference in a new issue