1use serde::{Deserialize, Serialize};
4use std::time::Duration;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, PartialOrd, Ord)]
8#[repr(u8)]
9pub enum MemoryTier {
10 Instant = 1,
14
15 Session = 2,
18
19 Episodic = 3,
22
23 Semantic = 4,
26
27 Collective = 5,
31
32 Evolutionary = 6,
35
36 Architectural = 7,
39
40 Substrate = 8,
43
44 Civilizational = 9,
48
49 Temporal = 10,
52
53 Physical = 11,
56
57 Omega = 12,
60}
61
62impl MemoryTier {
63 pub fn retention_duration(&self) -> Option<Duration> {
65 match self {
66 Self::Instant => Some(Duration::from_secs(60)), Self::Session => Some(Duration::from_secs(3600 * 24)), Self::Episodic => Some(Duration::from_secs(3600 * 24 * 30)), Self::Semantic => Some(Duration::from_secs(3600 * 24 * 365)), Self::Collective => Some(Duration::from_secs(3600 * 24 * 365 * 10)), _ => None, }
73 }
74
75 pub fn importance_threshold(&self) -> f64 {
77 match self {
78 Self::Instant => 0.0,
79 Self::Session => 0.1,
80 Self::Episodic => 0.3,
81 Self::Semantic => 0.5,
82 Self::Collective => 0.6,
83 Self::Evolutionary => 0.7,
84 Self::Architectural => 0.8,
85 Self::Substrate => 0.85,
86 Self::Civilizational => 0.9,
87 Self::Temporal => 0.93,
88 Self::Physical => 0.96,
89 Self::Omega => 0.99,
90 }
91 }
92
93 pub fn typical_size(&self) -> usize {
95 match self {
96 Self::Instant => 1_000, Self::Session => 10_000, Self::Episodic => 100_000, Self::Semantic => 1_000_000, Self::Collective => 10_000_000, Self::Evolutionary => 100_000_000, _ => usize::MAX, }
104 }
105
106 pub fn scale(&self) -> MemoryScale {
108 match self {
109 Self::Instant | Self::Session | Self::Episodic | Self::Semantic => MemoryScale::Individual,
110 Self::Collective | Self::Evolutionary | Self::Architectural | Self::Substrate => MemoryScale::Species,
111 Self::Civilizational | Self::Temporal | Self::Physical | Self::Omega => MemoryScale::Cosmic,
112 }
113 }
114
115 pub fn next_tier(&self) -> Option<MemoryTier> {
117 match self {
118 Self::Instant => Some(Self::Session),
119 Self::Session => Some(Self::Episodic),
120 Self::Episodic => Some(Self::Semantic),
121 Self::Semantic => Some(Self::Collective),
122 Self::Collective => Some(Self::Evolutionary),
123 Self::Evolutionary => Some(Self::Architectural),
124 Self::Architectural => Some(Self::Substrate),
125 Self::Substrate => Some(Self::Civilizational),
126 Self::Civilizational => Some(Self::Temporal),
127 Self::Temporal => Some(Self::Physical),
128 Self::Physical => Some(Self::Omega),
129 Self::Omega => None, }
131 }
132
133 pub fn tiers_in_scale(scale: MemoryScale) -> Vec<MemoryTier> {
135 match scale {
136 MemoryScale::Individual => vec![
137 Self::Instant,
138 Self::Session,
139 Self::Episodic,
140 Self::Semantic,
141 ],
142 MemoryScale::Species => vec![
143 Self::Collective,
144 Self::Evolutionary,
145 Self::Architectural,
146 Self::Substrate,
147 ],
148 MemoryScale::Cosmic => vec![
149 Self::Civilizational,
150 Self::Temporal,
151 Self::Physical,
152 Self::Omega,
153 ],
154 }
155 }
156
157 pub fn all() -> Vec<MemoryTier> {
159 vec![
160 Self::Instant,
161 Self::Session,
162 Self::Episodic,
163 Self::Semantic,
164 Self::Collective,
165 Self::Evolutionary,
166 Self::Architectural,
167 Self::Substrate,
168 Self::Civilizational,
169 Self::Temporal,
170 Self::Physical,
171 Self::Omega,
172 ]
173 }
174}
175
176#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
178pub enum MemoryScale {
179 Individual,
181 Species,
183 Cosmic,
185}
186
187impl std::fmt::Display for MemoryTier {
188 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
189 match self {
190 Self::Instant => write!(f, "Instant (T1)"),
191 Self::Session => write!(f, "Session (T2)"),
192 Self::Episodic => write!(f, "Episodic (T3)"),
193 Self::Semantic => write!(f, "Semantic (T4)"),
194 Self::Collective => write!(f, "Collective (T5)"),
195 Self::Evolutionary => write!(f, "Evolutionary (T6)"),
196 Self::Architectural => write!(f, "Architectural (T7)"),
197 Self::Substrate => write!(f, "Substrate (T8)"),
198 Self::Civilizational => write!(f, "Civilizational (T9)"),
199 Self::Temporal => write!(f, "Temporal (T10)"),
200 Self::Physical => write!(f, "Physical (T11)"),
201 Self::Omega => write!(f, "Omega (T12)"),
202 }
203 }
204}
205
206#[cfg(test)]
207mod tests {
208 use super::*;
209
210 #[test]
211 fn test_tier_ordering() {
212 assert!(MemoryTier::Instant < MemoryTier::Omega);
213 assert!(MemoryTier::Session < MemoryTier::Episodic);
214 }
215
216 #[test]
217 fn test_tier_progression() {
218 assert_eq!(MemoryTier::Instant.next_tier(), Some(MemoryTier::Session));
219 assert_eq!(MemoryTier::Omega.next_tier(), None);
220 }
221
222 #[test]
223 fn test_scale_categories() {
224 assert_eq!(MemoryTier::Instant.scale(), MemoryScale::Individual);
225 assert_eq!(MemoryTier::Collective.scale(), MemoryScale::Species);
226 assert_eq!(MemoryTier::Omega.scale(), MemoryScale::Cosmic);
227 }
228}