ErinnArrayQueue 1.0.1

Suggested Alternatives

crossbeam-queue

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package ErinnArrayQueue --version 1.0.1
                    
NuGet\Install-Package ErinnArrayQueue -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ErinnArrayQueue" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ErinnArrayQueue" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="ErinnArrayQueue" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ErinnArrayQueue --version 1.0.1
                    
#r "nuget: ErinnArrayQueue, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ErinnArrayQueue@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ErinnArrayQueue&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=ErinnArrayQueue&version=1.0.1
                    
Install as a Cake Tool

ErinnArrayQueue

NuGet

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

  • Capacity is fixed for the lifetime of the queue.
  • Multiple producers and consumers can enqueue and dequeue concurrently.
  • TryEnqueue leaves the queue unchanged and returns false when it is full.
  • TryDequeue returns false and sets its out value to the default value of T when the queue is empty.
  • IsEmpty, IsFull, and Count report the observed queue state. Concurrent operations can change that state immediately after a property is read.
  • Capacity and Count use the native-sized unsigned type nuint.

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

  • 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