https://github.com/bcvery1/levenshtein
Implementation of the Levenshtein Distance algorithm
https://github.com/bcvery1/levenshtein
autocomplete autocompletion cli fuzzy fuzzy-search levenshtein levenshtein-distance tooling zig
Last synced: about 1 year ago
JSON representation
Implementation of the Levenshtein Distance algorithm
- Host: GitHub
- URL: https://github.com/bcvery1/levenshtein
- Owner: bcvery1
- License: mit
- Created: 2025-03-28T16:40:04.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-31T10:31:57.000Z (about 1 year ago)
- Last Synced: 2025-03-31T11:29:22.126Z (about 1 year ago)
- Topics: autocomplete, autocompletion, cli, fuzzy, fuzzy-search, levenshtein, levenshtein-distance, tooling, zig
- Language: Zig
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Levenshteien
Implementation of the Levenshtein Distance algorithm in Zig.
## Getting started
### Adding as dependency
First use the following command to add the dependency to your `build.zig.zon`:
```sh
zig fetch --save https://github.com/bcvery1/levenshtein/archive/refs/tags/[RELEASE VERSION].tar.gz
```
You may wish to save the library with a specific name, for example:
```sh
zig fetch --save=lev https://github.com/bcvery1/levenshtein/archive/refs/tags/v0.1.0.tar.gz
```
We'll use the name `lev` the next excerpt.
Next you'll want to add the following to your `build.zig` file:
```zig
const levenshtein = b.dependency("lev", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("lev", levenshtein.module("lev");
```
You can then import and use the library with `const lev = @import("lev");`
### Basic usage
This simple example shows how to use the library to sort and get the closest word to any in a dictionary:
```zig
const std = @import("std");
const lev = @import("lev");
const assert = std.debug.assert;
var strs = [_][]const u8{
"bread",
"vegetables",
"cheese",
"ale",
};
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
const word1 = "a";
try lev.sort_in_place(allocator, word1, &strs, .{});
assert(std.mem.eql(u8, "ale", strs[0]));
const word2 = "vegeta";
try lev.sort_in_place(allocator, word2, &strs, .{});
assert(std.mem.eql(u8, "vegetables", strs[0]));
}
```
For more examples on usage, take a look at the [examples](https://github.com/bcvery1/levenshtein/tree/main/examples) directory.
## Licence
[MIT](./LICENSE)