Skip to main content

horon_engine/
init.rs

1//! init.rs - Initialization Module for horon-engine storage
2//!
3//! Provides functions for initializing and managing
4//! hyperbolic tree tensor (HTT) storage instances.
5
6use log::info;
7
8use super::storage::HTTStorage;
9use super::config::HTTStorageConfig;
10use super::tree_tensor::{SharedHTT, HyperbolicTreeTensor, IntegrationResult};
11
12/// Initialize HTT storage with a configuration.
13pub fn initialize_htt_storage(config: HTTStorageConfig) -> IntegrationResult<HTTStorage> {
14    info!("Initializing HTT storage components");
15
16    let storage = HTTStorage::new(config);
17
18    info!("HTT storage components initialized");
19    Ok(storage)
20}
21
22/// Execute a function with access to a shared HTT instance.
23///
24/// No locking needed: all HyperbolicTreeTensor methods take `&self`
25/// with fine-grained interior mutability (DashMap, Mutex, RwLock).
26pub fn with_htt<R, F>(
27    htt: &SharedHTT,
28    f: F,
29) -> IntegrationResult<R>
30where
31    F: FnOnce(&HyperbolicTreeTensor) -> IntegrationResult<R>,
32{
33    f(htt)
34}
35
36#[cfg(test)]
37mod tests {
38    use super::*;
39
40    #[test]
41    fn test_htt_initialization() {
42        let config = HTTStorageConfig::default();
43        let result = initialize_htt_storage(config);
44        assert!(result.is_ok());
45
46        let storage = result.unwrap();
47        assert!(storage.exists("/"));
48    }
49
50    #[test]
51    fn test_htt_with_custom_config() {
52        let config = HTTStorageConfig::new(
53            8,
54            2000,
55            200,
56            None,
57            120,
58            false,
59        );
60        let result = initialize_htt_storage(config);
61        assert!(result.is_ok());
62    }
63}