mirror of
https://github.com/loro-dev/loro.git
synced 2025-02-06 12:25:03 +00:00
fix: simplify op set
This commit is contained in:
parent
3eff9a2091
commit
bc57f01e18
1 changed files with 12 additions and 12 deletions
|
@ -1,5 +1,5 @@
|
|||
#![allow(unused)]
|
||||
use std::ptr::NonNull;
|
||||
use std::{ops::Range, ptr::NonNull};
|
||||
|
||||
use crdt_list::{
|
||||
crdt::{GetOp, ListCrdt, OpSet},
|
||||
|
@ -7,7 +7,7 @@ use crdt_list::{
|
|||
};
|
||||
use rle::{
|
||||
range_map::{RangeMap, WithStartEnd},
|
||||
rle_tree::{iter::IterMut, node::LeafNode, SafeCursorMut},
|
||||
rle_tree::{iter::IterMut, node::LeafNode, BumpMode, SafeCursorMut},
|
||||
HasLength,
|
||||
};
|
||||
|
||||
|
@ -22,23 +22,23 @@ use super::{
|
|||
// TODO: may use a simpler data structure here
|
||||
#[derive(Default, Debug)]
|
||||
pub struct OpSpanSet {
|
||||
map: RangeMap<u128, WithStartEnd<u128, bool>>,
|
||||
map: Vec<Range<u128>>,
|
||||
}
|
||||
|
||||
impl OpSet<YSpan, ID> for OpSpanSet {
|
||||
fn insert(&mut self, value: &YSpan) {
|
||||
self.map.set_small_range(
|
||||
value.id.into(),
|
||||
WithStartEnd {
|
||||
start: value.id.into(),
|
||||
end: value.id.inc(value.atom_len() as i32).into(),
|
||||
value: true,
|
||||
},
|
||||
)
|
||||
let start: u128 = value.id.into();
|
||||
self.map.push(start..start + value.atom_len() as u128);
|
||||
}
|
||||
|
||||
fn contain(&self, id: ID) -> bool {
|
||||
self.map.has(id.into())
|
||||
for range in &self.map {
|
||||
if range.contains(&(id.into())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
fn clear(&mut self) {
|
||||
|
|
Loading…
Reference in a new issue