use horon_engine::{Store, StoreConfig};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let store = Store::new();
assert!(store.is_empty());
store.put("/config/db", b"postgres://localhost:5432")?;
store.put("/config/cache", b"redis://localhost:6379")?;
store.put("/config/cache/ttl", b"3600")?;
let db = store.get("/config/db")?;
println!("db = {}", String::from_utf8_lossy(&db));
assert!(store.exists("/config/cache"));
println!("entries: {}", store.len());
store.set_meta("/config/db", "env", "production")?;
store.set_meta("/config/db", "owner", "platform-team")?;
let meta = store.get_meta("/config/db")?;
println!("db metadata: {:?}", meta);
let children = store.children("/config")?;
println!("children of /config: {:?}", children);
let all = store.list("/config")?;
println!("all under /config: {:?}", all);
let (path, distance) = store.nearest(&fp(&[0.0, 0.0, 0.0, 0.0]))?;
println!("nearest to origin: '{}' (distance {:.6})", path, distance);
let neighbors = store.neighbors("/config/cache", 2)?;
println!("2 nearest neighbors of /config/cache: {:?}", neighbors);
let nearby = store.find_within("/config", g_math::fixed_point::FixedPoint::from_f64(5.0))?;
println!("nodes within radius 5.0 of /config: {:?}", nearby);
store.remove("/config/cache/ttl")?;
assert!(!store.exists("/config/cache/ttl"));
println!("entries after delete: {}", store.len());
let small = Store::with_config(StoreConfig::new().capacity(100));
println!("small store empty: {}", small.is_empty());
let stats = store.inner().stats();
println!("internal stats: {:?}", stats);
println!("\nDone.");
Ok(())
}
fn fp(vals: &[f64]) -> Vec<g_math::fixed_point::FixedPoint> {
vals.iter().map(|&v| g_math::fixed_point::FixedPoint::from_f64(v)).collect()
}