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)
| 307 | /// Creates INTERNAL (hash → id), EXTERNAL (id → hash), and NODE_TYPES (id → type) |
| 308 | /// entries. Returns existing id if already registered. |
| 309 | fn register_entity(&mut self, hash: &Hash, entity_type: u8) -> PristineResult<NodeId> { |
| 310 | // Check if already registered |
| 311 | { |
| 312 | let table = self.txn.open_table(INTERNAL)?; |
| 313 | let result = table.get(hash.as_bytes())?; |
| 314 | if let Some(value) = result { |
| 315 | return Ok(NodeId::new(value.value())); |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | // Allocate a new ID |
| 320 | let id = self.next_node_id.fetch_add(1, Ordering::SeqCst); |
| 321 | let node_id = NodeId::new(id); |
| 322 | |
| 323 | // Insert into both tables |
| 324 | { |
| 325 | let mut external = self.txn.open_table(EXTERNAL)?; |
| 326 | external.insert(id, hash.as_bytes())?; |
| 327 | } |
| 328 | { |
| 329 | let mut internal = self.txn.open_table(INTERNAL)?; |
| 330 | internal.insert(hash.as_bytes(), id)?; |
| 331 | } |
| 332 | { |
| 333 | let mut node_types = self.txn.open_table(NODE_TYPES)?; |
| 334 | node_types.insert(id, entity_type)?; |
| 335 | } |
| 336 | |
| 337 | Ok(node_id) |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | // MutTxnT Implementation |
no test coverage detected