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

Method remove

cranelift/entity/src/sparse.rs:167–185  ·  view source on GitHub ↗

Remove a value from the map and return it.

(&mut self, key: K)

Source from the content-addressed store, hash-verified

165
166 /// Remove a value from the map and return it.
167 pub fn remove(&mut self, key: K) -> Option<V> {
168 if let Some(idx) = self.index(key) {
169 let back = self.dense.pop().unwrap();
170
171 // Are we popping the back of `dense`?
172 if idx == self.dense.len() {
173 return Some(back);
174 }
175
176 // We're removing an element from the middle of `dense`.
177 // Replace the element at `idx` with the back of `dense`.
178 // Repair `sparse` first.
179 self.sparse[back.key()] = idx as u32;
180 return Some(mem::replace(&mut self.dense[idx], back));
181 }
182
183 // Nothing to remove.
184 None
185 }
186
187 /// Remove the last value from the map.
188 pub fn pop(&mut self) -> Option<V> {

Callers

nothing calls this directly

Calls 6

replaceFunction · 0.50
indexMethod · 0.45
unwrapMethod · 0.45
popMethod · 0.45
lenMethod · 0.45
keyMethod · 0.45

Tested by

no test coverage detected