cmpstr
Version:
CmpStr is a lightweight, fast and well performing package for calculating string similarity
50 lines (49 loc) • 1.97 kB
TypeScript
/**
* Hamming Distance
* src/metric/Hamming.ts
*
* @see https://en.wikipedia.org/wiki/Hamming_distance
*
* The Hamming distance is a metric for comparing two strings of equal length. It
* measures the number of positions at which the corresponding symbols are different.
*
* This implementation allows for optional padding of the shorter string to equalize
* lengths, otherwise it throws an error if the strings are of unequal length.
*
* @module Metric/HammingDistance
* @author Paul Köhler (komed3)
* @license MIT
*/
import type { MetricInput, MetricOptions, MetricCompute } from '../utils/Types';
import { Metric } from './Metric';
export interface HammingRaw {
dist: number;
}
/**
* HammingDistance class extends the Metric class to implement the Hamming distance.
*/
export declare class HammingDistance extends Metric<HammingRaw> {
/**
* Constructor for the Hamming class.
*
* Initializes the Hamming distance metric with two input strings or
* arrays of strings and optional options.
*
* @param {MetricInput} a - First input string or array of strings
* @param {MetricInput} b - Second input string or array of strings
* @param {MetricOptions} opt - Options for the metric computation
*/
constructor(a: MetricInput, b: MetricInput, opt?: MetricOptions);
/**
* Calculates the Hamming distance between two strings.
*
* @param {string} a - First string
* @param {string} b - Second string
* @param {number} m - Length of the first string
* @param {number} n - Length of the second string
* @param {number} maxLen - Maximum length of the strings
* @return {MetricCompute<HammingRaw>} - Object containing the similarity result and raw distance
* @throws {Error} - If strings are of unequal length and padding is not specified
*/
protected compute(a: string, b: string, m: number, n: number, maxLen: number): MetricCompute<HammingRaw>;
}