Note
Still very WIP
A string similarity library for Lua/LuaJIT providing edit distance and similarity algorithms.
Check this out:
Note
Library will be deployed to luarocks at some point
Currently you will have to clone the repository manaully
git clone https://github.com/yourusername/strsim.gitTip
Or add as a dependency in your Lua path.
local strsim = require("init")
local dist = strsim.distance("kitten", "sitting") -- 3
local sim = strsim.similarity("hello", "hallo") -- 0.8
-- Use specific algorithm
local dist = strsim.distance("hello", "hallo", strsim.Algorithm.LEVENSHTEIN)Note
If no algorithm is selected we will default to LEVENSHTEIN
local levenshtein = require("algorithms.levenshtein")
local dist = levenshtein.distance("kitten", "sitting") -- 3
local sim = levenshtein.similarity("hello", "hallo") -- 0.8Note
Only LEVENSHTEIN distance is supported currently
Levenshtein distance is a string metric for measuring the difference between two sequences.
Check this out: https://en.wikipedia.org/wiki/Levenshtein_distance
Optimizations applied
- Single-row DP (O(min(m,n)) space instead of O(m*n))
- Early termination for equal strings
- Stripping common prefix/suffix
- Swapping strings to minimize memory usage
- Avoiding table.insert, using direct indexing
- Using byte access instead of sub() for single chars
Lua JIT specific optimizations applied:
- Using local variables for hot paths (LuaJIT optimization)
Note
Planned
Note
Planned
Note
Planned
Note
Planned
Note
Planned
Note
Planned