Skip to main content

qualia_core_db/q42/volume/
query_mode.rs

1//! Choose resident vs range query from file size. Small graphs stay in RAM;
2//! everything above the cap must use the range/BIDX path.
3
4/// 4 MiB decoded-file threshold. Above this, callers must not `read_all_quins`.
5pub const RESIDENT_QUERY_MAX_BYTES: u64 = 4 * 1024 * 1024;
6
7#[derive(Clone, Copy, Debug, Eq, PartialEq)]
8pub enum Q42QueryMode {
9    Resident,
10    Range,
11}
12
13impl Q42QueryMode {
14    pub fn for_file_bytes(file_bytes: u64) -> Self {
15        if file_bytes <= RESIDENT_QUERY_MAX_BYTES {
16            Self::Resident
17        } else {
18            Self::Range
19        }
20    }
21
22    pub fn allows_read_all_quins(self) -> bool {
23        matches!(self, Self::Resident)
24    }
25}
26
27#[cfg(test)]
28mod tests {
29    use super::*;
30
31    #[test]
32    fn small_files_may_reside_large_files_must_range() {
33        assert_eq!(Q42QueryMode::for_file_bytes(1024), Q42QueryMode::Resident);
34        assert_eq!(
35            Q42QueryMode::for_file_bytes(RESIDENT_QUERY_MAX_BYTES + 1),
36            Q42QueryMode::Range
37        );
38        assert!(!Q42QueryMode::Range.allows_read_all_quins());
39    }
40}