/// # Panics
///
/// Panics if the generation counter is even, as that would reference an empty slot.
+ #[inline(always)]
fn encode(encode_multiplier: u32, generation: u32, slot_index: SlotIndex) -> Self {
assert!(generation & 1 == 1);
}
impl Slot {
+ #[inline(always)]
const fn new() -> Self {
Self {
// Clear the generation counter, but leave the index bits set.
}
/// Extract the current generation counter from this slot.
+ #[inline(always)]
fn generation(&self) -> u32 {
(self.value_index_and_gen >> GEN_SHIFT) & GEN_MASK
}
/// Extract the current value index from this slot.
+ #[inline(always)]
fn value_index(&self) -> ValueIndex {
ValueIndex((self.value_index_and_gen >> IDX_SHIFT) & IDX_MASK)
}
/// Updates the slot's value index without modifying the generation.
+ #[inline(always)]
fn update_value_index(&mut self, value_index: ValueIndex) {
debug_assert!(value_index.0 & IDX_MASK == value_index.0);
self.value_index_and_gen =
}
/// Sets the slot's value index, incrementing the generation counter.
+ #[inline(always)]
fn set_value_index(&mut self, value_index: ValueIndex) {
let new_generation = self.generation().wrapping_add(1);
self.value_index_and_gen =
}
/// Clears the slot's value index, incrementing the generation counter.
+ #[inline(always)]
fn clear_value_index(&mut self) {
// Since we're clearing we need to reset the generation to one referencing an empty slot. But we still want to
// invalidate old handles.
Self { len: 0, ptr }
}
+ #[inline(always)]
fn get(&self, slot_index: SlotIndex) -> Option<&Slot> {
let index = slot_index.0 as usize;
if index < self.len {
}
}
+ #[inline(always)]
fn get_mut(&mut self, slot_index: SlotIndex) -> Option<&mut Slot> {
let index = slot_index.0 as usize;
if index < self.len {
}
/// Update the lookup table for the given `ValueIndex` with a new `SlotIndex`
+ #[inline(always)]
fn set_slot(&mut self, value_index: ValueIndex, slot_index: SlotIndex) {
let value_index = value_index.0 as usize;
assert!(value_index < self.len);
}
/// Retreive the `SlotIndex` corresponding to the given `ValueIndex` from the lookup table.
+ #[inline(always)]
fn get_slot(&mut self, value_index: ValueIndex) -> SlotIndex {
let value_index = value_index.0 as usize;
assert!(value_index < self.len);
}
/// Push a new value into the values storage. Returns the index of the added value.
+ #[inline(always)]
fn push(&mut self, value: T) -> ValueIndex {
if self.len == self.cap {
self.grow();
/// the lookup tables for the moved element.
///
/// Returns the removed value.
+ #[inline(always)]
fn swap_remove(&mut self, value_index: ValueIndex, slots: &mut Slots) -> T {
let last_value_index = ValueIndex((self.len - 1) as u32);
/// Retreive a reference to the value at `value_index`
/// Panics if `value_index` is out of bounds
+ #[inline(always)]
fn get(&self, value_index: ValueIndex) -> &T {
let value_index = value_index.0 as usize;
assert!(value_index < self.len);
/// Retreive a mutable reference to the value at `value_index`
/// Panics if `value_index` is out of bounds
+ #[inline(always)]
fn get_mut(&mut self, value_index: ValueIndex) -> &mut T {
let value_index = value_index.0 as usize;
assert!(value_index < self.len);
fn mul(self, rhs: Self) -> Self::Output {
let mut result = Mat3::IDENTITY;
{
- let result = result.as_rows_mut();
let lhs = self.as_rows();
let rhs = rhs.as_rows();
- for i in 0..3 {
- for j in 0..3 {
- result[i][j] =
- lhs[i][0] * rhs[0][j] + lhs[i][1] * rhs[1][j] + lhs[i][2] * rhs[2][j];
- }
- }
+ let result = result.as_rows_mut();
+
+ result[0][0] = lhs[0][0] * rhs[0][0] + lhs[0][1] * rhs[1][0] + lhs[0][2] * rhs[2][0];
+ result[0][1] = lhs[0][0] * rhs[0][1] + lhs[0][1] * rhs[1][1] + lhs[0][2] * rhs[2][1];
+ result[0][2] = lhs[0][0] * rhs[0][2] + lhs[0][1] * rhs[1][2] + lhs[0][2] * rhs[2][2];
+
+ result[1][0] = lhs[1][0] * rhs[0][0] + lhs[1][1] * rhs[1][0] + lhs[1][2] * rhs[2][0];
+ result[1][1] = lhs[1][0] * rhs[0][1] + lhs[1][1] * rhs[1][1] + lhs[1][2] * rhs[2][1];
+ result[1][2] = lhs[1][0] * rhs[0][2] + lhs[1][1] * rhs[1][2] + lhs[1][2] * rhs[2][2];
+
+ result[2][0] = lhs[2][0] * rhs[0][0] + lhs[2][1] * rhs[1][0] + lhs[2][2] * rhs[2][0];
+ result[2][1] = lhs[2][0] * rhs[0][1] + lhs[2][1] * rhs[1][1] + lhs[2][2] * rhs[2][1];
+ result[2][2] = lhs[2][0] * rhs[0][2] + lhs[2][1] * rhs[1][2] + lhs[2][2] * rhs[2][2];
}
result
}