insert the element in the subtree rooted at h
(h: Option<NonNull<Node<K, V>>>, key: K, val: V)
| 199 | |
| 200 | /// insert the element in the subtree rooted at h |
| 201 | fn put<K, V>(h: Option<NonNull<Node<K, V>>>, key: K, val: V) -> Option<NonNull<Node<K, V>>> |
| 202 | where |
| 203 | K: Ord, |
| 204 | { |
| 205 | let mut h = NodeQuery::new(h); |
| 206 | |
| 207 | match h.get_key() { |
| 208 | None => return Some(Node::new_leaf(key, Some(val), None)), |
| 209 | Some(h_key) => match key.cmp(h_key) { |
| 210 | Ordering::Equal => h.set_entry((key, Some(val))), // update val |
| 211 | Ordering::Less => h.set_left(put(h.left().node, key, val)), |
| 212 | Ordering::Greater => h.set_right(put(h.right().node, key, val)), |
| 213 | }, |
| 214 | } |
| 215 | |
| 216 | balance(h.node) |
| 217 | } |
| 218 | |
| 219 | /// delete the min element rooted at h |
| 220 | fn del_min<K, V>(h: Option<NonNull<Node<K, V>>>) -> Option<NonNull<Node<K, V>>> { |