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