{"id":23333472,"url":"https://github.com/insolor/zig-collections","last_synced_at":"2026-04-25T23:00:46.677Z","repository":{"id":268918816,"uuid":"905858606","full_name":"insolor/zig-collections","owner":"insolor","description":"Implementation of some useful data structures in Zig. Inspired by Python's collections module.","archived":false,"fork":false,"pushed_at":"2026-04-21T17:19:17.000Z","size":369,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-21T19:25:24.143Z","etag":null,"topics":["zig","zig-library","zig-package","ziglang"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/insolor.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-12-19T17:00:15.000Z","updated_at":"2026-04-21T17:19:00.000Z","dependencies_parsed_at":"2024-12-19T18:18:49.088Z","dependency_job_id":"00887c3c-d81e-4531-8a63-6bb45963f968","html_url":"https://github.com/insolor/zig-collections","commit_stats":null,"previous_names":["insolor/zig-collections"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/insolor/zig-collections","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/insolor%2Fzig-collections","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/insolor%2Fzig-collections/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/insolor%2Fzig-collections/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/insolor%2Fzig-collections/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/insolor","download_url":"https://codeload.github.com/insolor/zig-collections/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/insolor%2Fzig-collections/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32279660,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-25T18:29:39.964Z","status":"ssl_error","status_checked_at":"2026-04-25T18:29:32.149Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["zig","zig-library","zig-package","ziglang"],"created_at":"2024-12-21T00:17:21.176Z","updated_at":"2026-04-25T23:00:46.664Z","avatar_url":"https://github.com/insolor.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Zig Collections\n\n[![Zig 0.14.0, 0.14.1, 0.15.1, 0.15.2, 0.16.0, master](https://img.shields.io/badge/Zig-0.14.0%20%7C%200.14.1%20%7C%200.15.1%20%7C%200.15.2%20%7C%200.16.0%20%7C%20master-color?logo=zig\u0026color=%23f3ab20)](https://ziglang.org/download/) \u003c!-- see zig tag examples at https://github.com/KurtWagner/what-the-zig --\u003e\n[![zig build test](https://github.com/insolor/zig-collections/actions/workflows/zig-build-test.yml/badge.svg)](https://github.com/insolor/zig-collections/actions/workflows/zig-build-test.yml)\n[![documentation](https://img.shields.io/badge/docs-mkdocs-708FCC.svg?style=flat)](https://insolor.github.io/zig-collections/)\n\nImplementation of some useful data structures in Zig. Inspired by Python's [`collections`](https://docs.python.org/3/library/collections.html) module.\n\n## Installation\n\n1. In the root directory of your project, run the following command to add `zig_collections` to your `build.zig.zon` file (replace 0.0.2 with the latest release number):\n\n    ```bash\n    zig fetch --save https://github.com/insolor/zig-collections/archive/refs/tags/0.0.2.zip\n    ```\n\n    Replace `main` in the URL with the tag you want to use.\n\n2. Add zig_collections as a dependency module in your `build.zig` file, example:\n\n    ```zig\n    const zig_collections = b.dependency(\"zig_collections\", .{});\n    exe.root_module.addImport(\"zig_collections\", zig_collections.module(\"zig_collections\"));\n    ```\n\nAfter that, you'll be able to import `zig_collections` namespace from your code:\n\n```zig\nconst zig_collections = @import(\"zig_collections\");\nconst Counter = zig_collections.Counter;\nconst DefaultHashMap = zig_collections.DefaultHashMap;\n```\n\n## Usage examples\n\nImplemented so far:\n\n- ✅ `Counter`:\n  - a minimal functionality is implemented: increment of a value of a key, counting of duplicate values from a slice or an iterator\n- ✅ `defaultdict` (`DefaultHashMap`)\n\n### `Counter` usage examples\n\n```zig\ntest \"add from slice\" {\n    var counter = Counter(u8).init(allocator);\n    defer counter.deinit();\n\n    const array = [_]u8{ 1, 2, 2, 3, 3, 3 };\n    try counter.addFromSlice(array[0..]);\n    try expectEqual(1, counter.get(1));\n    try expectEqual(2, counter.get(2));\n    try expectEqual(3, counter.get(3));\n}\n\ntest \"add from iterator\" {\n    var counter = Counter([]const u8).init(allocator);\n    defer counter.deinit();\n\n    const text = \"alice bob alice\";\n    var iterator = std.mem.splitScalar(u8, text, ' ');\n    try counter.addFromIterator(\u0026iterator);\n    try expectEqual(2, counter.get(\"alice\"));\n    try expectEqual(1, counter.get(\"bob\"));\n}\n```\n\n### `DefaultHashMap` example\n\n```zig\ntest \"DefaultHashMap with list\" {\n    const EmptyArrayListFactory = struct {\n        allocator: std.mem.Allocator,\n\n        fn produce(self: @This()) ArrayList(u8) {\n            return ArrayList(u8).init(self.allocator);\n        }\n    };\n\n    var map = collections.DefaultHashMap(\n        u8,\n        ArrayList(u8),\n        EmptyArrayListFactory{ .allocator = allocator },\n        EmptyArrayListFactory.produce,\n    ).init(allocator);\n\n    defer map.deinit();\n\n    const array = [_]u8{ 3, 3, 1, 2, 3, 2 };\n    for (array, 0..) |item, i| {\n        try map.get(item).append(@intCast(i));\n    }\n\n    try expectEqualDeep(\u0026[_]u8{2}, map.get(1).items);\n    try expectEqualDeep(\u0026[_]u8{ 3, 5 }, map.get(2).items);\n    try expectEqualDeep(\u0026[_]u8{ 0, 1, 4 }, map.get(3).items);\n}\n```\n\nCorresponding Python code:\n\n```python\nfrom collections import defaultdict\n\ndmap = defaultdict(list)\n\narray = [3, 3, 1, 2, 3, 2]\nfor i, item in enumerate(array):\n    dmap[item].append(i)\n\nassert [2] == dmap[1]\nassert [3, 5] == dmap[2]\nassert [0, 1, 4] == dmap[3]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finsolor%2Fzig-collections","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finsolor%2Fzig-collections","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finsolor%2Fzig-collections/lists"}