pub struct VariableHeightsFenwick { /* private fields */ }Expand description
Variable height tracker using Fenwick tree for O(log n) prefix sum queries.
This enables efficient scroll offset to item index mapping for virtualized lists with variable height items.
§Operations
| Operation | Time |
|---|---|
find_item_at_offset | O(log n) |
offset_of_item | O(log n) |
set_height | O(log n) |
total_height | O(log n) |
§Invariants
tree.prefix(i)== sum of heights [0..=i]find_item_at_offset(offset)returns largest i where prefix(i-1) < offset- Heights are u32 internally (u16 input widened for large lists)
Implementations§
Source§impl VariableHeightsFenwick
impl VariableHeightsFenwick
Sourcepub fn new(default_height: u16, capacity: usize) -> Self
pub fn new(default_height: u16, capacity: usize) -> Self
Create a new height tracker with given default height and initial capacity.
Sourcepub fn from_heights(heights: &[u16], default_height: u16) -> Self
pub fn from_heights(heights: &[u16], default_height: u16) -> Self
Create from a slice of heights.
Sourcepub fn default_height(&self) -> u16
pub fn default_height(&self) -> u16
Get the default height for unmeasured items.
Sourcepub fn offset_of_item(&self, idx: usize) -> u32
pub fn offset_of_item(&self, idx: usize) -> u32
Get the y-offset (in pixels/rows) of an item. O(log n).
Returns the sum of heights of all items before idx.
Sourcepub fn find_item_at_offset(&self, offset: u32) -> usize
pub fn find_item_at_offset(&self, offset: u32) -> usize
Find the item index at a given scroll offset. O(log n).
Returns the index of the item that occupies the given offset.
If offset is beyond all items, returns self.len.
Item i occupies offsets [offset_of_item(i), offset_of_item(i+1)).
Sourcepub fn visible_count(&self, start_idx: usize, viewport_height: u16) -> usize
pub fn visible_count(&self, start_idx: usize, viewport_height: u16) -> usize
Count how many items fit within a viewport starting at start_idx. O(log n).
Returns the number of items that fit completely within viewport_height.
Sourcepub fn total_height(&self) -> u32
pub fn total_height(&self) -> u32
Get total height of all items. O(log n).
Trait Implementations§
Source§impl Clone for VariableHeightsFenwick
impl Clone for VariableHeightsFenwick
Source§fn clone(&self) -> VariableHeightsFenwick
fn clone(&self) -> VariableHeightsFenwick
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more