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)
| 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 |
no test coverage detected