package toffee
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/toffee.tree/Tree/Cache/index.html
Module Tree.CacheSource
Layout computation result caching.
This module provides memoization for layout computations. During layout, parent nodes often query child sizes multiple times under different constraints. The cache prevents redundant computation and ensures earlier results are not overwritten by later ones.
Cache Structure
The cache maintains two entry types:
- Final layout entry: Stores complete layout output including positions and baselines, computed during
Perform_layoutmode - Measure entries: Nine slots for preliminary size measurements computed during
Compute_sizemode
Slot Allocation Strategy
Measure cache slots are determined by two factors:
- How many dimensions are known: width, height, both, or neither
- For unknown dimensions: whether the available space constraint is min-content or max-content
Definite available space shares a cache slot with max-content because nodes are typically sized under one or the other, not both.
Slot assignments:
- Slot 0: Both width and height known
- Slots 1-2: Width known, height unknown
- Slot 1: Height max-content or definite
- Slot 2: Height min-content
- Slots 3-4: Height known, width unknown
- Slot 3: Width max-content or definite
- Slot 4: Width min-content
- Slots 5-8: Neither dimension known
- Slot 5: Both axes max-content or definite
- Slot 6: Width max-content or definite, height min-content
- Slot 7: Width min-content, height max-content or definite
- Slot 8: Both axes min-content
Cache Matching
A cache entry matches a query when:
- Known dimensions match the cached entry's known dimensions, OR known dimensions match the cached result size
- For unknown dimensions, available space constraints are roughly equal (within 0.0001 for definite values)
Hidden layouts (Perform_hidden_layout mode) are never cached.
cache_size is the number of measure cache slots (9).
type 'a cache_entry = {known_dimensions : float option Geometry.size;available_space : Available_space.t Geometry.size;content : 'a;
}Cached layout result paired with its input constraints.
Fields known_dimensions and available_space record the sizing constraints that produced content.
type t = {mutable final_layout_entry : Layout_output.t cache_entry option;mutable measure_entries : float Geometry.size cache_entry option array;mutable is_empty : bool;
}Cache for layout computation results.
Field final_layout_entry stores complete layout output with positions and baselines from Perform_layout mode. Field measure_entries stores preliminary size measurements from Compute_size mode. Field is_empty tracks whether any entries are populated.
Result of a clear operation.
compute_cache_slot known_dimensions available_space returns the measure cache slot index for the given constraints.
The slot is determined by which dimensions are known and the available space constraints for unknown dimensions.
is_roughly_equal av1 av2 tests approximate equality of available space values.
Definite values are equal when they differ by less than 0.0001. Min-content and max-content values are equal only to themselves.
val get :
t ->
known_dimensions:float option Geometry.size ->
available_space:Available_space.t Geometry.size ->
run_mode:Run_mode.t ->
Layout_output.t optionget t ~known_dimensions ~available_space ~run_mode retrieves a cached layout result matching the given constraints.
For Perform_layout, searches the final layout entry. For Compute_size, searches all measure entries. For Perform_hidden_layout, always returns None.
A cache entry matches when known dimensions match either the cached known dimensions or the cached result size, and unknown dimensions have roughly equal available space constraints.
val store :
t ->
known_dimensions:float option Geometry.size ->
available_space:Available_space.t Geometry.size ->
run_mode:Run_mode.t ->
Layout_output.t ->
unitstore t ~known_dimensions ~available_space ~run_mode layout_output stores a layout result in the cache.
For Perform_layout, stores complete layout_output in the final layout entry, replacing any previous entry. For Compute_size, stores only the size component in the measure entry slot determined by compute_cache_slot. For Perform_hidden_layout, performs no caching.
clear t removes all cached entries and reports the operation outcome.
Resets both final layout entry and all measure entries to None.