Skip to main content

ContractIndex

Struct ContractIndex 

Source
pub struct ContractIndex {
    pub entries: Vec<ContractEntry>,
    /* private fields */
}
Expand description

In-memory contract index with inverted indexes for fast lookup.

Fields§

§entries: Vec<ContractEntry>

Implementations§

Source§

impl ContractIndex

Source

pub fn from_directory(dir: &Path) -> Result<Self, Box<dyn Error>>

Build an index from a directory of YAML contracts.

Uses cached index from .pv/contracts.idx when fresh, otherwise rebuilds and caches for next time.

Source

pub fn from_directory_opts( dir: &Path, force_rebuild: bool, ) -> Result<Self, Box<dyn Error>>

Build an index with option to force rebuild (skip cache).

Source

pub fn build_from_directory(dir: &Path) -> Result<Self, Box<dyn Error>>

Build an index from a directory without cache.

Source

pub fn from_entries(entries: Vec<ContractEntry>) -> Self

Build an index from pre-parsed entries.

Source

pub fn get_by_stem(&self, stem: &str) -> Option<&ContractEntry>

Look up a contract by exact stem.

Source

pub fn cached_score(&self, stem: &str) -> Option<f64>

Get the pre-computed composite score for a contract stem.

Source

pub fn cached_pagerank(&self, stem: &str) -> Option<f64>

Get the pre-computed pagerank score for a contract stem.

Source

pub fn get_by_obligation(&self, ob_type: &str) -> Vec<&ContractEntry>

Look up contracts by obligation type.

Source

pub fn get_by_equation(&self, eq: &str) -> Vec<&ContractEntry>

Look up contracts by equation name.

BM25 search across all entries. Returns (index, score) pairs sorted descending.

Regex search across all entries. Returns matching indices.

Literal substring search. Returns matching indices.

Source

pub fn depended_by(&self, stem: &str) -> Vec<&str>

Return reverse dependencies: contracts that depend on stem.

Source

pub fn pagerank(&self, iterations: usize, damping: f64) -> HashMap<String, f64>

Compute pagerank scores over the contract dependency graph.

Returns a map from stem to pagerank score. Higher scores indicate more “important” contracts (more depended-upon by others).

Trait Implementations§

Source§

impl Debug for ContractIndex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.