Table of Contents

Class Trie<TValue>

Namespace
AlgorithmsSW.String
Assembly
AlgorithmsSW.dll

Represents a Trie data structure with values of type TValue.

[AlgorithmReference(5, 4)]
public class Trie<TValue> : IStringSymbolTable<TValue>, ISymbolTable<string, TValue>, IReadOnlySymbolTable<string, TValue>, IStringCollection

Type Parameters

TValue

The type of the values stored in the Trie.

Inheritance
Trie<TValue>
Implements
Inherited Members
Extension Methods

Constructors

Trie(int)

Represents a Trie data structure with values of type TValue.

public Trie(int radix = 256)

Parameters

radix int

Properties

Comparer

public IComparer<string> Comparer { get; }

Property Value

IComparer<string>

Count

Gets the number of key/value pairs contained in the symbol table.

public int Count { get; }

Property Value

int

Keys

Gets an IEnumerable<T> containing the keys of the symbol table.

public IEnumerable<string> Keys { get; }

Property Value

IEnumerable<string>

Radix

public int Radix { get; }

Property Value

int

SupportsEmptyKeys

Returns true if the symbol table supports empty keys; otherwise, false.

public bool SupportsEmptyKeys { get; }

Property Value

bool

false.

Methods

Add(string, TValue)

Adds the specified key and value to the symbol table.

public void Add(string key, TValue value)

Parameters

key string

The key of the element to add.

value TValue

The value of the element to add.

KeysThatMatch(string)

Returns all keys in the symbol table that match the given pattern.

public IEnumerable<string> KeysThatMatch(string pattern)

Parameters

pattern string

The pattern used to search for keys.

Returns

IEnumerable<string>

KeysWithPrefix(string)

Returns all keys in the symbol table that have the given prefix.

public IEnumerable<string> KeysWithPrefix(string prefix)

Parameters

prefix string

The prefix used to search for keys.

Returns

IEnumerable<string>

LongestPrefixOf(string)

Returns the longest string that is a prefix of the given string.

public string? LongestPrefixOf(string str)

Parameters

str string

Returns

string

The longest string that is a prefix of the given string; null if no keys are a prefix of the given string.

RemoveKey(string)

Removes the element with the specified key from the symbol table.

public void RemoveKey(string key)

Parameters

key string

The key of the element to remove.

TryGetValue(string, out TValue)

Tries to get the value associated with the specified key from the symbol table.

public bool TryGetValue(string key, out TValue value)

Parameters

key string

The key of the value to get.

value TValue

When this method returns, contains the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.

Returns

bool

true if the symbol table contains an element with the specified key; otherwise, false.