MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / put_leaf

Method put_leaf

atomic-core/tests/crdt_integration_test.rs:190–206  ·  view source on GitHub ↗
(&mut self, leaf: &Leaf, after: Option<LeafId>)

Source from the content-addressed store, hash-verified

188 }
189
190 fn put_leaf(&mut self, leaf: &Leaf, after: Option<LeafId>) -> Result<bool, Self::Error> {
191 let id = leaf.id();
192 let is_new = !self.leaves.contains_key(&id);
193 self.leaves.insert(id, leaf.clone());
194
195 let leaves = self.branch_leaves.entry(leaf.branch()).or_default();
196 if let Some(after_id) = after {
197 if let Some(pos) = leaves.iter().position(|l| *l == after_id) {
198 leaves.insert(pos + 1, id);
199 } else {
200 leaves.push(id);
201 }
202 } else {
203 leaves.insert(0, id);
204 }
205 Ok(is_new)
206 }
207
208 fn get_leaf(&self, id: LeafId) -> Result<Option<Leaf>, Self::Error> {
209 Ok(self.leaves.get(&id).cloned())

Callers

nothing calls this directly

Calls 8

contains_keyMethod · 0.80
idMethod · 0.45
insertMethod · 0.45
cloneMethod · 0.45
branchMethod · 0.45
positionMethod · 0.45
iterMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected