Insert a node and return its current slot/generation id. Reuses a free slot when available. Otherwise appends a new slot.
(&mut self, node: SceneNode)
| 151 | |
| 152 | /// Create an empty arena. |
| 153 | /// |
| 154 | /// Slot 0 is reserved as the nil sentinel, so the first inserted node uses |
| 155 | /// index 1. |
| 156 | pub fn new() -> Self { |
| 157 | // Reserve index 0 as invalid/nil sentinel so first real node ID is 1. |
| 158 | let mut nodes = Vec::with_capacity(2); |
| 159 | let mut generations = Vec::with_capacity(2); |
| 160 | nodes.push(None); |
| 161 | generations.push(0); |
| 162 | Self { |
| 163 | nodes, |
| 164 | generations, |
| 165 | node_types: vec![NodeType::Node], |
| 166 | parents: vec![NodeID::nil()], |
| 167 | packed_child_offsets: vec![0, 0], |
| 168 | packed_child_ids: Vec::new(), |
| 169 | packed_children_revision: 0, |
| 170 | free_indices: Vec::new(), |
| 171 | name_index: AHashMap::default(), |
| 172 | tag_index: AHashMap::default(), |
| 173 | active_len: 0, |
| 174 | mutation_revision: 0, |
| 175 | physics_revision: 0, |
| 176 | structural_revision: 0, |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | /// Create an empty arena with capacity for active nodes. |
| 181 | /// |
| 182 | /// The internal vectors reserve one extra slot for the nil sentinel. |
| 183 | pub fn with_capacity(capacity: usize) -> Self { |
| 184 | // +1 for reserved nil sentinel slot at index 0. |
| 185 | let mut nodes = Vec::with_capacity(capacity.saturating_add(1)); |
| 186 | let mut generations = Vec::with_capacity(capacity.saturating_add(1)); |
| 187 | nodes.push(None); |