https://github.com/mrdav30/swiftcollections
A high-performance, memory-efficient library of collections designed for game development, simulations, and other performance-critical applications.
https://github.com/mrdav30/swiftcollections
collections csharp data-structures dotnet game-development memory-management object-pooling observables performance unity
Last synced: 11 months ago
JSON representation
A high-performance, memory-efficient library of collections designed for game development, simulations, and other performance-critical applications.
- Host: GitHub
- URL: https://github.com/mrdav30/swiftcollections
- Owner: mrdav30
- License: mit
- Created: 2025-01-02T15:54:54.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-21T04:15:37.000Z (about 1 year ago)
- Last Synced: 2025-04-23T17:13:09.882Z (11 months ago)
- Topics: collections, csharp, data-structures, dotnet, game-development, memory-management, object-pooling, observables, performance, unity
- Language: C#
- Homepage:
- Size: 272 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
SwiftCollections
==============

[](https://github.com/mrdav30/SwiftCollections/actions/workflows/dotnet.yml)
**SwiftCollections** is a high-performance, memory-efficient library of collections designed for game development, simulations, and other performance-critical applications.
---
## ๐ ๏ธ Key Features
- **Optimized for Performance**: Designed for low time complexity and minimal memory allocations.
- **Versatile Use Cases**: Suitable for data structures in 3D environments and complex spatial queries.
- **Unity-Compatible**: Fully functional within Unity's ecosystem.
- **Customizable**: Use pre-built implementations or extend functionality with custom interfaces.
---
## Dependencies
- Requires [FixedMathSharp](https://github.com/mrdav30/FixedMathSharp).
---
## ๐ Installation
Clone the repository and add it to your project:
### Non-Unity Projects
1. **Install via NuGet**:
- Add SwiftCollections to your project using the following command:
```bash
dotnet add package SwiftCollections
```
2. **Or Download/Clone**:
- Clone the repository or download the source code.
```bash
git clone https://github.com/mrdav30/SwiftCollections.git
```
3. **Add to Project**:
- Include the `SwiftCollections` project or its DLLs in your build process.
### Unity
SwiftCollections is now maintained as a separate Unity package. For Unity-specific implementations, refer to:
๐ [SwiftCollection-Unity Repository](https://github.com/mrdav30/SwiftCollections-Unity).
---
## ๐งฉ Dependencies
SwiftCollections depends on the following library:
- [FixedMathSharp](https://github.com/mrdav30/FixedMathSharp)
This dependency is automatically included when installing.
---
## ๐ฆ Library Overview
### Core Data Structures
- **SwiftDictionary**: A high-performance dictionary optimized for O(1) operations and minimal memory usage.
- **SwiftBiDictionary**: A bidirectional dictionary for efficient forward and reverse lookups in O(1).
- **SwiftHashSet**: An optimized set for unique values with fast operations.
- **SwiftBucket**: High-performance collection for O(1) addition and removal with stable indexing.
- **SwiftQueue**: Circular-buffer-based queue for ultra-low-latency operations.
- **SwiftList**: A dynamic list optimized for speed-critical applications.
- **SwiftSortedList**: Dynamically sorted collection with O(log n) operations.
- **SwiftStack**: Fast array-based stack with O(1) operations.
- **SwiftArray2D / SwiftArray3D**: Efficient, flat-mapped arrays for 2D and 3D data.
- **SwiftBVH**: A Bounding Volume Hierarchy optimized for spatial queries.
### Pools
- **SwiftObjectPool**: Thread-safe generic object pooling for improved memory usage and performance.
- **SwiftArrayPool**: Array-specific pool for efficient reuse of arrays.
- **SwiftCollectionPool**: Pool for reusable collection instances (e.g., List, HashSet).
### Spatial Data Structures
- **SwiftBVH**: Bounding Volume Hierarchy for efficient spatial queries.
### Observable Collections
- **ObservableArray / ObservableSwiftList / ObservableDictionary**: Reactive, observable collections with property and collection change notifications.
## ๐ Usage Examples
### SwiftBVH for Spatial Queries
```csharp
var bvh = new SwiftBVH(100);
var volume = new BoundingVolume(new Vector3(0, 0, 0), new Vector3(1, 1, 1));
bvh.Insert(1, volume);
var results = new List();
bvh.Query(new BoundingVolume(new Vector3(0, 0, 0), new Vector3(2, 2, 2)), results);
Console.WriteLine(results.Count); // Output: 1
```
### SwiftArray2D
```csharp
var array2D = new Array2D(10, 10);
array2D[3, 4] = 42;
Console.WriteLine(array2D[3, 4]); // Output: 42
```
### SwiftQueue
```csharp
var queue = new SwiftQueue(10);
queue.Enqueue(5);
Console.WriteLine(queue.Dequeue()); // Output: 5
```
### Populating Arrays
```csharp
var array = new int[10].Populate(() => new Random().Next(1, 100));
```
## ๐งช Testing and Validation
SwiftCollections includes a comprehensive suite of xUnit tests for validation.
### Running Unit Tests
To execute all unit tests, use the following command:
```bash
dotnet test -c debug
```
### Running Benchmarks
The library includes benchmarks to measure the performance of its collections. Benchmarks are powered by BenchmarkDotNet and can be run as follows:
1. Open the SwiftCollections.Benchmarks project.
2. Modify the Program.cs file to select the desired benchmark. Uncomment the relevant BenchmarkRunner lines.
- Example Program.cs setup:
```csharp
using BenchmarkDotNet.Running;
namespace SwiftCollections.Benchmarks
{
class Program
{
static void Main(string[] args)
{
// Uncomment the benchmark you want to run:
// var ListIntegerBenchmarksSummary = BenchmarkRunner.Run();
var StackIntegerBenchmarksSummary = BenchmarkRunner.Run();
// var DictionaryStringBenchmarksSummary = BenchmarkRunner.Run();
}
}
}
```
3. Build and run the project. The results will be displayed in the console and saved to a results file for further analysis.
## ๐ ๏ธ Compatibility
- **.NET Framework** 4.7.2+
- **Unity 2020+** (via - [SwiftCollection-Unity](https://github.com/mrdav30/SwiftCollections-Unity).)
- **Cross-Platform Support** (Windows, Linux, macOS)
- **Query Collections Precision**: Supports both System.Numerics and FixedMathSharp.
## ๐ License
This project is licensed under the MIT License - see the `LICENSE` file
for details.
---
## ๐ฅ Contributors
- **mrdav30** - Lead Developer
- Contributions are welcome! Feel free to submit pull requests or report issues.
---
## ๐ง Contact
For questions or support, reach out to **mrdav30** via GitHub or open an issue in the repository.
---