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