Skip to main content

ass_editor/utils/indexing/
common.rs

1//! Shared search index types and helpers.
2//!
3//! Defines the [`IndexEntry`] record stored by every search index backend and
4//! the FNV content-hash helper used for cache invalidation.
5
6use crate::core::Position;
7
8#[cfg(not(feature = "std"))]
9use alloc::string::String;
10
11/// Entry in the search index
12#[derive(Debug, Clone)]
13pub struct IndexEntry {
14    /// Position in document
15    pub position: Position,
16
17    /// Context around the match
18    pub context: String,
19
20    /// Line number (0-based)
21    pub line: usize,
22
23    /// Column number (0-based)
24    pub column: usize,
25
26    /// Section type (Events, Styles, etc.)
27    pub section_type: Option<String>,
28}
29
30/// Simple hash function for content change detection
31pub(super) fn calculate_hash(content: &str) -> u64 {
32    // Simple FNV hash - in production might use a proper hasher
33    let mut hash = 0xcbf29ce484222325u64;
34    for byte in content.bytes() {
35        hash ^= byte as u64;
36        hash = hash.wrapping_mul(0x100000001b3);
37    }
38    hash
39}