Class ScyllaSparseSquareGrid<TCell>.Builder
Fluent builder for constructing ScyllaSparseSquareGrid<TCell> instances with configurable layout, optional bounds, and optional thread-safety.
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public sealed class ScyllaSparseSquareGrid<TCell>.Builder
Remarks
WithLayout(SquareGridLayout) is mandatory; calling Build() or BuildConcrete() without it throws InvalidOperationException.
Unlike the dense grid builder, this builder does not provide a WithDefaultValue
method because sparse grids only contain explicitly set cells and have no pre-allocated
storage to fill.
Build() returns an IScyllaGrid<TCoord, TCell> interface; use BuildConcrete() when the concrete type is needed and synchronization is not required.
Methods
Build()
Builds the sparse grid and returns it as an IScyllaGrid<TCoord, TCell>.
Declaration
public IScyllaGrid<SquareCoord, TCell> Build()
Returns
| Type | Description |
|---|---|
| IScyllaGrid<SquareCoord, TCell> | An IScyllaGrid<TCoord, TCell> representing the fully configured grid. |
Remarks
If Synchronized(object) was called the returned value is a ScyllaSparseSquareGrid<TCell>.SynchronizedScyllaSparseSquareGrid; otherwise it is the concrete ScyllaSparseSquareGrid<TCell>. If WithBounds(int, int, int, int) was called, the grid is bounded; otherwise it is unbounded.
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown when WithLayout(SquareGridLayout) has not been called. |
BuildConcrete()
Builds the sparse grid and returns it as the concrete ScyllaSparseSquareGrid<TCell> type.
Declaration
public ScyllaSparseSquareGrid<TCell> BuildConcrete()
Returns
| Type | Description |
|---|---|
| ScyllaSparseSquareGrid<TCell> | The configured ScyllaSparseSquareGrid<TCell>, bounded or unbounded depending on whether WithBounds(int, int, int, int) was called. |
Remarks
Use this overload when the concrete type is needed (e.g., to call TryRemove(SquareCoord, out TCell) or GetEnumerator() without boxing). Throws if Synchronized(object) was called, because the concrete type cannot represent a synchronized wrapper - use Build() in that case.
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown when Synchronized(object) was called (use Build() instead), or when WithLayout(SquareGridLayout) has not been called. |
Synchronized(object)
Configures the builder to wrap the constructed grid in a ScyllaSparseSquareGrid<TCell>.SynchronizedScyllaSparseSquareGrid so that all operations are thread-safe.
Declaration
public ScyllaSparseSquareGrid<TCell>.Builder Synchronized(object syncRoot = null)
Parameters
| Type | Name | Description |
|---|---|---|
| object | syncRoot | An optional external lock object to share. When |
Returns
| Type | Description |
|---|---|
| ScyllaSparseSquareGrid<TCell>.Builder | This builder instance for method chaining. |
WithBounds(int, int, int, int)
Sets inclusive coordinate bounds for the sparse grid.
Declaration
public ScyllaSparseSquareGrid<TCell>.Builder WithBounds(int minCol, int minRow, int maxCol, int maxRow)
Parameters
| Type | Name | Description |
|---|---|---|
| int | minCol | The minimum column value (inclusive). |
| int | minRow | The minimum row value (inclusive). |
| int | maxCol | The maximum column value (inclusive). Must be >= |
| int | maxRow | The maximum row value (inclusive). Must be >= |
Returns
| Type | Description |
|---|---|
| ScyllaSparseSquareGrid<TCell>.Builder | This builder instance for method chaining. |
Remarks
When this method is called, writes outside the defined rectangle are rejected. When omitted, the grid is unbounded and accepts any integer coordinate.
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
WithLayout(SquareGridLayout)
Sets the spatial layout used for world-space coordinate conversion.
Declaration
public ScyllaSparseSquareGrid<TCell>.Builder WithLayout(SquareGridLayout layout)
Parameters
| Type | Name | Description |
|---|---|---|
| SquareGridLayout | layout | The SquareGridLayout to assign. This call is required before Build() or BuildConcrete(). |
Returns
| Type | Description |
|---|---|
| ScyllaSparseSquareGrid<TCell>.Builder | This builder instance for method chaining. |