MCPcopy Index your code
hub / github.com/RustPython/RustPython / delete_or_insert

Method delete_or_insert

crates/vm/src/dict_inner.rs:491–512  ·  view source on GitHub ↗
(&self, vm: &VirtualMachine, key: &PyObject, value: T)

Source from the content-addressed store, hash-verified

489 }
490
491 pub fn delete_or_insert(&self, vm: &VirtualMachine, key: &PyObject, value: T) -> PyResult<()> {
492 let hash = key.key_hash(vm)?;
493 let _removed = loop {
494 let lookup = self.lookup(vm, key, hash, None)?;
495 let (entry, index_index) = lookup;
496 if entry.index().is_some() {
497 match self.pop_inner(lookup) {
498 ControlFlow::Break(Some(entry)) => break Some(entry),
499 _ => continue,
500 }
501 } else {
502 let mut inner = self.write();
503 if inner.indices.get(index_index) != Some(&entry) {
504 continue;
505 }
506 inner.unchecked_push(index_index, hash, key.to_owned(), value, entry);
507 self.bump_version();
508 break None;
509 }
510 };
511 Ok(())
512 }
513
514 pub fn setdefault<K, F>(&self, vm: &VirtualMachine, key: &K, default: F) -> PyResult<T>
515 where

Callers 2

symmetric_differenceMethod · 0.80

Calls 10

key_hashMethod · 0.80
pop_innerMethod · 0.80
unchecked_pushMethod · 0.80
bump_versionMethod · 0.80
SomeClass · 0.50
lookupMethod · 0.45
indexMethod · 0.45
writeMethod · 0.45
getMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected