Interface IScyllaTrie
Contract for a trie (prefix tree) that stores a set of strings with efficient prefix lookup and lexicographic enumeration. This is the set variant: keys have no associated value. For the key-value map variant see IScyllaTrie<TValue>.
Inherited Members
Namespace: Scylla.Core.Structures
Assembly: ScyllaCore.dll
Syntax
public interface IScyllaTrie : IScyllaCollection
Remarks
Primary use cases: in-game console command registration, tab-completion / autocomplete, prefix existence checks, and ordered enumeration of command names.
Prefix semantics: an empty string is a valid prefix and matches all stored
keys. Passing an empty string to ContainsPrefix(string) returns true whenever
any key is present. Passing an empty string to CopyMatches(string, Span<string>)
copies every key in the trie, equivalent to CopyTo(Span<string>).
Empty-key storage: an empty string is a valid key and may be stored
independently of prefix behaviour. After a successful TryAdd(""), the root node
becomes terminal.
Case sensitivity: implementations may optionally normalise characters to
upper-case (invariant culture) during traversal. When case-insensitive mode is active,
keys are stored with their original casing but matched without it. Check the concrete
implementation's IgnoreCase property for the active setting.
Lexicographic order: all CopyTo and CopyMatches methods
emit keys in ascending lexicographic order determined by the normalised character values
stored in the trie's sorted edge lists.
Thread safety: core implementations are unsynchronized. Use
AsSynchronized() on the concrete type to obtain a lock-protected wrapper, then
check ThreadSafety and
SyncRoot as needed.
Methods
Contains(string)
Determines whether the trie contains the specified key as an exact, complete match.
Declaration
bool Contains(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to search for. Must not be |
Returns
| Type | Description |
|---|---|
| bool |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
ContainsPrefix(string)
Determines whether the trie contains at least one key whose characters begin with
the characters of prefix.
Declaration
bool ContainsPrefix(string prefix)
Parameters
| Type | Name | Description |
|---|---|---|
| string | prefix | The prefix to test. Must not be |
Returns
| Type | Description |
|---|---|
| bool |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
CopyMatches(string, Span<string>)
Copies into destination all keys that start with
prefix, in ascending lexicographic order, stopping when the
span is full or all matching keys have been written. This is the primary method
for implementing autocomplete / tab-completion.
Declaration
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. If shorter than the number of
matching keys, only the first |
Returns
| Type | Description |
|---|---|
| int | The number of keys written into |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
CopyMatches(string, string[], int)
Copies into destination (starting at destinationIndex)
all keys that start with prefix, in ascending lexicographic order,
stopping when the remaining array space is exhausted or all matching keys have been written.
Declaration
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 | The zero-based index in |
Returns
| Type | Description |
|---|---|
| int | The number of keys written into |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
| ArgumentOutOfRangeException | Thrown when |
CopyTo(Span<string>)
Copies all stored keys in ascending lexicographic order into the provided
destination span, stopping when the span is full or all keys
have been written.
Declaration
int CopyTo(Span<string> destination)
Parameters
| Type | Name | Description |
|---|---|---|
| Span<string> | destination | The target span to write keys into. If the span length is smaller than
Count, only the first
|
Returns
| Type | Description |
|---|---|
| int | The number of keys written into |
CopyTo(string[], int)
Copies all stored keys in ascending lexicographic order into the provided
destination array starting at destinationIndex,
stopping when the remaining array space is exhausted or all keys have been written.
Declaration
int CopyTo(string[] destination, int destinationIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| string[] | destination | The target array to write keys into. Must not be |
| int | destinationIndex | The zero-based index in |
Returns
| Type | Description |
|---|---|
| int | The number of keys written into |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
| ArgumentOutOfRangeException | Thrown when |
TryAdd(string)
Attempts to insert the specified key into the trie.
Declaration
bool TryAdd(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to add. Must not be |
Returns
| Type | Description |
|---|---|
| bool |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
TryRemove(string)
Attempts to remove the specified key from the trie. After a successful removal, any internal nodes or edges that are no longer reachable by any stored key are pruned and their slots returned to the free list for reuse.
Declaration
bool TryRemove(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key to remove. Must not be |
Returns
| Type | Description |
|---|---|
| bool |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |