MCPcopy Index your code
hub / github.com/endbasic/endbasic / insert

Method insert

core/src/compiler/ids.rs:66–81  ·  view source on GitHub ↗

Inserts the `key`/`value` pair into the hash map, assigning a new identifier to the `key` if it does not yet have one. If the `key` is already present, returns a pair with the previous value and the already assigned identifier. If the `keys` is not yet present, returns a pair with None and the newly-assigned identifier. Returns `None` when the IDs run out.

(&mut self, key: K, value: V)

Source from the content-addressed store, hash-verified

64 ///
65 /// Returns `None` when the IDs run out.
66 pub(super) fn insert(&mut self, key: K, value: V) -> Option<(Option<V>, I)> {
67 let id = match self.map.get(&key) {
68 Some((_value, id)) => *id,
69 None => match I::try_from(self.map.len()) {
70 Ok(id) => id,
71 Err(_) => return None,
72 },
73 };
74 self.map
75 .insert(key, (value, id))
76 .map(|(prev_value, prev_id)| {
77 debug_assert_eq!(prev_id, id);
78 (Some(prev_value), id)
79 })
80 .or(Some((None, id)))
81 }
82
83 /// Returns the number of assigned identifiers.
84 pub(super) fn len(&self) -> usize {

Callers 15

default_headersMethod · 0.45
get_file_aclsMethod · 0.45
patch_file_contentMethod · 0.45
enumerateMethod · 0.45
newMethod · 0.45
add_fixupMethod · 0.45
get_constantMethod · 0.45
define_user_callableMethod · 0.45
define_labelMethod · 0.45
get_upcallMethod · 0.45
build_image_deltaMethod · 0.45
compile_stmtFunction · 0.45

Calls 2

getMethod · 0.45
lenMethod · 0.45