MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / try_leaf_insert

Method try_leaf_insert

cranelift/bforest/src/node.rs:193–217  ·  view source on GitHub ↗

Try to insert `key, value` at `index` in a leaf node, but fail and return false if the node is full.

(&mut self, index: usize, key: F::Key, value: F::Value)

Source from the content-addressed store, hash-verified

191 /// Try to insert `key, value` at `index` in a leaf node, but fail and return false if the node
192 /// is full.
193 pub fn try_leaf_insert(&mut self, index: usize, key: F::Key, value: F::Value) -> bool {
194 match *self {
195 Self::Leaf {
196 ref mut size,
197 ref mut keys,
198 ref mut vals,
199 } => {
200 let sz = usize::from(*size);
201 let keys = keys.borrow_mut();
202 let vals = vals.borrow_mut();
203 debug_assert!(sz <= keys.len());
204 debug_assert!(index <= sz);
205
206 if let Some(ks) = keys.get_mut(0..=sz) {
207 *size = (sz + 1) as u8;
208 slice_insert(ks, index, key);
209 slice_insert(&mut vals[0..=sz], index, value);
210 true
211 } else {
212 false
213 }
214 }
215 _ => panic!("Expected leaf node"),
216 }
217 }
218
219 /// Split off the second half of this node.
220 /// It is assumed that this a completely full inner or leaf node.

Callers

nothing calls this directly

Calls 3

fromFunction · 0.85
slice_insertFunction · 0.85
get_mutMethod · 0.45

Tested by

no test coverage detected