pub struct Cache { /* private fields */ }Expand description
LRU cache for kernel matrix rows.
Each of the l data items may have a cached row of length up to l.
The cache tracks how much memory (in Qfloat units) is in use and evicts
LRU entries when the budget is exceeded.
The LRU list is a circular doubly-linked list using array indices.
Index l is the sentinel head node. All operations (insert, remove,
evict) are O(1).
Implementations§
Source§impl Cache
impl Cache
Sourcepub fn new(l: usize, size_bytes: usize) -> Self
pub fn new(l: usize, size_bytes: usize) -> Self
Create a new cache for l data items with size_bytes of memory.
Sourcepub fn get_data(
&mut self,
index: usize,
request_len: usize,
) -> (&mut [Qfloat], usize)
pub fn get_data( &mut self, index: usize, request_len: usize, ) -> (&mut [Qfloat], usize)
Request data for row index of length request_len.
Returns (data, start) where data is the cached row slice and
start is the position from which data needs to be filled.
If start >= request_len, the entire row was already cached.
The caller must fill data[start..request_len] with kernel values.
Sourcepub fn swap_index(&mut self, i: usize, j: usize)
pub fn swap_index(&mut self, i: usize, j: usize)
Swap indices i and j in the cache.
Used by the solver when rearranging the working set.