Struct Levenshtein

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

A struct for calculating Levenshtein distance.

This struct provides methods to set custom costs for insert, delete, and replace operations and a method to calculate the Levenshtein distance between two sequences.

Implementations§

Source§

impl Levenshtein

Source

pub fn new() -> Levenshtein

Constructs a new Levenshtein.

Initializes with default costs for insertion, deletion, and replacement operations.

§Examples
let levenshtein = Levenshtein::new();
Source

pub fn set_insert_cost(&mut self, cost: i32)

Sets the cost of an insertion operation.

§Arguments
  • cost - The cost of an insertion operation.
§Examples
let mut levenshtein = Levenshtein::new();
levenshtein.set_insert_cost(2);
Source

pub fn set_replace_cost(&mut self, cost: i32)

Sets the cost of a replacement operation.

§Arguments
  • cost - The cost of a replacement operation.
§Examples
let mut levenshtein = Levenshtein::new();
levenshtein.set_replace_cost(1);
Source

pub fn set_delete_cost(&mut self, cost: i32)

Sets the cost of a deletion operation.

§Arguments
  • cost - The cost of a deletion operation.
§Examples
let mut levenshtein = Levenshtein::new();
levenshtein.set_delete_cost(2);
Source

pub fn calculate(&self, seq1: &str, seq2: &str) -> Results

Calculates the Levenshtein distance between two sequences.

Returns a Results struct containing the distance and the sequence of operations.

§Arguments
  • seq1 - The first sequence.
  • seq2 - The second sequence.
§Examples
let levenshtein = Levenshtein::new();
let results = levenshtein.calculate("kitten", "sitting");

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.