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

Method get_or_create

src/models/common.rs:555–570  ·  view source on GitHub ↗
(&self, k: K, f: F)

Source from the content-addressed store, hash-verified

553 }
554
555 pub fn get_or_create<F>(&self, k: K, f: F) -> V
556 where
557 F: FnOnce() -> V,
558 V: Clone,
559 {
560 let index = self.hash_key(&k);
561 let mut ht = self.hash_table_list[index].lock().unwrap();
562 match ht.get(&k) {
563 Some(v) => v.clone(),
564 None => {
565 let new_v = f();
566 ht.insert(k, new_v.clone());
567 new_v
568 }
569 }
570 }
571
572 pub fn modify_or_insert<M, I>(&self, k: K, modify: M, insert: I)
573 where

Callers 2

get_lazy_objectMethod · 0.80
get_dataMethod · 0.80

Calls 4

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

Tested by

no test coverage detected