XenoAtom.Collections
1.0.0
Prefix Reserved
See the version list below for details.
dotnet add package XenoAtom.Collections --version 1.0.0
NuGet\Install-Package XenoAtom.Collections -Version 1.0.0
<PackageReference Include="XenoAtom.Collections" Version="1.0.0" />
paket add XenoAtom.Collections --version 1.0.0
#r "nuget: XenoAtom.Collections, 1.0.0"
// Install XenoAtom.Collections as a Cake Addin #addin nuget:?package=XenoAtom.Collections&version=1.0.0 // Install XenoAtom.Collections as a Cake Tool #tool nuget:?package=XenoAtom.Collections&version=1.0.0
XenoAtom.Collections
<img align="right" width="160px" height="160px" src="https://raw.githubusercontent.com/XenoAtom/XenoAtom.Collections/main/img/XenoAtom.Collections.png">
This .NET library offers structure-based collections optimized for high performance and minimal memory usage. It features UnsafeList<T>
, UnsafeDictionary<TKey, TValue>
, and UnsafeHashSet<T>
. These collections are implemented as value types backed by a managed array, specifically designed for performance-critical scenarios where avoiding additional memory allocations for container objects is essential.
The code has been derived from the .NET Core runtime released under the MIT license.
These collections contains unsafe methods (prefixed by Unsafe) and should be used with caution.
✨ Features
- 3 collections:
UnsafeList<T>
,UnsafeDictionary<TKey, TValue>
andUnsafeHashSet<T>
- Faster access for Dictionary and HashSet by requiring the key to be
IEquatable<TKey>
- Struct based collections to avoid an allocation for the container and improve locality
- Proper debugger support for collections with custom
DebuggerDisplay
- A few advanced unsafe methods to avoid checks
- e.g
Unsafe<T>.UnsafeSetCount
,Unsafe<T>.UnsafeGetRefAt
...
- e.g
- NativeAOT compatible
net8.0
+ support
📖 Usage
UnsafeList<T>
// UnsafeList is a struct, but the underlying array is a managed array var list = new UnsafeList<int>(); list.Add(1); list.Add(2); list.Add(3); list.Add(4); var span = list.AsSpan(); foreach(var value in span) { Console.WriteLine(value); }
UnsafeDictionary<TKey, TValue>
// UnsafeDictionary is a struct, but the underlying array is a managed array var dictionary = new UnsafeDictionary<int, string>(); dictionary.Add(1, "One"); dictionary.Add(2, "Two"); dictionary.Add(3, "Three"); dictionary.Add(4, "Four"); foreach(var pair in dictionary) { Console.WriteLine($"{pair.Key} = {pair.Value}"); }
UnsafeHashSet<T>
// UnsafeDictionary is a struct, but the underlying array is a managed array var hashSet = new UnsafeHashSet<int>(); hashSet.Add(1); hashSet.Add(2); hashSet.Add(3); hashSet.Add(4); foreach(var value in hashSet) { Console.WriteLine(value); }
🪪 License
This software is released under the BSD-2-Clause license.
🤗 Author
Alexandre Mutel aka XenoAtom.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on XenoAtom.Collections:
Package | Downloads |
---|---|
XenoAtom.Allocators
This is a default project description |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on XenoAtom.Collections:
Repository | Stars |
---|---|
amerkoleci/alimer
Cross-platform .NET 8 C# 12 game engine.
|