{"id":21173923,"url":"https://github.com/zigzedd/zollections","last_synced_at":"2025-08-01T05:38:15.770Z","repository":{"id":258590779,"uuid":"871101179","full_name":"zigzedd/zollections","owner":"zigzedd","description":"[MIRROR] Zig collections library.","archived":false,"fork":false,"pushed_at":"2024-10-16T09:55:44.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-21T11:15:32.987Z","etag":null,"topics":["collections","zig","zig-library","zig-package"],"latest_commit_sha":null,"homepage":"https://code.zeptotech.net/zedd/zollections","language":"Zig","has_issues":false,"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/zigzedd.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-10-11T09:17:44.000Z","updated_at":"2025-01-08T22:24:08.000Z","dependencies_parsed_at":"2024-10-19T18:36:12.915Z","dependency_job_id":null,"html_url":"https://github.com/zigzedd/zollections","commit_stats":null,"previous_names":["zigzedd/zollections"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zigzedd%2Fzollections","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zigzedd%2Fzollections/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zigzedd%2Fzollections/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zigzedd%2Fzollections/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zigzedd","download_url":"https://codeload.github.com/zigzedd/zollections/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243624103,"owners_count":20321029,"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","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":["collections","zig","zig-library","zig-package"],"created_at":"2024-11-20T16:52:45.892Z","updated_at":"2025-03-14T18:16:50.129Z","avatar_url":"https://github.com/zigzedd.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\t\u003ca href=\"https://code.zeptotech.net/zedd/zollections\"\u003e\n\t\t\u003cpicture\u003e\n\t\t\t\u003cimg alt=\"Zollections logo\" width=\"150\" src=\"https://code.zeptotech.net/zedd/zollections/raw/branch/main/logo.svg\" /\u003e\n\t\t\u003c/picture\u003e\n\t\u003c/a\u003e\n\u003c/p\u003e\n\n\u003ch1 align=\"center\"\u003e\n\tZollections\n\u003c/h1\u003e\n\n\u003ch4 align=\"center\"\u003e\n\t\u003ca href=\"https://code.zeptotech.net/zedd/zollections\"\u003eDocumentation\u003c/a\u003e\n|\n\t\u003ca href=\"https://zedd.zeptotech.net/zollections/api\"\u003eAPI\u003c/a\u003e\n\u003c/h4\u003e\n\n\u003cp align=\"center\"\u003e\n\tZig collections library\n\u003c/p\u003e\n\nZollections is part of [_zedd_](https://code.zeptotech.net/zedd), a collection of useful libraries for zig.\n\n## Zollections\n\n_Zollections_ is a collections library for Zig. It's made to ease memory management of dynamically allocated slices and elements.\n\n## Versions\n\nZollections 0.1.1 is made and tested with zig 0.13.0.\n\n## How to use\n\n### Install\n\nIn your project directory:\n\n```shell\n$ zig fetch --save https://code.zeptotech.net/zedd/zollections/archive/v0.1.1.tar.gz\n```\n\nIn `build.zig`:\n\n```zig\n// Add zollections dependency.\nconst zollections = b.dependency(\"zollections\", .{\n\t.target = target,\n\t.optimize = optimize,\n});\nexe.root_module.addImport(\"zollections\", zollections.module(\"zollections\"));\n```\n\n### Examples\n\nThese examples are taken from tests in [`tests/collection.zig`](https://code.zeptotech.net/zedd/zollections/src/branch/main/tests/collection.zig).\n\n#### Simple collection\n\n```zig\n// Allocate your slice.\nconst slice = try allocator.alloc(*u8, 3);\n// Create your slice elements.\nslice[0] = try allocator.create(u8);\nslice[1] = try allocator.create(u8);\nslice[2] = try allocator.create(u8);\n\n// Create a collection with your slice of elements.\nconst collection = try zollections.Collection(u8).init(allocator, slice);\n// Free your collection: your slice and all your elements will be freed.\ndefer collection.deinit();\n```\n\n#### Recursive free\n\n```zig\n// Create a pointer to a slice.\nconst slicePointer = try allocator.create([]*u8);\n\n// Allocate your slice in the pointed slice.\nslicePointer.* = try allocator.alloc(*u8, 3);\n// Create slice elements.\nslicePointer.*[0] = try allocator.create(u8);\nslicePointer.*[1] = try allocator.create(u8);\nslicePointer.*[2] = try allocator.create(u8);\n\n// Allocate your slice or pointers to slices.\nconst slice = try allocator.alloc(*[]*u8, 1);\nslice[0] = slicePointer;\n\n// Create a collection with your slice of elements.\nconst collection = try zollections.Collection([]*u8).init(allocator, slice);\n// Free your collection: your slice and all your slices and their elements will be freed.\ndefer collection.deinit();\n```\n\n#### Custom structure deinitialization\n\n```zig\n\n/// An example structure.\nconst ExampleStruct = struct {\n\tconst Self = @This();\n\n\tallocator: std.mem.Allocator,\n\tbuffer: []u8,\n\n\t/// Initialize a new example struct.\n\tpub fn init(bufSiz: usize) !Self\n\t{\n\t\tconst allocator = std.testing.allocator;\n\n\t\treturn .{\n\t\t\t.allocator = allocator,\n\t\t\t.buffer = try allocator.alloc(u8, bufSiz),\n\t\t};\n\t}\n\n\t/// Deinitialize the example struct.\n\tpub fn deinit(self: *Self) void\n\t{\n\t\tself.allocator.free(self.buffer);\n\t}\n};\n\n// Allocate your slice.\nconst slice = try allocator.alloc(*ExampleStruct, 3);\n// Create your slice elements with custom structs and their inner init / deinit.\nslice[0] = try allocator.create(ExampleStruct);\nslice[0].* = try ExampleStruct.init(4);\nslice[1] = try allocator.create(ExampleStruct);\nslice[1].* = try ExampleStruct.init(8);\nslice[2] = try allocator.create(ExampleStruct);\nslice[2].* = try ExampleStruct.init(16);\n\n// Create a collection with your slice of elements.\nconst collection = try zollections.Collection(ExampleStruct).init(allocator, slice);\n// Free your collection: your slice and all your elements will be deinitialized and freed.\ndefer collection.deinit();\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzigzedd%2Fzollections","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzigzedd%2Fzollections","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzigzedd%2Fzollections/lists"}