pub struct LruTextureCache<K: Hash + Eq, V> { /* private fields */ }Expand description
A LRU texture cache to cache rects in a texture.
§Algorithm
This works by dividing the texture in rows. When adding a rect it check if it fit in any of the existing rows. If not, a new row is created, with the height of the added rect. If there is no space for new rows, a range of unused rows with a height that fit the rect is remove, and a new row that fit the rect is added. If no row is find, the entire cache is cleared.
When adding multiple rects, all rows that contains any of the already added rects are marked as used, and the remain are the unused ones.
Implementations§
Source§impl<K: Hash + Eq + Copy + 'static, V: Clone> LruTextureCache<K, V>
impl<K: Hash + Eq + Copy + 'static, V: Clone> LruTextureCache<K, V>
Sourcepub fn new(width: u32, height: u32) -> Self
pub fn new(width: u32, height: u32) -> Self
Create a new empty cache, with the given width and height.
Sourcepub fn min_height(&self) -> u32
pub fn min_height(&self) -> u32
The height of the occupied area of the cache.
Cached rects are placed at the top, and grows to bottom, this is the position of the bottom of the lowest rect.
Sourcepub fn contains(&self, key: &K) -> bool
pub fn contains(&self, key: &K) -> bool
Return true if there is a cached rect associated with the given Key. Otherwise, return false.
Sourcepub fn cache_rects<D>(
&mut self,
rects: &mut [RectEntry<K, V, D>],
) -> Result<Cached, CacheErr>
pub fn cache_rects<D>( &mut self, rects: &mut [RectEntry<K, V, D>], ) -> Result<Cached, CacheErr>
Cache the given slice of rects.
The given slice of rects is reorder so that it start with every rect that was added to the
cache. This way you can iterate over them by subslicing rects (rects[0..len], where
len is Cached::len or CacheErr::len) and draw them to the texture cache.
If return Ok, it is guaranteed that each one of the given rects will be present in the
cache after this call, but any rects from previous calls could have been removed.