pub struct ValueHeap { /* private fields */ }Implementations§
Source§impl ValueHeap
impl ValueHeap
pub fn new() -> Self
Sourcepub fn alloc(&mut self, len: u32, room: &mut Room) -> Range
pub fn alloc(&mut self, len: u32, room: &mut Room) -> Range
Allocates a range of at least len slots, filled with Value::EMPTY.
The returned length is rounded up to the class size. A growth step is
charged to room.
Sourcepub fn alloc_slots(&mut self, len: u32, room: &mut Room) -> Range
pub fn alloc_slots(&mut self, len: u32, room: &mut Room) -> Range
ValueHeap::alloc rounded to a power of two: an object’s named
property slots, which the header decodes with one shift.
Sourcepub fn growth_bytes(&self, len: u32) -> usize
pub fn growth_bytes(&self, len: u32) -> usize
Bytes the backing vector grows by if a range of len is allocated now.
Sourcepub fn grow(&mut self, range: Range, new_len: u32, room: &mut Room) -> Range
pub fn grow(&mut self, range: Range, new_len: u32, room: &mut Room) -> Range
Returns a range of at least new_len holding range’s values: the same
range when it is already large enough, otherwise a new one (alloc, copy,
free).
Sourcepub fn grow_slots(
&mut self,
range: Range,
new_len: u32,
room: &mut Room,
) -> Range
pub fn grow_slots( &mut self, range: Range, new_len: u32, room: &mut Room, ) -> Range
ValueHeap::grow for named property slots, to a power of two.
Sourcepub fn free(&mut self, range: Range)
pub fn free(&mut self, range: Range)
Returns a range to its class. The slots are poisoned with EMPTY.
Sourcepub fn begin_sweep(&mut self)
pub fn begin_sweep(&mut self)
Starts a collection’s sweep: the free space moves into the bitmap of
free slots, where ValueHeap::release records the ranges the sweep
frees, and ValueHeap::finish_sweep rebuilds it from the bitmap.
Sourcepub fn release(&mut self, range: Range)
pub fn release(&mut self, range: Range)
Frees a range during the sweep: poisons it with EMPTY and records it
in the bitmap of free slots.
Sourcepub fn finish_sweep(&mut self)
pub fn finish_sweep(&mut self)
Ends the sweep: rebuilds the free space from the maximal runs of free
slots. A run shorter than [SHORT_RUN] goes on the class lists, cut
from its start into the largest class ranges that fit (a run of seven
becomes ranges of six and one); a longer one becomes a free
run. A run that ends the heap and spans more than a quarter of its
capacity is cut off instead, and the capacity past one growth step
goes back to the allocator. Lower ranges and runs are reused first.
pub fn get(&self, range: Range, slot: u32) -> Value
pub fn set(&mut self, range: Range, slot: u32, value: Value)
Sourcepub fn get_or_empty(&self, range: Range, slot: u32) -> Value
pub fn get_or_empty(&self, range: Range, slot: u32) -> Value
The value at slot of range, or Value::EMPTY past its end.
Sourcepub fn get_at(&self, index: u32) -> Value
pub fn get_at(&self, index: u32) -> Value
An absolute slot; callers check the range in debug builds.
pub fn set_at(&mut self, index: u32, value: Value)
pub fn slice(&self, range: Range) -> &[Value]
pub fn slice_mut(&mut self, range: Range) -> &mut [Value]
Sourcepub fn total_slots(&self) -> usize
pub fn total_slots(&self) -> usize
Slots handed out, free or in use.
Sourcepub fn free_slots(&self) -> usize
pub fn free_slots(&self) -> usize
Slots sitting in free lists.
Sourcepub fn used_slots(&self) -> usize
pub fn used_slots(&self) -> usize
Slots held by live ranges.
Sourcepub fn fragmentation(&self) -> f64
pub fn fragmentation(&self) -> f64
Free-list slots over all handed-out slots.
pub fn bytes(&self) -> usize
Sourcepub fn free_blocks(&self) -> impl Iterator<Item = Range> + '_
pub fn free_blocks(&self) -> impl Iterator<Item = Range> + '_
Every free range of the class lists.