{"id":25009102,"url":"https://github.com/mrdav30/swiftcollections","last_synced_at":"2026-07-01T06:01:29.132Z","repository":{"id":275857133,"uuid":"911261401","full_name":"mrdav30/SwiftCollections","owner":"mrdav30","description":"A high-performance, memory-efficient library of collections designed for game development, simulations, and other performance-critical applications.","archived":false,"fork":false,"pushed_at":"2025-02-21T04:15:37.000Z","size":279,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-23T17:13:09.882Z","etag":null,"topics":["collections","csharp","data-structures","dotnet","game-development","memory-management","object-pooling","observables","performance","unity"],"latest_commit_sha":null,"homepage":"","language":"C#","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/mrdav30.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2025-01-02T15:54:54.000Z","updated_at":"2025-02-21T04:08:00.000Z","dependencies_parsed_at":"2025-02-05T00:29:26.012Z","dependency_job_id":null,"html_url":"https://github.com/mrdav30/SwiftCollections","commit_stats":null,"previous_names":["mrdav30/swiftcollections"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdav30%2FSwiftCollections","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdav30%2FSwiftCollections/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdav30%2FSwiftCollections/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrdav30%2FSwiftCollections/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrdav30","download_url":"https://codeload.github.com/mrdav30/SwiftCollections/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250477810,"owners_count":21437049,"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","csharp","data-structures","dotnet","game-development","memory-management","object-pooling","observables","performance","unity"],"created_at":"2025-02-05T04:12:28.556Z","updated_at":"2026-07-01T06:01:29.109Z","avatar_url":"https://github.com/mrdav30.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftCollections\n\n![SwiftCollections Icon](https://raw.githubusercontent.com/mrdav30/SwiftCollections/main/icon.png)\n\n[![Build](https://github.com/mrdav30/SwiftCollections/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/mrdav30/SwiftCollections/actions/workflows/build-and-test.yml)\n[![Coverage](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fmrdav30.github.io%2FSwiftCollections%2FSummary.json\u0026query=%24.summary.linecoverage\u0026suffix=%25\u0026label=coverage\u0026color=brightgreen)](https://mrdav30.github.io/SwiftCollections/)\n[![NuGet](https://img.shields.io/nuget/v/SwiftCollections.svg)](https://www.nuget.org/packages/SwiftCollections)\n[![NuGet Downloads](https://img.shields.io/nuget/dt/SwiftCollections.svg)](https://www.nuget.org/packages/SwiftCollections)\n[![License](https://img.shields.io/github/license/mrdav30/SwiftCollections.svg)](https://github.com/mrdav30/SwiftCollections/blob/main/LICENSE)\n[![Frameworks](https://img.shields.io/badge/frameworks-netstandard2.1%20%7C%20net8.0-512BD4.svg)](https://github.com/mrdav30/SwiftCollections)\n\nSwiftCollections is a performance-oriented collection library for .NET systems that care about hot-path cost: simulations, games, spatial queries, deterministic runtimes, and allocation-sensitive tooling.\n\nThe standard .NET collections are excellent general-purpose defaults. SwiftCollections is for the places where you need more control over storage layout, pooling, dense iteration, externally owned integer IDs, deterministic string hashing, or broad-phase spatial query structures. It is not meant to replace every `List\u003cT\u003e` or `Dictionary\u003cTKey, TValue\u003e` in an application. It is meant to give performance-critical code a sharper set of tools.\n\n## Why Use It\n\n- Low-allocation collection types for repeated simulation and gameplay loops.\n- Hash tables, lists, queues, stacks, buckets, packed sets, sparse sets, and sparse maps with APIs designed for predictable hot-path behavior.\n- Dense integer-ID membership and value lookup through `SwiftSparseSet` and `SwiftSparseMap\u003cT\u003e`.\n- Stable-handle storage through `SwiftBucket\u003cT\u003e` and generation-checked handles through `SwiftGenerationalBucket\u003cT\u003e`.\n- Spatial query structures: BVH, spatial hash, and octree implementations over `System.Numerics` volumes, plus fixed-point companions through `SwiftCollections.FixedMathSharp`.\n- Optional MemoryPack serialization in standard packages, with lean variants for projects that want the same core APIs without MemoryPack.\n- Benchmarks and high coverage are part of the repo workflow, not an afterthought.\n\n## Packages\n\nChoose the package that matches your runtime and serialization needs.\n\n| Package | Use When |\n| --- | --- |\n| `SwiftCollections` | You want the core collections with MemoryPack support. |\n| `SwiftCollections.Lean` | You want the core collections without the MemoryPack dependency. |\n| `SwiftCollections.FixedMathSharp` | You need fixed-point BVH, octree, or spatial hash volume wrappers backed by FixedMathSharp. |\n| `SwiftCollections.FixedMathSharp.Lean` | You need the fixed-point companion without MemoryPack. |\n\n```bash\ndotnet add package SwiftCollections\ndotnet add package SwiftCollections.Lean\ndotnet add package SwiftCollections.FixedMathSharp\ndotnet add package SwiftCollections.FixedMathSharp.Lean\n```\n\nThe standard and lean variants expose the same core collection APIs. The difference is whether MemoryPack is included. If you are targeting Unity Burst AOT or already have a serializer pipeline, prefer the lean variants.\n\nUnity package support lives in a separate repository: [SwiftCollections-Unity](https://github.com/mrdav30/SwiftCollections-Unity).\n\n## Picking A Container\n\n| Use case | Better fit |\n| --- | --- |\n| General key/value lookup with arbitrary keys | `SwiftDictionary\u003cTKey, TValue\u003e` |\n| General unique values | `SwiftHashSet\u003cT\u003e` |\n| Fast list, queue, stack, or sorted-list operations | `SwiftList\u003cT\u003e`, `SwiftQueue\u003cT\u003e`, `SwiftStack\u003cT\u003e`, `SwiftSortedList\u003cT\u003e` |\n| Store objects and receive stable integer slots | `SwiftBucket\u003cT\u003e` |\n| Store objects and guard against stale handles | `SwiftGenerationalBucket\u003cT\u003e` |\n| Track membership for compact externally owned integer IDs | `SwiftSparseSet` |\n| Attach values to compact externally owned integer IDs | `SwiftSparseMap\u003cT\u003e` |\n| Store densely iterated unique values with hash-backed membership checks | `SwiftPackedSet\u003cT\u003e` |\n| Arbitrary, huge, or widely sparse integer IDs | `SwiftHashSet\u003cint\u003e` or `SwiftDictionary\u003cint, T\u003e` |\n| Broad-phase spatial queries | `SwiftBVH\u003cTKey\u003e`, `SwiftSpatialHash\u003cTKey\u003e`, `SwiftOctree\u003cTKey\u003e` |\n\nMore detail is available in the [library overview](https://github.com/mrdav30/SwiftCollections/blob/main/docs/OVERVIEW.md).\n\n## Quick Examples\n\n### Sparse Membership For External IDs\n\n```csharp\nusing SwiftCollections;\n\nvar activeBodies = new SwiftSparseSet();\n\nactiveBodies.Add(42);\nactiveBodies.Add(128);\n\nif (activeBodies.Contains(42))\n{\n    activeBodies.Remove(42);\n}\n\nforeach (int bodyId in activeBodies)\n{\n    // Dense iteration over active IDs.\n}\n\nvar sortedBodyIds = new SwiftList\u003cint\u003e(activeBodies.Count);\nactiveBodies.CopySortedKeysTo(sortedBodyIds);\n```\n\n### Sparse Values For External IDs\n\n```csharp\nusing System.Numerics;\nusing SwiftCollections;\n\nvar positions = new SwiftSparseMap\u003cVector3\u003e();\n\npositions[128] = new Vector3(10, 0, 4);\n\nif (positions.TryGetValue(128, out Vector3 position))\n{\n    positions[128] = position + new Vector3(1, 0, 0);\n}\n\nvar sortedPositionIds = new SwiftList\u003cint\u003e(positions.Count);\npositions.CopySortedKeysTo(sortedPositionIds);\n```\n\n### Scratch List Sorting\n\n```csharp\nusing SwiftCollections;\n\nvar keys = new SwiftList\u003cint\u003e { 12, 4, 8 };\nkeys.SortInPlace();\n\n// keys: 4, 8, 12\n```\n\n### Stable Handles\n\n```csharp\nusing System;\nusing SwiftCollections;\n\nvar bodies = new SwiftGenerationalBucket\u003cstring\u003e();\n\nSwiftHandle handle = bodies.Add(\"player\");\n\nif (bodies.TryGet(handle, out string body))\n{\n    Console.WriteLine(body);\n}\n\nbodies.Remove(handle);\n```\n\n### Spatial Queries\n\n```csharp\nusing System.Numerics;\nusing SwiftCollections;\nusing SwiftCollections.Query;\n\nvar bvh = new SwiftBVH\u003cint\u003e(capacity: 128);\n\nbvh.Insert(\n    1,\n    new BoundVolume(\n        new Vector3(0, 0, 0),\n        new Vector3(1, 1, 1)));\n\nvar results = new SwiftList\u003cint\u003e();\nbvh.Query(\n    new BoundVolume(\n        new Vector3(-1, -1, -1),\n        new Vector3(2, 2, 2)),\n    results);\n```\n\n## Serialization And Diagnostics\n\nMost core types expose state-backed serialization support. Standard packages include MemoryPack support; lean packages compile the same public collection surface without taking a MemoryPack dependency. `net8.0` builds use System.Text.Json converter implementations where supported, while older targets use compatibility shims.\n\nDiagnostics are opt-in through `SwiftCollections.Diagnostics`. Disabled diagnostic writes are designed to avoid doing formatting work when the requested level is below the channel minimum, and guard helpers use lazy exception-message formatting for condition-gated throws.\n\n## Development\n\nBuild the solution:\n\n```bash\ndotnet build SwiftCollections.slnx -c Debug\n```\n\nRun the unit tests:\n\n```bash\ndotnet test tests/SwiftCollections.Tests/SwiftCollections.Tests.csproj -c Debug --no-build\n```\n\nRun coverage with the shared runsettings:\n\n```bash\ndotnet test tests/SwiftCollections.Tests/SwiftCollections.Tests.csproj -c Debug --no-build --collect:\"XPlat Code Coverage\" --settings tests/SwiftCollections.Tests/coverlet.runsettings\n```\n\nRun benchmarks:\n\n```bash\ndotnet run --project tests/SwiftCollections.Benchmarks/SwiftCollections.Benchmarks.csproj -c Release -f net8 -- list\ndotnet run --project tests/SwiftCollections.Benchmarks/SwiftCollections.Benchmarks.csproj -c Release -f net8 -- dictionary\ndotnet run --project tests/SwiftCollections.Benchmarks/SwiftCollections.Benchmarks.csproj -c Release -f net8 -- query --list flat\ndotnet run --project tests/SwiftCollections.Benchmarks/SwiftCollections.Benchmarks.csproj -c Release -f net8 -- all --list flat\n```\n\n## Compatibility\n\n- Library targets: `netstandard2.1` and `net8.0`\n- Test target: `net8.0`\n- Benchmark target: `net8`\n- CI covers `Release` and `ReleaseLean` on Windows and Linux\n\n## Community And License\n\nQuestions and discussion are welcome in the [Discord community](https://discord.gg/mhwK2QFNBA). Bug reports and feature requests should be opened as GitHub issues.\n\nSwiftCollections is licensed under the MIT License. See `LICENSE`, `NOTICE`, and `COPYRIGHT` for license, branding, and authorship details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrdav30%2Fswiftcollections","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrdav30%2Fswiftcollections","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrdav30%2Fswiftcollections/lists"}