Class ScyllaDisjointSet.SynchronizedScyllaDisjointSet
A thread-safe decorator around ScyllaDisjointSet that serializes all operations through a single monitor lock.
Implements
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public sealed class ScyllaDisjointSet.SynchronizedScyllaDisjointSet : IScyllaCollection
Remarks
Every public method and property acquires the lock stored in SyncRoot before delegating to the inner ScyllaDisjointSet. This guarantees mutual exclusion for all individual operations, but compound operations (e.g., check-then-union) require the caller to acquire SyncRoot explicitly to avoid TOCTOU races.
Obtain an instance via AsSynchronized(object) or the Synchronized(object) builder option.
Constructors
SynchronizedScyllaDisjointSet(ScyllaDisjointSet, object)
Initializes a new ScyllaDisjointSet.SynchronizedScyllaDisjointSet wrapping the provided inner set and synchronizing on the given lock object.
Declaration
public SynchronizedScyllaDisjointSet(ScyllaDisjointSet inner, object syncRoot)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaDisjointSet | inner | The ScyllaDisjointSet instance whose operations should be
synchronized. Must not be |
| object | syncRoot | The monitor object to lock on. When |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
Properties
Capabilities
Gets the feature and capability flags supported by this collection instance.
Declaration
public ScyllaCollectionCapabilities Capabilities { get; }
Property Value
| Type | Description |
|---|---|
| ScyllaCollectionCapabilities | A bitfield of ScyllaCollectionCapabilities flags describing which optional operations the concrete instance supports. The value None indicates that only the base contract (Count, IsEmpty, Clear()) is available. |
Remarks
Use Capabilities for feature detection in place of type-casting. For example:
if ((collection.Capabilities & ScyllaCollectionCapabilities.SupportsPeek) != 0)
{
// safe to call TryPeek through IScyllaCollection<T>
}
Synchronized wrappers cache the capability flags of their inner collection at construction time, so the value returned is stable and does not require synchronization.
See Also
Capacity
Gets the total number of elements in the underlying disjoint set, read under lock.
Declaration
public int Capacity { get; }
Property Value
| Type | Description |
|---|---|
| int | Equivalent to Capacity of the wrapped instance. |
ComponentCount
Gets the current number of disjoint connected components, read under lock.
Declaration
public int ComponentCount { get; }
Property Value
| Type | Description |
|---|---|
| int | Equivalent to ComponentCount of the wrapped instance. Reflects all merges performed so far. |
Count
Gets the number of elements in the underlying disjoint set.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int | The fixed element count of the wrapped ScyllaDisjointSet, read under lock. Equivalent to Count. |
IsEmpty
Gets a value indicating whether the underlying disjoint set contains no elements.
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
SyncRoot
Gets the synchronization root object used to externally coordinate multi-step operations with this collection.
Declaration
public object SyncRoot { get; }
Property Value
| Type | Description |
|---|---|
| object | A non-null object suitable for use with |
Remarks
When this collection is a synchronized wrapper, SyncRoot must be non-null and
stable for the entire lifetime of the wrapper. All internal operations on the wrapper
must lock on this same object. This allows callers to perform atomic multi-step
sequences:
lock (collection.SyncRoot)
{
if (!collection.IsEmpty)
typedCollection.TryRemove(out var item);
}
For unsynchronized collections (SyncRoot == null), callers are responsible for
supplying and consistently applying their own external synchronization mechanism.
A null SyncRoot does not mean the collection is thread-safe;
consult ThreadSafety for the authoritative guarantee.
See Also
ThreadSafety
Gets the thread-safety guarantees provided by this collection instance.
Declaration
public ScyllaCollectionThreadSafety ThreadSafety { get; }
Property Value
| Type | Description |
|---|---|
| ScyllaCollectionThreadSafety | A ScyllaCollectionThreadSafety value indicating whether the collection is unsynchronized, synchronized via a lock, or safe for lock-free concurrent access. Most core implementations return Unsynchronized. Synchronized wrappers return Synchronized. |
Remarks
Always check this property (or SyncRoot) before assuming a collection is
safe for concurrent use. Do not rely solely on the absence of a non-null SyncRoot
to infer thread safety; use this property as the authoritative source.
See Also
Methods
Clear()
Resets all elements to individual singleton components under lock.
Declaration
public void Clear()
Remarks
Connected(int, int)
Determines whether elements x and y share
the same component, acquired under lock.
Declaration
public bool Connected(int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| int | x | The zero-based index of the first element. |
| int | y | The zero-based index of the second element. |
Returns
| Type | Description |
|---|---|
| bool |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
Find(int)
Returns the canonical root of the component containing element x,
acquired under lock.
Declaration
public int Find(int x)
Parameters
| Type | Name | Description |
|---|---|---|
| int | x | The zero-based element index. Must satisfy |
Returns
| Type | Description |
|---|---|
| int | The root index of the component containing |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |
Union(int, int)
Merges the components of elements x and y
under lock.
Declaration
public bool Union(int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| int | x | The zero-based index of the first element. |
| int | y | The zero-based index of the second element. |
Returns
| Type | Description |
|---|---|
| bool |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when |