Class ScyllaMap<TKey, TValue>.Builder
Fluent builder for constructing ScyllaMap instances with complex configurations. Supports capacity, fixed-capacity mode, custom key comparer, and synchronized wrapper creation.
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public sealed class ScyllaMap<TKey, TValue>.Builder
Remarks
The builder provides a discoverable API for configuring maps without relying on positional parameters. Use Build() to obtain a configured map (returns interface for synchronized wrappers). Use BuildConcrete() to obtain the concrete unsynchronized map type (throws if synchronized).
// Basic usage with defaults
var map = ScyllaMap<string, int>.CreateBuilder().Build();
// Configure capacity and fixed-capacity mode
var map = ScyllaMap<int, string>.CreateBuilder()
.WithCapacity(64)
.FixedCapacity()
.Build();
// Custom comparer for case-insensitive string keys
var map = ScyllaMap<string, User>.CreateBuilder()
.WithCapacity(128)
.WithComparer(StringComparer.OrdinalIgnoreCase)
.Build();
// Create synchronized (thread-safe) wrapper
var map = ScyllaMap<int, Task>.CreateBuilder()
.WithCapacity(256)
.Synchronized()
.Build();
Methods
Build()
Builds and returns the configured ScyllaMap instance or synchronized wrapper. If Synchronized(object) was called, returns a ScyllaMap<TKey, TValue>.SynchronizedScyllaMap wrapper. Otherwise, returns the unsynchronized ScyllaMap<TKey, TValue>.
Declaration
public IScyllaMap<TKey, TValue> Build()
Returns
| Type | Description |
|---|---|
| IScyllaMap<TKey, TValue> | An IScyllaMap<TKey, TValue> representing either the unsynchronized map or synchronized wrapper |
BuildConcrete()
Builds and returns the concrete unsynchronized ScyllaMap<TKey, TValue> instance. This method provides access to the concrete type instead of the interface.
Declaration
public ScyllaMap<TKey, TValue> BuildConcrete()
Returns
| Type | Description |
|---|---|
| ScyllaMap<TKey, TValue> | The configured unsynchronized ScyllaMap 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 rehashing when the map becomes full. When fixed-capacity is enabled, insert operations will fail instead of growing the hashtable.
Declaration
public ScyllaMap<TKey, TValue>.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 |
|---|---|
| ScyllaMap<TKey, TValue>.Builder | This builder instance for method chaining |
Synchronized(object)
Configures the builder to return a synchronized (thread-safe) wrapper around the map. All operations on the synchronized wrapper will be protected by a lock.
Declaration
public ScyllaMap<TKey, TValue>.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 |
|---|---|
| ScyllaMap<TKey, TValue>.Builder | This builder instance for method chaining |
WithCapacity(int)
Sets the initial capacity of the map hashtable.
Declaration
public ScyllaMap<TKey, TValue>.Builder WithCapacity(int capacity)
Parameters
| Type | Name | Description |
|---|---|---|
| int | capacity | The initial capacity. Must be at least 1. Will be rounded up to next power of two during construction. |
Returns
| Type | Description |
|---|---|
| ScyllaMap<TKey, TValue>.Builder | This builder instance for method chaining |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when capacity is less than 1 |
WithComparer(IEqualityComparer<TKey>)
Sets a custom equality comparer for key comparison. If not set or set to null, the map will use Default for the key type.
Declaration
public ScyllaMap<TKey, TValue>.Builder WithComparer(IEqualityComparer<TKey> comparer)
Parameters
| Type | Name | Description |
|---|---|---|
| IEqualityComparer<TKey> | comparer | The equality comparer to use for key comparison, or null to use the default comparer. Common use case: OrdinalIgnoreCase for case-insensitive string keys. |
Returns
| Type | Description |
|---|---|
| ScyllaMap<TKey, TValue>.Builder | This builder instance for method chaining |