{"id":13741630,"url":"https://github.com/aalbacetef/strcompare","last_synced_at":"2025-07-22T06:05:44.194Z","repository":{"id":241364635,"uuid":"798836360","full_name":"aalbacetef/strcompare","owner":"aalbacetef","description":"strcompare is a library for comparing strings using Hamming, Levenshtein, and Damerau-Levenshtein metrics.","archived":false,"fork":false,"pushed_at":"2024-09-27T22:19:12.000Z","size":32,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T14:49:27.349Z","etag":null,"topics":["damerau-levenshtein","hamming-distance","levenshtein","levenshtein-distance","string-comparison","zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aalbacetef.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-10T15:17:18.000Z","updated_at":"2025-01-21T17:56:22.000Z","dependencies_parsed_at":"2024-05-28T01:24:49.865Z","dependency_job_id":"6ba1f33c-70c2-4dbc-a0e6-a69f60300419","html_url":"https://github.com/aalbacetef/strcompare","commit_stats":null,"previous_names":["aalbacetef/strcompare"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/aalbacetef/strcompare","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aalbacetef%2Fstrcompare","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aalbacetef%2Fstrcompare/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aalbacetef%2Fstrcompare/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aalbacetef%2Fstrcompare/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aalbacetef","download_url":"https://codeload.github.com/aalbacetef/strcompare/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aalbacetef%2Fstrcompare/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266437373,"owners_count":23928235,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["damerau-levenshtein","hamming-distance","levenshtein","levenshtein-distance","string-comparison","zig"],"created_at":"2024-08-03T04:01:01.101Z","updated_at":"2025-07-22T06:05:44.168Z","avatar_url":"https://github.com/aalbacetef.png","language":"Zig","readme":"![CI status](https://github.com/aalbacetef/strcompare/actions/workflows/ci.yml/badge.svg)   [![License](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)\n\n\n# strcompare\n\n\n`strcompare` is a zig library implementing 3 of the most common string comparison algorithms:\n \n - Hamming distance\n - Levenshtein distance \n - Damerau-Levenshtein distance (specifically, the optimal string alignment distance)\n\n## Usage \n\nThe library provides two convenience functions: `similarity` and `distance`.\n\nBoth functions accept a `Metrics` argument, one of:\n\n```zig\npub const Metrics = enum { \n    Damerau,\n    Hamming,\n    Levenshtein,\n};\n```\n\n#### distance \n\n`distance` will return the edit distance, a `u64`.\n\nIt accepts the following arguments:\n - alloc: an `std.mem.Allocator`\n - metric: one of the `Metrics`\n - a, b: strings to compare\n\nExample:\n\n```zig\nconst a = \"kitten\";\nconst b = \"sitting\";\n\nconst d = distance(alloc, Metrics.Levenshtein, a, b);\n\nstd.debug.print(\"distance: {d}\\n\", .{d}); \n// \n// distance: 3\n//\n```\n\n#### similarity\n\n`similarity` returns a weighted distance, that is, an `f64` from `0.0` to `1.0`. \nIt will return `0.0` if the strings differ completely and `1.0` if they are identical.\n\nIt accepts the following arguments:\n - alloc: an `std.mem.Allocator`\n - metric: one of the `Metrics`\n - a, b: strings to compare\n\n\nExample:\n\n```zig\nconst a = \"kitten\";\nconst b = \"sitting\";\n\nconst d = similarity(alloc, Metrics.Levenshtein, a, b);\n\nstd.debug.print(\"similarity: {d:.0}%\\n\", .{d*100.0}); \n// \n// similarity: 57%\n//\n```\n\n## Installing\n\nAfter acquiring the repo's code, run:\n\n```bash\nzig fetch --save ./path/to/strcompare \n```\n\nthen add the following to your `build.zig`\n\n```zig\n    const pkg = b.dependency(\"strcompare\", .{});\n    exe.root_module.addImport(\"strcompare\", pkg.module(\"strcompare\"));\n\n```\n\nDo the same for your tests:\n\n```zig\n\n    const exe_unit_tests = b.addTest(.{\n        .root_source_file = b.path(\"src/main.zig\"),\n        .target = target,\n        .optimize = optimize,\n    });\n\n    exe_unit_tests.root_module.addImport(\"strcompare\", pkg.module(\"strcompare\"));\n\n```\n\nYou should now be able to import the module with:\n\n```zig\nconst strcompare = @import(\"strcompare\");\nconst Metrics = strcompare.Metrics;\nconst distance = strcompare.distance;\nconst similarity = strcompare.similarity;\n\nfn dist() !void {\n    const a = \"a\";\n    const b = \"bb\";\n    const alloc = std.heap.page_allocator;\n\n    const d = try distance(alloc, Metrics.Levenshtein, a, b);\n    std.debug.print(\"distance: {d}\\n\", .{d});\n}\n\n```\n","funding_links":[],"categories":["Libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faalbacetef%2Fstrcompare","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faalbacetef%2Fstrcompare","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faalbacetef%2Fstrcompare/lists"}