Skip to main content

cbtop/grammar/
resources.rs

1//! Resource mapping (Aesthetics equivalent in Grammar of Graphics).
2
3/// Scale binding for resource mapping
4#[derive(Debug, Clone, PartialEq)]
5pub enum ScaleBinding {
6    /// Bind to problem size
7    ProblemSize,
8    /// Bind to data volume
9    DataVolume,
10    /// Bind to throughput requirement
11    Throughput,
12    /// Custom binding expression
13    Custom(String),
14}
15
16/// Byte size helper
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub struct ByteSize(pub usize);
19
20impl ByteSize {
21    /// Create from megabytes
22    pub fn mb(mb: usize) -> Self {
23        ByteSize(mb * 1024 * 1024)
24    }
25
26    /// Create from gigabytes
27    pub fn gb(gb: usize) -> Self {
28        ByteSize(gb * 1024 * 1024 * 1024)
29    }
30
31    /// Get raw bytes
32    pub fn bytes(&self) -> usize {
33        self.0
34    }
35}
36
37/// Resource mapping (analogous to Aesthetics)
38#[derive(Debug, Clone, PartialEq, Default)]
39pub struct ResourceMapping {
40    /// Map problem size to cores
41    pub cores: Option<ScaleBinding>,
42    /// Map data volume to memory
43    pub memory: Option<ScaleBinding>,
44    /// Map throughput to bandwidth
45    pub bandwidth: Option<ScaleBinding>,
46    /// Map latency constraints
47    pub latency: Option<ScaleBinding>,
48    /// Fixed core count override
49    pub cores_value: Option<usize>,
50    /// Fixed memory limit override
51    pub memory_value: Option<ByteSize>,
52}
53
54impl ResourceMapping {
55    /// Create empty resource mapping
56    pub fn new() -> Self {
57        Self::default()
58    }
59
60    /// Set core binding
61    pub fn cores(mut self, binding: ScaleBinding) -> Self {
62        self.cores = Some(binding);
63        self
64    }
65
66    /// Set fixed core count
67    pub fn cores_value(mut self, count: usize) -> Self {
68        self.cores_value = Some(count);
69        self
70    }
71
72    /// Set memory binding
73    pub fn memory(mut self, binding: ScaleBinding) -> Self {
74        self.memory = Some(binding);
75        self
76    }
77
78    /// Set fixed memory limit
79    pub fn memory_value(mut self, size: ByteSize) -> Self {
80        self.memory_value = Some(size);
81        self
82    }
83}