mirror of
https://github.com/loro-dev/loro.git
synced 2025-02-06 12:25:03 +00:00
fix: lookup change
This commit is contained in:
parent
1743f4af42
commit
f0266f015f
2 changed files with 10 additions and 7 deletions
|
@ -101,9 +101,13 @@ impl LogStore {
|
|||
|
||||
#[inline]
|
||||
pub fn lookup_change(&self, id: ID) -> Option<&Change> {
|
||||
self.changes
|
||||
.get(&id.client_id)
|
||||
.map(|changes| changes.get(id.counter as usize).unwrap().element)
|
||||
self.changes.get(&id.client_id).and_then(|changes| {
|
||||
if id.counter <= changes.last().unwrap().id_last().counter {
|
||||
Some(changes.get(id.counter as usize).unwrap().element)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn export(&self, remote_vv: &VersionVector) -> FxHashMap<ClientID, Vec<Change<RemoteOp>>> {
|
||||
|
|
|
@ -374,10 +374,9 @@ pub(crate) fn get_lamport_by_deps(
|
|||
) -> Result<Lamport, ClientID> {
|
||||
let mut ans = Vec::new();
|
||||
for id in deps.iter() {
|
||||
if let Some(c) = store.and_then(|x|x.lookup_change(*id)) {
|
||||
let offset = id.counter - c.id.counter;
|
||||
ans.push(c.lamport + offset as u32);
|
||||
}
|
||||
if let Some(c) = store.and_then(|x| x.lookup_change(*id)) {
|
||||
let offset = id.counter - c.id.counter;
|
||||
ans.push(c.lamport + offset as u32);
|
||||
} else if let Some(v) = lamport_map.get(&id.client_id) {
|
||||
if let Some((lamport, offset)) = get_value_from_range_map(v, id.counter) {
|
||||
ans.push(lamport + offset);
|
||||
|
|
Loading…
Reference in a new issue