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

Method get_or_create_with_flag

src/models/common.rs:603–618  ·  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

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)
604 where
605 F: FnOnce() -> V,
606 V: Clone,
607 {
608 let index = self.hash_key(&k);
609 let mut ht = self.hash_table_list[index].lock().unwrap();
610 match ht.get(&k) {
611 Some(v) => (v.clone(), true),
612 None => {
613 let new_v = f();
614 ht.insert(k, new_v.clone());
615 (new_v, false)
616 }
617 }
618 }
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>

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