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

Method register_entity

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

875 /// Creates INTERNAL (hash → id), EXTERNAL (id → hash), and NODE_TYPES (id → type)
876 /// entries. Returns existing id if already registered.
877 fn register_entity(&mut self, hash: &Hash, entity_type: u8) -> PristineResult<NodeId> {
878 // Check if already registered
879 {
880 let table = self.txn.open_table(INTERNAL)?;
881 let result = table.get(hash.as_bytes())?;
882 if let Some(value) = result {
883 return Ok(NodeId::new(value.value()));
884 }
885 }
886
887 // Allocate a new ID
888 let id = self.next_node_id.fetch_add(1, Ordering::SeqCst);
889 let node_id = NodeId::new(id);
890
891 // Insert into both tables
892 {
893 let mut external = self.txn.open_table(EXTERNAL)?;
894 external.insert(id, hash.as_bytes())?;
895 }
896 {
897 let mut internal = self.txn.open_table(INTERNAL)?;
898 internal.insert(hash.as_bytes(), id)?;
899 }
900 {
901 let mut node_types = self.txn.open_table(NODE_TYPES)?;
902 node_types.insert(id, entity_type)?;
903 }
904
905 Ok(node_id)
906 }
907}
908
909// 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