MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / remove

Method remove

crates/table/src/pointer_map.rs:285–318  ·  view source on GitHub ↗

Removes the association `hash -> ptr`. Returns whether the association was deleted.

(&mut self, hash: RowHash, ptr: RowPointer)

Source from the content-addressed store, hash-verified

283 ///
284 /// Returns whether the association was deleted.
285 pub fn remove(&mut self, hash: RowHash, ptr: RowPointer) -> bool {
286 'fun: {
287 let Entry::Occupied(mut entry) = self.map.entry(hash) else {
288 break 'fun false;
289 };
290
291 match entry.get().unpack() {
292 // Remove entry on `hash -> [ptr]`.
293 MapSlotRef::Pointer(o) if *o == ptr => drop(entry.remove()),
294 MapSlotRef::Pointer(_) => break 'fun false,
295 MapSlotRef::Collider(ci) => {
296 // Find `ptr` in slot and remove.
297 let slot = &mut self.colliders[ci.idx()];
298 let Some(idx) = slot.iter().position(|o| *o == ptr) else {
299 break 'fun false;
300 };
301 slot.swap_remove(idx);
302
303 match slot.len() {
304 // SAFETY: This never happens per `self.maintains_collider_invariant()`.
305 0 => unsafe { hint::unreachable_unchecked() },
306 // Simplify; don't use collider list since `hash -> [a_ptr]`.
307 1 => *entry.get_mut() = PtrOrCollider::ptr(slot.pop().unwrap()),
308 _ => break 'fun true,
309 }
310
311 // Slot is now empty; reuse later.
312 self.emptied_collider_slots.push(ci);
313 }
314 }
315
316 true
317 }
318 }
319
320 /// Returns an iterator over all row hash x row pointer pairs.
321 pub fn iter(&self) -> impl '_ + Iterator<Item = (RowHash, RowPointer)> {

Callers 15

find_result_jsonFunction · 0.45
gather_docs_filesFunction · 0.45
sanitize_db_nameFunction · 0.45
sanitize_for_commitMethod · 0.45
move_agentFunction · 0.45
derive_updatesMethod · 0.45
handle_deleteMethod · 0.45
remove_rowMethod · 0.45
remove_on_insertMethod · 0.45
remove_on_deleteMethod · 0.45
remove_on_updateMethod · 0.45
pop_call_infoMethod · 0.45

Calls 10

entryMethod · 0.80
positionMethod · 0.80
iterMethod · 0.65
unpackMethod · 0.45
getMethod · 0.45
idxMethod · 0.45
lenMethod · 0.45
get_mutMethod · 0.45
unwrapMethod · 0.45
pushMethod · 0.45

Tested by 2

test_config_editsFunction · 0.36
test_projectFunction · 0.36