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

Method register_entity

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

780 /// Creates INTERNAL (hash → id), EXTERNAL (id → hash), and NODE_TYPES (id → type)
781 /// entries. Returns existing id if already registered.
782 fn register_entity(&mut self, hash: &Hash, entity_type: u8) -> PristineResult<NodeId> {
783 // Check if already registered
784 {
785 let table = self.txn.open_table(INTERNAL)?;
786 let result = table.get(hash.as_bytes())?;
787 if let Some(value) = result {
788 return Ok(NodeId::new(value.value()));
789 }
790 }
791
792 // Allocate a new ID
793 let id = self.next_node_id.fetch_add(1, Ordering::SeqCst);
794 let node_id = NodeId::new(id);
795
796 // Insert into both tables
797 {
798 let mut external = self.txn.open_table(EXTERNAL)?;
799 external.insert(id, hash.as_bytes())?;
800 }
801 {
802 let mut internal = self.txn.open_table(INTERNAL)?;
803 internal.insert(hash.as_bytes(), id)?;
804 }
805 {
806 let mut node_types = self.txn.open_table(NODE_TYPES)?;
807 node_types.insert(id, entity_type)?;
808 }
809
810 Ok(node_id)
811 }
812}
813
814// 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