mycelial_cache.rs
rust
1pub struct MycelialCache<K: Hash + Eq + Clone, V> { /* internal */ }
2
3impl<K: Hash + Eq + Clone, V> MycelialCache<K, V> {
4 // Construction (+ preset configs)
5 pub fn new(config: MycelialConfig) -> Self;
6 pub fn with_capacity(capacity: u64) -> Self;
7 pub fn general_purpose(capacity: u64) -> Self;
8 pub fn high_co_access(capacity: u64) -> Self;
9 pub fn low_overhead(capacity: u64) -> Self;
10
11 // Core operations
12 pub fn get(&mut self, key: &K) -> Option<&V>;
13 pub fn get_mut(&mut self, key: &K) -> Option<&mut V>;
14 pub fn set(&mut self, key: K, value: V) -> Option<V>;
15 pub fn set_with_ttl(&mut self, key: K, value: V, ttl: Duration) -> Option<V>;
16 pub fn delete(&mut self, key: &K) -> Option<V>;
17 pub fn contains(&self, key: &K) -> bool;
18
19 // Size & capacity
20 pub fn len(&self) -> u64;
21 pub fn capacity(&self) -> u64;
22 pub fn is_empty(&self) -> bool;
23 pub fn is_full(&self) -> bool;
24 pub fn clear(&mut self);
25
26 // Iteration (does not update mesh)
27 pub fn keys(&self) -> impl Iterator<Item = &K>;
28 pub fn values(&self) -> impl Iterator<Item = &V>;
29 pub fn iter(&self) -> impl Iterator<Item = (&K, &V)>;
30
31 // Pinning
32 pub fn pin(&mut self, key: &K) -> bool;
33 pub fn unpin(&mut self, key: &K) -> bool;
34 pub fn is_pinned(&self, key: &K) -> bool;
35
36 // Mesh introspection
37 pub fn mesh_neighbors(&self, key: &K) -> Option<Vec<(K, f32)>>;
38 pub fn eviction_score(&self, key: &K) -> Option<EvictionScore>;
39 pub fn bridge_entries(&self) -> Vec<K>;
40 pub fn mesh_stats(&self) -> MeshStats;
41 pub fn fever_intensity(&self) -> f32;
42 pub fn coherence_ema(&self) -> f32;
43 pub fn coherence_baseline(&self) -> f32;
44 pub fn config(&self) -> &MycelialConfig;
45
46 // Maintenance (Maintainable trait)
47 pub fn tick(&mut self) -> MaintenanceReport;
48}
49