//! Visual similarity index using BK-tree over perceptual hashes.
//!
//! This module provides O(log N) visual similarity search over assertion
//! perceptual hashes (pHash). The BK-tree is optimized for discrete metric
//! spaces like hamming distance.
//!
//! # Background
//!
//! Phase 2.5 added brute-force hamming scan for `visual_near` queries. This
//! module replaces that O(N) approach with an indexed O(log N) solution using
//! a Burkhard-Keller tree (BK-tree).
//!
//! # BK-Tree Algorithm
//!
//! A BK-tree organizes nodes by distance from their parent. For hamming distance:
//! - Root node is the first inserted hash
//! - Each child edge is labeled with the hamming distance from parent
//! - To search with threshold t: only explore children with edge distance d
//!   where |d - query_distance| <= t
//!
//! This exploits the triangle inequality to prune the search space.
//!
//! # Storage Layout
//!
//! | Key Pattern | Value | Purpose |
//! |-------------|-------|---------|
//! | `VH:tree` | BK-tree (rkyv) | The tree structure |
//! | `VH:count` | u64 | Number of indexed hashes |
//!
//! # Example
//!
//! ```ignore
//! use stemedb_storage::{BkTreeVisualIndex, VisualIndex};
//!
//! let index = BkTreeVisualIndex::new();
//!
//! // Insert assertion's visual hash
//! index.insert(&assertion_hash, &phash)?;
//!
//! // Find visually similar within hamming distance 5
//! let similar = index.search(&query_phash, 5)?;
//! for (hash, distance) in similar {
//!     println!("Hash: {}, Hamming distance: {}", hex::encode(hash), distance);
//! }
//! ```

mod bk_tree;
mod hamming;
mod persistent;

pub use bk_tree::{BkTreeSnapshot, BkTreeVisualIndex};
pub use hamming::{hamming_distance, VisualIndex};
pub use persistent::{PersistentVisualIndex, PersistentVisualIndexConfig};
