MCPcopy Create free account
hub / github.com/cosdata/cosdata / modify_or_insert_with_value

Method modify_or_insert_with_value

src/models/common.rs:585–600  ·  view source on GitHub ↗

works exactly like `modify_or_insert`, but takes a value `T`, which is passed to both closures (only one actually runs, so only passed to one of them), which is not possible with `modify_or_insert` because of Rust's borrow checking rules

(&self, k: K, v: T, modify: M, insert: I)

Source from the content-addressed store, hash-verified

583 // closures (only one actually runs, so only passed to one of them), which is not possible
584 // with `modify_or_insert` because of Rust's borrow checking rules
585 pub fn modify_or_insert_with_value<M, I, T>(&self, k: K, v: T, modify: M, insert: I)
586 where
587 M: FnOnce(T, &mut V),
588 I: FnOnce(T) -> V,
589 {
590 let index = self.hash_key(&k);
591 let mut ht = self.hash_table_list[index].lock().unwrap();
592 match ht.entry(k) {
593 Entry::Occupied(mut entry) => {
594 modify(v, entry.get_mut());
595 }
596 Entry::Vacant(entry) => {
597 entry.insert(insert(v));
598 }
599 }
600 }
601
602 // This bool represents whether the key was found in the map or not.
603 pub fn get_or_create_with_flag<F>(&self, k: K, f: F) -> (V, bool)

Callers 2

insertMethod · 0.80
pushMethod · 0.80

Calls 2

hash_keyMethod · 0.80
insertMethod · 0.45

Tested by

no test coverage detected