Skip to content

Repository files navigation

SwiftCollections

SwiftCollections icon

Build Core Branch Coverage NuGet License API Discord

Specialized .NET collections for hot paths that need tighter control over storage, allocation, iteration, and spatial queries.

The BCL collections are excellent defaults. SwiftCollections is for the code where profiling says the default is no longer enough: simulation loops, games, spatial indexing, deterministic runtimes, and allocation-sensitive tooling.

Why SwiftCollections?

  • Low-allocation lists, queues, stacks, hash tables, buckets, packed sets, sparse sets, and sparse maps.
  • Dense iteration and stable or generation-checked handles for entity-style workloads.
  • BVH, spatial hash, and octree queries over System.Numerics volumes.
  • Fixed-point query companions powered by FixedMathSharp.
  • Explicit state-backed serialization, with Standard and Lean package variants.
  • Benchmarks and full reachable coverage enforced as part of the repository workflow.

Install

Choose one package family:

Need Package
Core collections with MemoryPack SwiftCollections
Core collections without the MemoryPack runtime SwiftCollections.Lean
FixedMathSharp spatial queries with MemoryPack SwiftCollections.FixedMathSharp
FixedMathSharp spatial queries without the MemoryPack runtime SwiftCollections.FixedMathSharp.Lean
dotnet add package SwiftCollections

Or install a companion package when you need fixed-point query volumes. NuGet brings in the matching SwiftCollections and FixedMathSharp packages:

dotnet add package SwiftCollections.FixedMathSharp

Use the matching .Lean packages as a pair. Lean keeps the collection APIs but removes the MemoryPack runtime; it is useful when your application owns its serialization stack or wants the smaller dependency surface.

A quick taste

SwiftGenerationalBucket<T> gives you dense storage with handles that stop resolving after their slot is reused:

using System;
using SwiftCollections;

var actors = new SwiftGenerationalBucket<string>();
SwiftHandle player = actors.Add("player");

if (actors.TryGet(player, out string actor))
{
    Console.WriteLine(actor);
}

actors.Remove(player);

For externally owned compact integer IDs, start with SwiftSparseSet or SwiftSparseMap<T>. For broad-phase queries, start with SwiftBVH<TKey>, SwiftSpatialHash<TKey>, or SwiftOctree<TKey>.

Learn more

Using Unity? The maintained SwiftCollections-Unity packages add Unity-serializable adapters, Bounds conversions, GameObject pooling, and FixedMathSharp integration.

Compatibility

The libraries target netstandard2.1 and net8.0. CI validates Standard and Lean builds on Windows and Linux.

Questions and discussion are welcome in the Discord community. SwiftCollections is available under the MIT License.

About

A high-performance, memory-efficient library of collections designed for game development, simulations, and other performance-critical applications.

Topics

Resources

Contributing

Stars

12 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Contributors

Languages