This bool represents whether the key was found in the map or not.
(&self, k: K, f: F)
| 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 |