diff options
| author | Crozet Sébastien <developer@crozet.re> | 2021-02-04 17:12:40 +0100 |
|---|---|---|
| committer | Crozet Sébastien <developer@crozet.re> | 2021-02-04 17:12:40 +0100 |
| commit | 09b867d0be5378f249a3dc4722527ed2e0233645 (patch) | |
| tree | 9c5ae3c2e389c988338e697bd5471c1bbd3035f9 /src/data | |
| parent | 822f0d81bf2fbcb3a7f0733ce9bf24569a591bf7 (diff) | |
| download | rapier-09b867d0be5378f249a3dc4722527ed2e0233645.tar.gz rapier-09b867d0be5378f249a3dc4722527ed2e0233645.tar.bz2 rapier-09b867d0be5378f249a3dc4722527ed2e0233645.zip | |
Experiment with incremental island having only one awake island.
Diffstat (limited to 'src/data')
| -rw-r--r-- | src/data/coarena.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/data/coarena.rs b/src/data/coarena.rs index 78cbfa7..6cdfbde 100644 --- a/src/data/coarena.rs +++ b/src/data/coarena.rs @@ -29,6 +29,27 @@ impl<T> Coarena<T> { .and_then(|(gg, t)| if g == *gg { Some(t) } else { None }) } + pub fn ensure_element_exists(&mut self, index: Index, default: T) -> &mut T + where + T: Clone, + { + let (i1, g1) = index.into_raw_parts(); + + let elt1 = { + if self.data.len() <= i1 { + self.data.resize(i1 + 1, (u32::MAX as u64, default.clone())); + } + + &mut self.data[i1] + }; + + if elt1.0 != g1 { + *elt1 = (g1, default); + } + + &mut elt1.1 + } + /// Ensure that elements at the two given indices exist in this coarena, and return their reference. /// /// Missing elements are created automatically and initialized with the `default` value. @@ -69,3 +90,16 @@ impl<T> Coarena<T> { (&mut elt1.1, &mut elt2.1) } } + +impl<T> std::ops::Index<Index> for Coarena<T> { + type Output = T; + fn index(&self, id: Index) -> &T { + self.get(id).expect("Index out of bounds.") + } +} + +impl<T> std::ops::IndexMut<Index> for Coarena<T> { + fn index_mut(&mut self, id: Index) -> &mut T { + self.get_mut(id).expect("Index out of bounds.") + } +} |
