ErinnArrayQueue 1.0.1
dotnet add package ErinnArrayQueue --version 1.0.1
NuGet\Install-Package ErinnArrayQueue -Version 1.0.1
<PackageReference Include="ErinnArrayQueue" Version="1.0.1" />
<PackageVersion Include="ErinnArrayQueue" Version="1.0.1" />
<PackageReference Include="ErinnArrayQueue" />
paket add ErinnArrayQueue --version 1.0.1
#r "nuget: ErinnArrayQueue, 1.0.1"
#:package ErinnArrayQueue@1.0.1
#addin nuget:?package=ErinnArrayQueue&version=1.0.1
#tool nuget:?package=ErinnArrayQueue&version=1.0.1
ErinnArrayQueue
ErinnArrayQueue provides a bounded, fixed-capacity multi-producer, multi-consumer queue. The queue allocates its slot buffer when it is constructed and does not grow when it becomes full.
Basic use
TryEnqueue returns false when the queue is full. TryDequeue returns false when the queue is empty:
using System;
using Erinn;
var queue = new ErinnArrayQueue<string>(capacity: 2);
queue.TryEnqueue("first");
queue.TryEnqueue("second");
if (!queue.TryEnqueue("third"))
Console.WriteLine("The queue is full.");
while (queue.TryDequeue(out var item))
Console.WriteLine(item);
The capacity must be greater than zero. Constructing a queue with a zero or negative capacity
throws ArgumentOutOfRangeException.
Queue behavior
Capacityis fixed for the lifetime of the queue.- Multiple producers and consumers can enqueue and dequeue concurrently.
TryEnqueueleaves the queue unchanged and returnsfalsewhen it is full.TryDequeuereturnsfalseand sets itsoutvalue to the default value ofTwhen the queue is empty.IsEmpty,IsFull, andCountreport the observed queue state. Concurrent operations can change that state immediately after a property is read.CapacityandCountuse the native-sized unsigned typenuint.
Overwriting the oldest element
Enqueue always inserts the new element. If the queue is full, it replaces the oldest element and
returns it through overwritten:
using System;
using Erinn;
var queue = new ErinnArrayQueue<int>(capacity: 2);
queue.Enqueue(10, out _);
queue.Enqueue(20, out _);
if (queue.Enqueue(30, out var overwritten) == InsertResult.Overwritten)
Console.WriteLine(overwritten); // 10
InsertResult.Success means no element was replaced. InsertResult.Overwritten means the oldest
element was replaced. Use the result to distinguish an overwritten null value from the default
value assigned to overwritten when no element was replaced.
Source
The queue follows the bounded MPMC algorithm by Dmitry Vyukov and is based on Crossbeam's
ArrayQueue.
License
ErinnArrayQueue is distributed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- System.Runtime.CompilerServices.Unsafe (>= 6.0.0)
-
net10.0
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|