Insert a new key-value pair, returning the old value associated with this key (if any).
(&mut self, k: K, v: V, ctx: &Ctx)
| 85 | /// Insert a new key-value pair, returning the old value associated |
| 86 | /// with this key (if any). |
| 87 | pub fn insert<Ctx>(&mut self, k: K, v: V, ctx: &Ctx) -> Option<V> |
| 88 | where |
| 89 | Ctx: CtxEq<K, K> + CtxHash<K>, |
| 90 | { |
| 91 | let hash = compute_hash(ctx, &k); |
| 92 | match self.raw.find_mut(hash as u64, |bucket| { |
| 93 | hash == bucket.hash && ctx.ctx_eq(&bucket.k, &k) |
| 94 | }) { |
| 95 | Some(bucket) => Some(core::mem::replace(&mut bucket.v, v)), |
| 96 | None => { |
| 97 | let data = BucketData { hash, k, v }; |
| 98 | self.raw |
| 99 | .insert_unique(hash as u64, data, |bucket| bucket.hash as u64); |
| 100 | None |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /// Look up a key, returning a borrow of the value if present. |
| 106 | pub fn get<'a, Q, Ctx>(&'a self, k: &Q, ctx: &Ctx) -> Option<&'a V> |
no test coverage detected