Interface IScyllaCollection<T>
Typed extension of IScyllaCollection that adds element-level operations for
collections that store items of a specific type T.
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public interface IScyllaCollection<T> : IScyllaCollection
Type Parameters
| Name | Description |
|---|---|
| T | The element type stored in the collection. May be a value type or a reference type. No constraints are applied; concrete implementations handle null behavior individually. |
Remarks
This interface deliberately uses a small, "try"-based surface area so that implementations with fundamentally different shapes - queues (FIFO), stacks (LIFO), ring buffers - can all satisfy the same contract without semantic mismatches or forced allocations.
The meaning of "add", "remove", and "peek" is intentionally abstract:
- On a ScyllaQueue<T>, TryAdd(T) enqueues and TryRemove(out T) dequeues.
- On a ScyllaStack<T>, TryAdd(T) pushes and TryRemove(out T) pops.
- On a ScyllaRingBuffer<T>, TryAdd(T) writes and TryRemove(out T) reads the oldest item.
When a collection supports capacity-bounded growth, TryAdd(T) returns
false rather than throwing, enabling callers to handle a full collection without
exceptions. Query Capabilities to determine whether a
collection has a capacity ceiling (HasCapacity)
and whether peeking is supported (SupportsPeek).
Allocation-free enumeration: The two CopyTo overloads provide
snapshot-style export to caller-owned buffers. This is the recommended approach for
iterating over a collection through the interface, avoiding the heap allocation that
IEnumerable<T> would require. Iteration through the concrete type
(e.g. using a value-type foreach enumerator) is always preferred in hot paths.
Methods
CopyTo(Span<T>)
Copies up to destination.Length elements from the collection into the provided
Span<T> buffer and returns the number of elements actually copied.
Declaration
int CopyTo(Span<T> destination)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<T> | destination | A caller-owned Span<T> that receives the copied elements. If
|
Returns
| Type | Description |
|---|---|
| int | The number of elements copied into |
Remarks
Copy order is collection-dependent and mirrors the collection's natural iteration order:
- ScyllaQueue<T> and ScyllaRingBuffer<T>: oldest element first (front-to-back / FIFO order).
- ScyllaStack<T>: top element first (top-to-bottom / LIFO order).
This overload is the preferred allocation-free alternative to interface-based
IEnumerable<T> enumeration. Using a stack-allocated or pooled
Span<T> avoids any heap allocation.
On synchronized wrappers, this operation is protected by the internal lock. The copied snapshot reflects the collection state at the moment the lock was acquired.
See Also
CopyTo(T[], int)
Copies up to destination.Length - destinationIndex elements from the collection
into the provided array starting at destinationIndex, and returns the
number of elements actually copied.
Declaration
int CopyTo(T[] destination, int destinationIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | destination | A caller-owned array that receives the copied elements. Must not be |
| int | destinationIndex | The zero-based index in |
Returns
| Type | Description |
|---|---|
| int | The number of elements copied. This is
|
Remarks
Copy order is collection-dependent and mirrors the collection's natural iteration order:
- ScyllaQueue<T> and ScyllaRingBuffer<T>: oldest element first (front-to-back / FIFO order).
- ScyllaStack<T>: top element first (top-to-bottom / LIFO order).
This overload is provided for scenarios where a Span<T> cannot be used (e.g. across async boundaries or when targeting APIs that expect arrays). Prefer CopyTo(Span<T>) in synchronous hot paths.
On synchronized wrappers, this operation is protected by the internal lock. The copied snapshot reflects the collection state at the moment the lock was acquired.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
| ArgumentOutOfRangeException | Thrown when |
See Also
TryAdd(T)
Attempts to add an item to the collection using the collection's natural insertion semantics.
Declaration
bool TryAdd(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to add. The interpretation of |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
This method never throws due to a full collection. It may still throw for programmer errors such as an internal overflow beyond maximum array size, but those cases are documented on the concrete implementation.
When the collection is unsynchronized and TryAdd is called concurrently from
multiple threads, the behavior is undefined. Use a synchronized wrapper
(see ThreadSafety) or supply external locking.
TryPeek(out T)
Attempts to inspect the "next" item that would be returned by TryRemove(out T) without actually removing it from the collection.
Declaration
bool TryPeek(out T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
Not all collections support peeking. Before calling this method through the interface,
check Capabilities for the
SupportsPeek flag. If the flag is absent,
the method will always return false.
On unsynchronized collections, the item returned by TryPeek may be removed or
replaced by a concurrent thread before the caller acts on it. Wrap the peek-and-act
pattern inside a lock on SyncRoot when using a
synchronized collection.
See Also
TryRemove(out T)
Attempts to remove the "next" item from the collection using the collection's natural
removal semantics, and returns it via an out parameter.
Declaration
bool TryRemove(out T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|
Remarks
For reference-type collections, implementations should null out the internal slot after removal to release the reference and allow garbage collection.
This method never throws due to an empty collection. It is safe to call on an empty collection and simply check the return value.