Class ScyllaPriorityQueue<T>.Builder
Fluent builder for constructing ScyllaPriorityQueue instances with complex configurations. Supports capacity configuration, fixed-capacity mode, heap ordering (min/max), custom comparer, and synchronized wrapper creation.
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public sealed class ScyllaPriorityQueue<T>.Builder
Remarks
The builder provides a discoverable API for configuring priority queues without relying on positional parameters. Use Build() to obtain a configured priority queue (returns interface for synchronized wrappers). Use BuildConcrete() to obtain the concrete unsynchronized priority queue type (throws if synchronized).
// Basic usage with defaults (min-heap)
var queue = ScyllaPriorityQueue<int>.CreateBuilder().Build();
// Configure capacity and max-heap mode
var queue = ScyllaPriorityQueue<string>.CreateBuilder()
.WithCapacity(64)
.MaxHeap()
.Build();
// Custom comparer for case-insensitive string comparison
var queue = ScyllaPriorityQueue<string>.CreateBuilder()
.WithCapacity(128)
.WithComparer(StringComparer.OrdinalIgnoreCase)
.Build();
// Create synchronized (thread-safe) wrapper
var queue = ScyllaPriorityQueue<Task>.CreateBuilder()
.WithCapacity(256)
.Synchronized()
.Build();
Methods
Build()
Builds and returns the configured ScyllaPriorityQueue instance or synchronized wrapper. If Synchronized(object) was called, returns a ScyllaPriorityQueue<T>.SynchronizedScyllaPriorityQueue wrapper. Otherwise, returns the unsynchronized ScyllaPriorityQueue<T>.
Declaration
public IScyllaCollection<T> Build()
Returns
| Type | Description |
|---|---|
| IScyllaCollection<T> | An IScyllaCollection<T> representing either the unsynchronized priority queue or synchronized wrapper |
BuildConcrete()
Builds and returns the concrete unsynchronized ScyllaPriorityQueue<T> instance. This method provides access to the concrete type instead of the interface.
Declaration
public ScyllaPriorityQueue<T> BuildConcrete()
Returns
| Type | Description |
|---|---|
| ScyllaPriorityQueue<T> | The configured unsynchronized ScyllaPriorityQueue instance |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown when Synchronized(object) was called. Use Build() to obtain the synchronized wrapper. |
FixedCapacity(bool)
Enables fixed-capacity mode, preventing automatic growth when the priority queue becomes full. When fixed-capacity is enabled, enqueue operations will return false instead of resizing the buffer.
Declaration
public ScyllaPriorityQueue<T>.Builder FixedCapacity(bool value = true)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | value | True to enable fixed-capacity mode, false to allow automatic growth (default: true) |
Returns
| Type | Description |
|---|---|
| ScyllaPriorityQueue<T>.Builder | This builder instance for method chaining |
MaxHeap()
Configures the priority queue to use Max-heap ordering (largest element has highest priority).
Declaration
public ScyllaPriorityQueue<T>.Builder MaxHeap()
Returns
| Type | Description |
|---|---|
| ScyllaPriorityQueue<T>.Builder | This builder instance for method chaining |
MinHeap()
Configures the priority queue to use Min-heap ordering (smallest element has highest priority). This is the default ordering if neither MinHeap() nor MaxHeap() is called.
Declaration
public ScyllaPriorityQueue<T>.Builder MinHeap()
Returns
| Type | Description |
|---|---|
| ScyllaPriorityQueue<T>.Builder | This builder instance for method chaining |
Synchronized(object)
Configures the builder to return a synchronized (thread-safe) wrapper around the priority queue. All operations on the synchronized wrapper will be protected by a lock.
Declaration
public ScyllaPriorityQueue<T>.Builder Synchronized(object syncRoot = null)
Parameters
| Type | Name | Description |
|---|---|---|
| object | syncRoot | Optional external lock object to use for synchronization. If null, the wrapper creates and owns a private lock. Provide a custom sync root to coordinate synchronization across multiple synchronized collections. |
Returns
| Type | Description |
|---|---|
| ScyllaPriorityQueue<T>.Builder | This builder instance for method chaining |
WithCapacity(int)
Sets the initial capacity of the priority queue backing buffer.
Declaration
public ScyllaPriorityQueue<T>.Builder WithCapacity(int capacity)
Parameters
| Type | Name | Description |
|---|---|---|
| int | capacity | The initial capacity. Must be at least 1. If less than 1, will be clamped to 1 during construction. |
Returns
| Type | Description |
|---|---|
| ScyllaPriorityQueue<T>.Builder | This builder instance for method chaining |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when capacity is less than 1 |
WithComparer(IComparer<T>)
Sets a custom comparer for element comparison and ordering. If not set or set to null, the priority queue will use Default for the element type.
Declaration
public ScyllaPriorityQueue<T>.Builder WithComparer(IComparer<T> comparer)
Parameters
| Type | Name | Description |
|---|---|---|
| IComparer<T> | comparer | The comparer to use for element ordering, or null to use the default comparer. Common use case: OrdinalIgnoreCase for case-insensitive string comparison. |
Returns
| Type | Description |
|---|---|
| ScyllaPriorityQueue<T>.Builder | This builder instance for method chaining |