Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultFilename ¶ added in v0.2.0
func DefaultFilename(path string, fn DistanceFunc) string
DefaultFilename returns a filename with the metric name embedded, e.g. DefaultFilename("data.gob", Levenshtein) → "data_levenshtein.gob".
func Hamming ¶
Hamming computes the Hamming distance between two equal-length strings. Panics if the strings have different lengths.
func Levenshtein ¶
Levenshtein computes the edit distance between two strings using the Wagner-Fischer algorithm with O(min(len(a),len(b))) space. The distance is calculated over Unicode code points (runes), not bytes.
Types ¶
type BKTree ¶
type BKTree struct {
// contains filtered or unexported fields
}
BKTree is a Burkhard-Keller tree for fast approximate string matching.
func Load ¶ added in v0.2.0
func Load(r io.Reader, dist DistanceFunc) (*BKTree, error)
Load reads a tree topology from r using gob encoding.
func New ¶
func New(dist DistanceFunc) *BKTree
New creates a new empty BKTree with the given distance function. Panics if dist is nil.
func (*BKTree) Exists ¶
Exists returns true if there exists at least one word in the tree within maxDist of the query word. It short-circuits on the first match.
type DistanceFunc ¶
DistanceFunc defines a metric distance function between two strings.
type Forest ¶
type Forest struct {
// contains filtered or unexported fields
}
Forest partitions words by length into multiple BK-Trees. This enables natural Hamming support and Levenshtein length-based pruning.
func LoadForest ¶ added in v0.2.0
func LoadForest(r io.Reader, dist DistanceFunc) (*Forest, error)
LoadForest reads a forest topology from r using gob encoding.
func NewForest ¶
func NewForest(dist DistanceFunc) *Forest
NewForest creates a new empty Forest with the given distance function. Panics if dist is nil.
func (*Forest) Add ¶
Add inserts a word into the forest, routing it to the tree keyed by its length.
func (*Forest) Exists ¶
Exists returns true if there exists at least one word in the forest within maxDist of the query word. Short-circuits on first match.