Class ScyllaTrie<TValue>.SynchronizedScyllaTrie
Thread-safe wrapper around ScyllaTrie<TValue> 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<TValue>.SynchronizedScyllaTrie : IScyllaTrie<TValue>, IScyllaCollection
Remarks
All methods delegate to the wrapped ScyllaTrie<TValue> while holding the internal lock. For multi-step atomic sequences (e.g. check-then-act), lock on SyncRoot externally.
Constructors
SynchronizedScyllaTrie(ScyllaTrie<TValue>, object)
Initializes a new synchronized wrapper around the specified unsynchronized trie.
Declaration
public SynchronizedScyllaTrie(ScyllaTrie<TValue> inner, object syncRoot)
Parameters
| Type | Name | Description |
|---|---|---|
| ScyllaTrie<TValue> | inner | The ScyllaTrie<TValue> 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; reads do not require locking.
Declaration
public ScyllaCollectionCapabilities Capabilities { get; }
Property Value
| Type | Description |
|---|---|
| ScyllaCollectionCapabilities |
Count
Gets the number of key/value pairs currently stored in the wrapped trie, under the internal lock.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int |
EdgeCapacity
Gets the current number of edge slots in the wrapped trie's 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, 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. Cached at wrapper construction time; does not require locking.
Declaration
public bool IsFixedCapacity { get; }
Property Value
| Type | Description |
|---|---|
| bool |
NodeCapacity
Gets the current number of node slots in the wrapped trie's 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. Always Synchronized.
Declaration
public ScyllaCollectionThreadSafety ThreadSafety { get; }
Property Value
| Type | Description |
|---|---|
| ScyllaCollectionThreadSafety |
Methods
Clear()
Removes all keys and their associated values from the wrapped trie under the internal lock. See Clear() for full semantics.
Declaration
public void Clear()
ContainsKey(string)
Determines whether the exact key exists in the wrapped trie. Thread-safe. See ContainsKey(string) for full documentation.
Declaration
public bool ContainsKey(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 |
|
CopyKeyValuePairsTo(Span<KeyValuePair<string, TValue>>)
Copies all stored key/value pairs in ascending lexicographic order (by key) into
destination under the internal lock. Thread-safe.
See CopyKeyValuePairsTo(Span<KeyValuePair<string, TValue>>) for full documentation.
Declaration
public int CopyKeyValuePairsTo(Span<KeyValuePair<string, TValue>> destination)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<KeyValuePair<string, TValue>> | destination | The target span to write pairs into. |
Returns
| Type | Description |
|---|---|
| int | The number of pairs written. |
CopyKeysTo(Span<string>)
Copies all stored keys in ascending lexicographic order into destination
under the internal lock. Thread-safe.
See CopyKeysTo(Span<string>) for full documentation.
Declaration
public int CopyKeysTo(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. |
CopyKeysTo(string[], int)
Copies all stored keys in ascending lexicographic order into destination
starting at destinationIndex, under the internal lock. Thread-safe.
See CopyKeysTo(string[], int) for full documentation.
Declaration
public int CopyKeysTo(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. |
CopyMatches(string, Span<KeyValuePair<string, TValue>>)
Copies all key/value pairs whose key begins with prefix, in ascending
lexicographic key order, into destinationPairs under the internal lock.
Thread-safe.
See CopyMatches(string, Span<KeyValuePair<string, TValue>>)
for full documentation.
Declaration
public int CopyMatches(string prefix, Span<KeyValuePair<string, TValue>> destinationPairs)
Parameters
| Type | Name | Description |
|---|---|---|
| string | prefix | The prefix to match against. An empty string matches all stored pairs.
Must not be |
| Span<KeyValuePair<string, TValue>> | destinationPairs | The span to write matching key/value pairs into. Writing stops when the span is full. |
Returns
| Type | Description |
|---|---|
| int | The number of matching pairs written to |
CopyMatches(string, Span<string>)
Copies all keys whose prefix matches prefix, in ascending lexicographic order,
into destinationKeys under the internal lock. Thread-safe.
See CopyMatches(string, Span<string>) for full documentation.
Declaration
public int CopyMatches(string prefix, Span<string> destinationKeys)
Parameters
| Type | Name | Description |
|---|---|---|
| string | prefix | The prefix to match against. An empty string matches all stored keys.
Must not be |
| Span<string> | destinationKeys | The span to write matching keys into. Writing stops when the span is full. |
Returns
| Type | Description |
|---|---|
| int | The number of matching keys written to |
TryAdd(string, TValue)
Attempts to insert a new key/value pair into the wrapped trie under the internal lock. Thread-safe. See TryAdd(string, TValue) for full documentation.
Declaration
public bool TryAdd(string key, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to add. Must not be |
| TValue | value | The value to associate with |
Returns
| Type | Description |
|---|---|
| bool |
|
TryGetValue(string, out TValue)
Attempts to retrieve the value for the specified key from the wrapped trie. Thread-safe. See TryGetValue(string, out TValue) for full documentation.
Declaration
public bool TryGetValue(string key, out TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to look up. Must not be |
| TValue | value | When |
Returns
| Type | Description |
|---|---|
| bool |
|
TryRemove(string)
Attempts to remove the specified key and its value 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 |
|
TrySet(string, TValue)
Attempts to update the value for an existing key in the wrapped trie under the internal lock. Thread-safe. See TrySet(string, TValue) for full documentation.
Declaration
public bool TrySet(string key, TValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to update. Must not be |
| TValue | value | The new value to associate with |
Returns
| Type | Description |
|---|---|
| bool |
|