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

Method register_entity

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

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