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

Method register_entity

atomic-core/src/pristine/txn/write/mod.rs:309–338  ·  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

307 /// Creates INTERNAL (hash → id), EXTERNAL (id → hash), and NODE_TYPES (id → type)
308 /// entries. Returns existing id if already registered.
309 fn register_entity(&mut self, hash: &Hash, entity_type: u8) -> PristineResult<NodeId> {
310 // Check if already registered
311 {
312 let table = self.txn.open_table(INTERNAL)?;
313 let result = table.get(hash.as_bytes())?;
314 if let Some(value) = result {
315 return Ok(NodeId::new(value.value()));
316 }
317 }
318
319 // Allocate a new ID
320 let id = self.next_node_id.fetch_add(1, Ordering::SeqCst);
321 let node_id = NodeId::new(id);
322
323 // Insert into both tables
324 {
325 let mut external = self.txn.open_table(EXTERNAL)?;
326 external.insert(id, hash.as_bytes())?;
327 }
328 {
329 let mut internal = self.txn.open_table(INTERNAL)?;
330 internal.insert(hash.as_bytes(), id)?;
331 }
332 {
333 let mut node_types = self.txn.open_table(NODE_TYPES)?;
334 node_types.insert(id, entity_type)?;
335 }
336
337 Ok(node_id)
338 }
339}
340
341// 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 3

getMethod · 0.65
as_bytesMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected