Skip to main content

ComponentIndex

Struct ComponentIndex 

Source
pub struct ComponentIndex { /* private fields */ }
Expand description

Index for efficient component candidate lookup.

Reduces the O(n·m) comparison to O(n·k) where k << m by:

  1. Grouping components by ecosystem
  2. Bucketing by name prefix
  3. Bucketing by trigrams (3-char substrings) for fuzzy matching
  4. Pre-normalizing names for fast comparison

Uses Arc<CanonicalId> internally for efficient cloning during index building.

Implementations§

Source§

impl ComponentIndex

Source

pub fn build(sbom: &NormalizedSbom) -> Self

Build an index from an SBOM.

Uses Arc<CanonicalId> internally to avoid expensive cloning of IDs across multiple index structures.

Source

pub fn normalize_component(comp: &Component) -> NormalizedEntry

Normalize a component for indexing.

Source

pub fn normalize_name(name: &str, ecosystem: Option<&str>) -> String

Normalize a component name for comparison.

Applies ecosystem-specific normalization rules:

  • PyPI: underscores, hyphens, dots are all equivalent (converted to hyphen)
  • Cargo: hyphens and underscores are equivalent (converted to underscore)
  • npm: lowercase only, preserves scope
  • Default: lowercase with underscore to hyphen conversion

This is also used by LSH for consistent shingle computation.

Source

pub fn get_entry(&self, id: &CanonicalId) -> Option<&NormalizedEntry>

Get normalized entry for a component.

Source

pub fn get_by_ecosystem(&self, ecosystem: &str) -> Option<Vec<CanonicalId>>

Get components by ecosystem.

Returns cloned CanonicalIds for API stability. The internal storage uses Arc to avoid expensive cloning during index building.

Source

pub fn find_candidates( &self, source_id: &CanonicalId, source_entry: &NormalizedEntry, max_candidates: usize, max_length_diff: usize, ) -> Vec<CanonicalId>

Find candidate matches for a component.

Returns a list of component IDs that are likely matches, ordered by likelihood. Uses ecosystem and prefix-based filtering to reduce candidates.

Returns cloned CanonicalIds for API stability. The internal storage uses Arc to avoid expensive cloning during index building.

Source

pub fn all_ids(&self) -> Vec<CanonicalId>

Get all component IDs (for fallback full scan).

Returns cloned CanonicalIds for API stability.

Source

pub fn len(&self) -> usize

Get the number of indexed components.

Source

pub fn is_empty(&self) -> bool

Check if the index is empty.

Source

pub fn find_candidates_parallel<'a>( &self, sources: &[(&'a CanonicalId, &NormalizedEntry)], max_candidates: usize, max_length_diff: usize, ) -> Vec<(&'a CanonicalId, Vec<CanonicalId>)>

Find candidates for multiple source components in parallel.

This is significantly faster than calling find_candidates sequentially for large SBOMs (1000+ components). Uses rayon for parallel iteration.

Returns a vector of (source_id, candidates) pairs in the same order as input.

Source

pub fn find_all_candidates_from( &self, other: &Self, max_candidates: usize, max_length_diff: usize, ) -> Vec<(CanonicalId, Vec<CanonicalId>)>

Find candidates for all components in another index in parallel.

Useful for diffing two SBOMs: build an index from the new SBOM, then find candidates for all components from the old SBOM.

Source

pub fn stats(&self) -> IndexStats

Get statistics about the index.

Source

pub fn trigram_similarity( entry_a: &NormalizedEntry, entry_b: &NormalizedEntry, ) -> f64

Compute trigram similarity between two entries (Jaccard coefficient).

Returns a value between 0.0 and 1.0 where 1.0 means identical trigram sets.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more