MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / register_entity

Method register_entity

atomic-core/src/pristine/txn/write/mod.rs:1136–1171  ·  view source on GitHub ↗

Register an entity in the identity tables. Creates INTERNAL (hash → id), EXTERNAL (id → hash), and NODE_TYPES (id → type) entries. Returns existing id if already registered.

(&mut self, hash: &Hash, entity_type: u8)

Source from the content-addressed store, hash-verified

1134 /// Creates INTERNAL (hash → id), EXTERNAL (id → hash), and NODE_TYPES (id → type)
1135 /// entries. Returns existing id if already registered.
1136 fn register_entity(&mut self, hash: &Hash, entity_type: u8) -> PristineResult<NodeId> {
1137 // Check if already registered
1138 {
1139 let table = self.txn.open_table(INTERNAL)?;
1140 let result = table.get(hash.as_bytes())?;
1141 if let Some(value) = result {
1142 return Ok(NodeId::new(value.value()));
1143 }
1144 }
1145
1146 // Allocate a new ID
1147 let id = if let Some((next, _, _)) = &mut self.preview_allocations {
1148 let id = *next;
1149 *next = next.checked_add(1).ok_or(PristineError::IdSpaceExhausted)?;
1150 id
1151 } else {
1152 self.next_node_id.fetch_add(1, Ordering::SeqCst)
1153 };
1154 let node_id = NodeId::new(id);
1155
1156 // Insert into both tables
1157 {
1158 let mut external = self.txn.open_table(EXTERNAL)?;
1159 external.insert(id, hash.as_bytes())?;
1160 }
1161 {
1162 let mut internal = self.txn.open_table(INTERNAL)?;
1163 internal.insert(hash.as_bytes(), id)?;
1164 }
1165 {
1166 let mut node_types = self.txn.open_table(NODE_TYPES)?;
1167 node_types.insert(id, entity_type)?;
1168 }
1169
1170 Ok(node_id)
1171 }
1172}
1173
1174// MutTxnT Implementation

Callers 5

put_tagMethod · 0.80
register_changeMethod · 0.80
register_tagMethod · 0.80
register_attestationMethod · 0.80
register_provenanceMethod · 0.80

Calls 4

valueMethod · 0.80
getMethod · 0.65
as_bytesMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected