fix: simplify op set

This commit is contained in:
Zixuan Chen 2022-12-08 23:03:01 +08:00
parent 3eff9a2091
commit bc57f01e18

View file

@ -1,5 +1,5 @@
#![allow(unused)] #![allow(unused)]
use std::ptr::NonNull; use std::{ops::Range, ptr::NonNull};
use crdt_list::{ use crdt_list::{
crdt::{GetOp, ListCrdt, OpSet}, crdt::{GetOp, ListCrdt, OpSet},
@ -7,7 +7,7 @@ use crdt_list::{
}; };
use rle::{ use rle::{
range_map::{RangeMap, WithStartEnd}, range_map::{RangeMap, WithStartEnd},
rle_tree::{iter::IterMut, node::LeafNode, SafeCursorMut}, rle_tree::{iter::IterMut, node::LeafNode, BumpMode, SafeCursorMut},
HasLength, HasLength,
}; };
@ -22,23 +22,23 @@ use super::{
// TODO: may use a simpler data structure here // TODO: may use a simpler data structure here
#[derive(Default, Debug)] #[derive(Default, Debug)]
pub struct OpSpanSet { pub struct OpSpanSet {
map: RangeMap<u128, WithStartEnd<u128, bool>>, map: Vec<Range<u128>>,
} }
impl OpSet<YSpan, ID> for OpSpanSet { impl OpSet<YSpan, ID> for OpSpanSet {
fn insert(&mut self, value: &YSpan) { fn insert(&mut self, value: &YSpan) {
self.map.set_small_range( let start: u128 = value.id.into();
value.id.into(), self.map.push(start..start + value.atom_len() as u128);
WithStartEnd {
start: value.id.into(),
end: value.id.inc(value.atom_len() as i32).into(),
value: true,
},
)
} }
fn contain(&self, id: ID) -> bool { 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) { fn clear(&mut self) {