comp

package
v1.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Package comp

Abstract

comp compares sequences of comparable values. Its constructors return a Comparer[T], whose public interface exposes a normalized Similarity score. Use []rune for Unicode text, []byte for byte sequences, or slices of other comparable values for tokens and symbols.

Algorithms

Constructor Measures
NewHamming[T] Positional differences; input lengths must match for a non-zero similarity.
NewLevenshtein[T] Insertions, deletions, and substitutions.
NewDamerauLevenshtein[T] Levenshtein edits plus adjacent transpositions using the restricted optimal-string-alignment variant.
NewLCS[T] Longest common subsequence, not longest common substring.
NewJaroWinkler[T] Jaro-style matching-window similarity. The current implementation does not apply a separate Winkler prefix boost.

Similarity returns a score from 0 to 100, rounded to two decimal places. Two empty sequences score 100. Hamming comparison of unequal-length sequences scores 0.

package main

import (
	"fmt"

	"go.osspkg.com/algorithms/comp"
)

func main() {
	comparer := comp.NewLevenshtein[rune]()
	score := comparer.Similarity([]rune("kitten"), []rune("sitting"))
	fmt.Printf("%.2f\n", score)
}

The constructors expose Similarity through Comparer[T]; distance methods are not part of that interface.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comparer

type Comparer[T comparable] interface {
	Similarity(a, b []T) float64
}

func NewDamerauLevenshtein

func NewDamerauLevenshtein[T comparable]() Comparer[T]

func NewHamming

func NewHamming[T comparable]() Comparer[T]

func NewJaroWinkler

func NewJaroWinkler[T comparable]() Comparer[T]

func NewLCS

func NewLCS[T comparable]() Comparer[T]

func NewLevenshtein

func NewLevenshtein[T comparable]() Comparer[T]

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL