MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / insert

Method insert

nodedb/src/engine/kv/sorted_index/tree.rs:70–85  ·  view source on GitHub ↗

Insert a new entry. If the primary key already exists, updates its sort key. Returns `true` if this was a new insert, `false` if it was an update.

(&mut self, sort_key: Vec<u8>, primary_key: Vec<u8>)

Source from the content-addressed store, hash-verified

68 ///
69 /// Returns `true` if this was a new insert, `false` if it was an update.
70 pub fn insert(&mut self, sort_key: Vec<u8>, primary_key: Vec<u8>) -> bool {
71 // If primary key already exists with a different sort key, remove first.
72 if let Some(old_sort) = self.key_to_sort.get(&primary_key) {
73 if *old_sort == sort_key {
74 return false; // Same sort key, nothing to do.
75 }
76 let old_sort = old_sort.clone();
77 self.remove_by_composite(&old_sort, &primary_key);
78 }
79
80 self.key_to_sort
81 .insert(primary_key.clone(), sort_key.clone());
82 let new_root = self.avl_insert(self.root, sort_key, primary_key);
83 self.root = new_root;
84 true
85 }
86
87 /// Remove an entry by primary key. Returns `true` if found and removed.
88 pub fn remove(&mut self, primary_key: &[u8]) -> bool {

Callers 14

multiple_inserts_orderedFunction · 0.45
top_kFunction · 0.45
update_existing_keyFunction · 0.45
removeFunction · 0.45
range_queryFunction · 0.45
avl_balance_maintainedFunction · 0.45
windowed_rangeFunction · 0.45
registerMethod · 0.45
on_putMethod · 0.45

Calls 4

remove_by_compositeMethod · 0.80
avl_insertMethod · 0.80
getMethod · 0.45
cloneMethod · 0.45

Tested by 9

multiple_inserts_orderedFunction · 0.36
top_kFunction · 0.36
update_existing_keyFunction · 0.36
removeFunction · 0.36
range_queryFunction · 0.36
avl_balance_maintainedFunction · 0.36