graphos_common/memory/buffer/
region.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8pub enum MemoryRegion {
9 GraphStorage,
11 IndexBuffers,
13 ExecutionBuffers,
15 SpillStaging,
17}
18
19impl MemoryRegion {
20 #[must_use]
22 pub const fn index(&self) -> usize {
23 match self {
24 Self::GraphStorage => 0,
25 Self::IndexBuffers => 1,
26 Self::ExecutionBuffers => 2,
27 Self::SpillStaging => 3,
28 }
29 }
30
31 #[must_use]
33 pub const fn name(&self) -> &'static str {
34 match self {
35 Self::GraphStorage => "Graph Storage",
36 Self::IndexBuffers => "Index Buffers",
37 Self::ExecutionBuffers => "Execution Buffers",
38 Self::SpillStaging => "Spill Staging",
39 }
40 }
41
42 #[must_use]
44 pub const fn all() -> [Self; 4] {
45 [
46 Self::GraphStorage,
47 Self::IndexBuffers,
48 Self::ExecutionBuffers,
49 Self::SpillStaging,
50 ]
51 }
52}
53
54impl std::fmt::Display for MemoryRegion {
55 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56 write!(f, "{}", self.name())
57 }
58}
59
60#[cfg(test)]
61mod tests {
62 use super::*;
63
64 #[test]
65 fn test_region_indices() {
66 assert_eq!(MemoryRegion::GraphStorage.index(), 0);
67 assert_eq!(MemoryRegion::IndexBuffers.index(), 1);
68 assert_eq!(MemoryRegion::ExecutionBuffers.index(), 2);
69 assert_eq!(MemoryRegion::SpillStaging.index(), 3);
70 }
71
72 #[test]
73 fn test_region_names() {
74 assert_eq!(MemoryRegion::GraphStorage.name(), "Graph Storage");
75 assert_eq!(MemoryRegion::ExecutionBuffers.name(), "Execution Buffers");
76 }
77
78 #[test]
79 fn test_region_all() {
80 let all = MemoryRegion::all();
81 assert_eq!(all.len(), 4);
82 }
83}