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

Method get_or_try_create_with_flag

src/models/common.rs:621–636  ·  view source on GitHub ↗

This bool represents whether the key was found in the map or not.

(&self, k: K, f: F)

Source from the content-addressed store, hash-verified

619
620 // This bool represents whether the key was found in the map or not.
621 pub fn get_or_try_create_with_flag<F, E>(&self, k: K, f: F) -> Result<(V, bool), E>
622 where
623 F: FnOnce() -> Result<V, E>,
624 V: Clone,
625 {
626 let index = self.hash_key(&k);
627 let mut ht = self.hash_table_list[index].lock().unwrap();
628 match ht.get(&k) {
629 Some(v) => Ok((v.clone(), true)),
630 None => {
631 let new_v = f()?;
632 ht.insert(k, new_v.clone());
633 Ok((new_v, false))
634 }
635 }
636 }
637
638 pub fn lock_key_and_try<F, R>(&self, k: K, f: F) -> R
639 where

Callers

nothing calls this directly

Calls 4

hash_keyMethod · 0.80
cloneMethod · 0.80
getMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected