1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! # Rule Indexing for High-Performance Rule Matching
//!
//! This module provides indexed rule lookup for efficient rule matching in large rule sets.
//! Instead of sequential scanning through all rules, this module enables O(1) lookup
//! based on predicate and first-argument patterns.
//!
//! ## Features
//!
//! - **Predicate Indexing**: Index rules by their body predicate patterns
//! - **First-Argument Indexing**: Additional indexing by first argument for common patterns
//! - **Hash-Based Lookup**: O(1) average case retrieval
//! - **Index Statistics**: Track hit rates and performance metrics
//! - **Automatic Maintenance**: Self-updating indices on rule addition/removal
//!
//! ## Performance Impact
//!
//! - **Without indexing**: O(n) rule scan per fact (n = number of rules)
//! - **With indexing**: O(1) average lookup + O(m) matching rules (m << n typically)
//! - **Expected speedup**: 10-100x for large rule sets (100+ rules)
//!
//! ## Example
//!
//! ```rust
//! use oxirs_rule::rule_index::{RuleIndex, IndexConfig};
//! use oxirs_rule::{Rule, RuleAtom, Term};
//!
//! let config = IndexConfig::default()
//! .with_predicate_indexing(true)
//! .with_first_arg_indexing(true);
//!
//! let mut index = RuleIndex::new(config);
//!
//! // Add rules to index
//! let rule = Rule {
//! name: "ancestor".to_string(),
//! body: vec![RuleAtom::Triple {
//! subject: Term::Variable("X".to_string()),
//! predicate: Term::Constant("parent".to_string()),
//! object: Term::Variable("Y".to_string()),
//! }],
//! head: vec![RuleAtom::Triple {
//! subject: Term::Variable("X".to_string()),
//! predicate: Term::Constant("ancestor".to_string()),
//! object: Term::Variable("Y".to_string()),
//! }],
//! };
//!
//! index.add_rule(rule);
//!
//! // Fast lookup by predicate
//! let matching_rules = index.find_rules_by_predicate("parent");
//! ```
// Re-export all public types from the sibling modules
pub use crate::rule_index_store::{wildcard_matches, PriorityIndex, RuleIndex, RuleIndexBuilder};
pub use crate::rule_index_types::{
ArgType, CombinedKey, DependencyEdge, FirstArgKey, IndexConfig, IndexStatistics,
IndexStatisticsSnapshot, PredicateKey, PrioritizedRule, RuleDependencyGraph, RuleId,
};