libzed 1.9.9
A general-purpose library for quick and simple data manipulation.
 
Loading...
Searching...
No Matches
z::math Namespace Reference

This section contains math-related functions, constants, and datatypes. More...

Functions

template<encoding E>
int levenschtein (const z::core::string< E > &word1, const z::core::string< E > &word2, int max=16) noexcept
 Computes the Levenshtein distance between two strings with an optional maximum threshold.
 

Variables

const double pi = 3.1415926535897932384626433832795
 The numerical constant pi.
 
const double e = 2.7182818284590452353602874713527
 The numerical constant e.
 
const double sqrt2 = 1.41421356237309504880168872420969807856967187537694807317667973799
 Pythagoras' constant.
 
const double sqrt5 = 2.23606797749978969640917366873127623544061835961152572427089
 The square root of 5.
 
const double phi = 1.6180339887498948482045868343656381177203091798057628621
 The golden ratio.
 

Detailed Description

This section contains math-related functions, constants, and datatypes.

Function Documentation

◆ levenschtein()

template<encoding E>
int z::math::levenschtein ( const z::core::string< E > &  word1,
const z::core::string< E > &  word2,
int  max = 16 
)
noexcept

Computes the Levenshtein distance between two strings with an optional maximum threshold.

This function calculates the Levenshtein distance, which is a metric for measuring the difference between two strings word1 and word2. It represents the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into the other.

The function allows for an optional maximum distance max. If the calculated Levenshtein distance exceeds this threshold, it will return early with the maximum possible value, as the strings are – for all intents and purposes – completely different.

Parameters
word1The first string to compare.
word2The second string to compare.
maxThe optional maximum distance threshold. If the Levenshtein distance exceeds this value, the maximum integer value is returned.
Returns
The Levenshtein distance between the two strings.