loro/crates/delta/src/delta_trait.rs
Zixuan Chen 9d4f7aa8a3
DeltaRope (#327)
* feat: delta rope support init

* perf: use generic-btree v0.9.0

* refactor: improve readability and maintainability

* fix: fix several issues about composing

* fix: a few more issue about composing deletions

* test: rich text

* fix: cover more edge cases

* refactor: use deltarope for list event

* refactor: replace text delta with DeltaRope

* fix: list fuzz err

* fix: safety issue on insert_many

* chore: refine impl of text delta

* refactor: use Replace instead of insert+del in DeltaItem (#330)

* refactor: use Replace instead of insert+del in DeltaItem

* fix: each deltaitem should have non-zero rle_len
Updated generic-btree dependency to version 0.10.3 and refactored DeltaItem and DeltaRope implementations in loro-delta. Refine compose impl

* fix: update generic-btree to fix the update leaf issue

* chore: lockfile

* chore: clippy fix

* refactor: make composing easier to understand

* refactor: simplify the impl of composing
2024-04-24 13:53:26 +08:00

41 lines
1 KiB
Rust

use generic_btree::rle::{HasLength, Mergeable, Sliceable, TryInsert};
use std::hash::{BuildHasher, Hash};
use std::{collections::HashMap, fmt::Debug};
pub trait DeltaValue:
HasLength + Sliceable + Mergeable + TryInsert + Debug + Clone + Default
{
}
pub trait DeltaAttr: Clone + PartialEq + Debug + Default {
fn compose(&mut self, other: &Self);
fn attr_is_empty(&self) -> bool;
}
mod implementations {
use super::*;
impl DeltaAttr for () {
fn compose(&mut self, _other: &Self) {}
fn attr_is_empty(&self) -> bool {
true
}
}
impl<K, V, S> DeltaAttr for HashMap<K, V, S>
where
K: Eq + Hash + Debug + Clone,
V: Debug + PartialEq + Clone,
S: BuildHasher + Default + Clone,
{
fn compose(&mut self, other: &Self) {
for (key, value) in other {
self.insert(key.clone(), value.clone());
}
}
fn attr_is_empty(&self) -> bool {
self.is_empty()
}
}
}