pub struct TensorRuleIndex {
pub rules: HashMap<u64, IndexedRule>,
pub predicate_index: HashMap<String, Vec<u64>>,
}Expand description
Multi-dimensional index over IndexedRule entries.
Supports O(1) lookup by rule ID and predicate, plus flexible filtered queries across predicate, arity, confidence, body content, and active status.
Fields§
§rules: HashMap<u64, IndexedRule>Primary store: rule_id → rule.
predicate_index: HashMap<String, Vec<u64>>Secondary index: head_predicate → list of rule_ids.
Implementations§
Source§impl TensorRuleIndex
impl TensorRuleIndex
Sourcepub fn insert(&mut self, rule: IndexedRule)
pub fn insert(&mut self, rule: IndexedRule)
Insert a rule, updating both the primary store and the predicate index.
If a rule with the same rule_id already exists it is replaced, and the
predicate index is kept consistent.
Sourcepub fn remove(&mut self, rule_id: u64) -> bool
pub fn remove(&mut self, rule_id: u64) -> bool
Remove the rule with the given rule_id.
Returns true on success, false when no such rule exists.
Sourcepub fn deactivate(&mut self, rule_id: u64) -> bool
pub fn deactivate(&mut self, rule_id: u64) -> bool
Set a rule’s active field to false.
Returns true on success, false when no such rule exists.
Sourcepub fn activate(&mut self, rule_id: u64) -> bool
pub fn activate(&mut self, rule_id: u64) -> bool
Set a rule’s active field to true.
Returns true on success, false when no such rule exists.
Sourcepub fn query(&self, q: &RuleQuery) -> Vec<&IndexedRule>
pub fn query(&self, q: &RuleQuery) -> Vec<&IndexedRule>
Return rules that match all criteria in q.
Results are sorted by confidence descending; ties are broken by
rule_id ascending.
Sourcepub fn dependents_of(&self, rule_id: u64) -> Vec<&IndexedRule>
pub fn dependents_of(&self, rule_id: u64) -> Vec<&IndexedRule>
Return all rules whose depends_on list contains rule_id, sorted by
rule_id ascending.
Sourcepub fn rules_for_predicate(&self, predicate: &str) -> Vec<&IndexedRule>
pub fn rules_for_predicate(&self, predicate: &str) -> Vec<&IndexedRule>
Return all rules with the given head predicate, sorted by confidence descending.
Uses the predicate index for efficient lookup.
Sourcepub fn stats(&self) -> RuleIndexStats
pub fn stats(&self) -> RuleIndexStats
Compute aggregate statistics over the current rule set.
Trait Implementations§
Source§impl Debug for TensorRuleIndex
impl Debug for TensorRuleIndex
Source§impl Default for TensorRuleIndex
impl Default for TensorRuleIndex
Source§fn default() -> TensorRuleIndex
fn default() -> TensorRuleIndex
Auto Trait Implementations§
impl Freeze for TensorRuleIndex
impl RefUnwindSafe for TensorRuleIndex
impl Send for TensorRuleIndex
impl Sync for TensorRuleIndex
impl Unpin for TensorRuleIndex
impl UnsafeUnpin for TensorRuleIndex
impl UnwindSafe for TensorRuleIndex
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more