Class ScyllaTrie.SynchronizedScyllaTrie
Thread-safe wrapper around ScyllaTrie that serialises all operations through a single monitor lock, making them safe for concurrent access from multiple threads. Obtain an instance via AsSynchronized(object) or Synchronized(object).
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public sealed class ScyllaTrie.SynchronizedScyllaTrie : IScyllaTrie, IScyllaCollection
Remarks
All methods delegate to the wrapped ScyllaTrie while holding the internal lock. For multi-step atomic sequences (e.g. check-then-act), lock on SyncRoot externally:
lock (wrapper.SyncRoot)
{
if (!wrapper.Contains("cmd"))
wrapper.TryAdd("cmd");
}
Constructors
SynchronizedScyllaTrie(ScyllaTrie, object)
Initializes a new synchronized wrapper around the specified unsynchronized trie.
Declaration
public SynchronizedScyllaTrie(ScyllaTrie inner, object syncRoot)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaTrie | inner | The ScyllaTrie to wrap. Must not be |
| object | syncRoot | An optional external lock object to synchronize on. When |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
Properties
Capabilities
Gets the capability flags supported by the wrapped trie. Cached at wrapper construction time; reads do not require locking.
Declaration
public ScyllaCollectionCapabilities Capabilities { get; }
Property Value
| Type | Description |
|---|---|
| ScyllaCollectionCapabilities |
Count
Gets the number of keys currently stored in the wrapped trie, acquired under the internal lock.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int |
EdgeCapacity
Gets the current number of edge slots allocated in the wrapped trie's internal edge array. Delegates to EdgeCapacity under the internal lock.
Declaration
public int EdgeCapacity { get; }
Property Value
| Type | Description |
|---|---|
| int |
IsEmpty
Gets a value indicating whether the wrapped trie contains no keys, acquired under the internal lock.
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsFixedCapacity
Gets a value indicating whether the wrapped trie is operating in fixed-capacity mode. This value is cached at wrapper construction time and does not require locking.
Declaration
public bool IsFixedCapacity { get; }
Property Value
| Type | Description |
|---|---|
| bool |
NodeCapacity
Gets the current number of node slots allocated in the wrapped trie's internal node array. Delegates to NodeCapacity under the internal lock.
Declaration
public int NodeCapacity { get; }
Property Value
| Type | Description |
|---|---|
| int |
SyncRoot
Gets the monitor object used to synchronize all operations on this wrapper.
Use this object with lock to perform atomic multi-step sequences against the trie.
Declaration
public object SyncRoot { get; }
Property Value
| Type | Description |
|---|---|
| object |
ThreadSafety
Gets the thread-safety guarantee for this wrapper instance. Always Synchronized.
Declaration
public ScyllaCollectionThreadSafety ThreadSafety { get; }
Property Value
| Type | Description |
|---|---|
| ScyllaCollectionThreadSafety |
Methods
Clear()
Removes all keys from the wrapped trie under the internal lock. See Clear() for full semantics.
Declaration
public void Clear()
Contains(string)
Determines whether the exact key exists in the wrapped trie. Thread-safe. See Contains(string) for full parameter and return documentation.
Declaration
public bool Contains(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to search for. Must not be |
Returns
| Type | Description |
|---|---|
| bool |
|
ContainsPrefix(string)
Determines whether the wrapped trie contains at least one key starting with
prefix. Thread-safe. See ContainsPrefix(string)
for full documentation.
Declaration
public bool ContainsPrefix(string prefix)
Parameters
| Type | Name | Description |
|---|---|---|
| string | prefix | The prefix to test. Must not be |
Returns
| Type | Description |
|---|---|
| bool |
|
CopyMatches(string, Span<string>)
Copies all keys that start with prefix in ascending lexicographic order
into destination under the internal lock. Thread-safe.
See CopyMatches(string, Span<string>) for full documentation.
Declaration
public int CopyMatches(string prefix, Span<string> destination)
Parameters
| Type | Name | Description |
|---|---|---|
| string | prefix | The prefix to filter by. Must not be |
| Span<string> | destination | The target span to write matching keys into. |
Returns
| Type | Description |
|---|---|
| int | The number of keys written. |
CopyMatches(string, string[], int)
Copies all keys that start with prefix in ascending lexicographic order
into destination starting at destinationIndex,
under the internal lock. Thread-safe.
See CopyMatches(string, string[], int) for full documentation.
Declaration
public int CopyMatches(string prefix, string[] destination, int destinationIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| string | prefix | The prefix to filter by. Must not be |
| string[] | destination | The target array to write matching keys into. Must not be |
| int | destinationIndex | Zero-based start index within the array. |
Returns
| Type | Description |
|---|---|
| int | The number of keys written. |
CopyTo(Span<string>)
Copies all stored keys in ascending lexicographic order into destination
under the internal lock. Thread-safe.
See CopyTo(Span<string>) for full documentation.
Declaration
public int CopyTo(Span<string> destination)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<string> | destination | The target span to write keys into. |
Returns
| Type | Description |
|---|---|
| int | The number of keys written. |
CopyTo(string[], int)
Copies all stored keys in ascending lexicographic order into destination
starting at destinationIndex, under the internal lock. Thread-safe.
See CopyTo(string[], int) for full documentation.
Declaration
public int CopyTo(string[] destination, int destinationIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| string[] | destination | The target array to write keys into. Must not be |
| int | destinationIndex | Zero-based start index within the array. |
Returns
| Type | Description |
|---|---|
| int | The number of keys written. |
TryAdd(string)
Attempts to insert the specified key into the wrapped trie under the internal lock. Thread-safe. See TryAdd(string) for full documentation.
Declaration
public bool TryAdd(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to add. Must not be |
Returns
| Type | Description |
|---|---|
| bool |
|
TryRemove(string)
Attempts to remove the specified key from the wrapped trie under the internal lock. Thread-safe. See TryRemove(string) for full documentation.
Declaration
public bool TryRemove(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to remove. Must not be |
Returns
| Type | Description |
|---|---|
| bool |
|