sort_governor/plan/kind.rs
1//! The decision the planner produces.
2
3/// How a sort will be executed, chosen by [`crate::SortPlanner`].
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum SortPlan {
6 /// Sort entirely in memory — a `Vec` sort that never opens a file
7 /// descriptor. Chosen for small sorts when the budget has headroom.
8 InMemory,
9 /// Spill to disk and merge. `run_buffer_bytes` bounds the in-memory run
10 /// before each spill; `max_fan_in` bounds the number of run files open
11 /// at once during the (possibly cascaded) merge, so the process file
12 /// descriptor table can never be exhausted.
13 External {
14 /// In-memory run size before a spill, in bytes.
15 run_buffer_bytes: usize,
16 /// Maximum run files open simultaneously during the merge.
17 max_fan_in: u32,
18 },
19}
20
21impl SortPlan {
22 /// Whether this plan spills to disk.
23 #[must_use]
24 pub fn is_external(&self) -> bool {
25 matches!(self, SortPlan::External { .. })
26 }
27
28 /// Whether this plan stays entirely in memory.
29 #[must_use]
30 pub fn is_in_memory(&self) -> bool {
31 matches!(self, SortPlan::InMemory)
32 }
33}