mirror of
https://github.com/loro-dev/loro.git
synced 2025-02-06 12:25:03 +00:00
feat: add contains
This commit is contained in:
parent
99278b1e22
commit
b30dee1386
3 changed files with 18 additions and 1 deletions
|
@ -254,6 +254,11 @@ impl ContainerRegistry {
|
|||
.map(|x| Arc::downgrade(&self.containers[x.0 as usize].container))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn contains(&self, id: &ContainerID) -> bool {
|
||||
self.container_to_idx.contains_key(id)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn get_by_idx(&self, idx: ContainerIdx) -> Option<&Arc<Mutex<ContainerInstance>>> {
|
||||
self.containers.get(idx.0 as usize).map(|x| &x.container)
|
||||
|
|
|
@ -265,7 +265,12 @@ impl LogStore {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn contains(&self, id: ID) -> bool {
|
||||
pub fn contains_container(&self, id: &ContainerID) -> bool {
|
||||
self.reg.contains(id)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn contains_id(&self, id: ID) -> bool {
|
||||
self.changes
|
||||
.get(&id.client_id)
|
||||
.map_or(0, |changes| changes.atom_len())
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use std::sync::{Arc, Mutex, RwLock};
|
||||
|
||||
use crate::{
|
||||
container::ContainerID,
|
||||
dag::DagUtils,
|
||||
event::RawEvent,
|
||||
hierarchy::Hierarchy,
|
||||
log_store::{EncodeConfig, LoroEncoder},
|
||||
|
@ -73,6 +75,11 @@ impl LoroCore {
|
|||
Text::from_instance(instance, cid)
|
||||
}
|
||||
|
||||
pub fn contains(&self, id: &ContainerID) -> bool {
|
||||
let store = self.log_store.try_read().unwrap();
|
||||
store.contains_container(id)
|
||||
}
|
||||
|
||||
// TODO: make it private
|
||||
pub fn export(&self, remote_vv: VersionVector) -> FxHashMap<u64, Vec<Change<RemoteOp>>> {
|
||||
let store = self.log_store.read().unwrap();
|
||||
|
|
Loading…
Reference in a new issue