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)
| 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) |