Class LoudsDictionary
- Namespace
- BelNytheraSeiche.TrieDictionary
- Assembly
- BelNytheraSeiche.TrieDictionary.dll
A concrete implementation of KeyRecordDictionary that uses a memory-efficient LOUDS (Level-Order Unary Degree Sequence) trie.
public abstract class LoudsDictionary : LevelOrderBitsDictionary, KeyRecordDictionary.IKeyAccess
- Inheritance
-
LoudsDictionary
- Implements
- Inherited Members
Remarks
This class represents a trie data structure using a compact, bit-level representation to achieve significant memory savings. The structure is built from a sorted set of keys and is highly optimized for prefix-based searches.
Important Usage Notes:
- Read-Only Structure: Like the DAWG implementation, this dictionary is built once and is effectively read-only. Key addition and removal operations are not supported and will throw a NotSupportedException.
- Key Reconstruction: Getting a key by its identifier requires traversing the structure from a node up to the root.
Methods
Create(IEnumerable<byte[]>, SearchDirectionType)
Creates a new LoudsDictionary from a collection of keys.
public static LoudsDictionary Create(IEnumerable<byte[]> keys, KeyRecordDictionary.SearchDirectionType searchDirection = SearchDirectionType.LTR)
Parameters
keys
IEnumerable<byte[]>An enumerable collection of byte arrays to use as the initial keys. The collection does not need to be pre-sorted. Duplicate keys are permitted, but only the first occurrence will be added. The collection must not contain any elements that are null or empty byte array.
searchDirection
KeyRecordDictionary.SearchDirectionTypeThe key search direction for the new dictionary.
Returns
- LoudsDictionary
A new, optimized, and read-only LoudsDictionary instance.
Remarks
The input keys are sorted and used to construct the LOUDS trie representation.
Exceptions
- ArgumentNullException
keys
is null.
Deserialize(Stream)
Deserializes a dictionary from a stream.
public static LoudsDictionary Deserialize(Stream stream)
Parameters
stream
StreamThe stream to read the serialized data from.
Returns
- LoudsDictionary
A new instance of LoudsDictionary.
Exceptions
- ArgumentNullException
stream
is null.- InvalidDataException
The stream data is corrupted or in an unsupported format.
Serialize(LoudsDictionary, Stream, SerializationOptions?)
Serializes the state of the dictionary into a stream.
public static void Serialize(LoudsDictionary dictionary, Stream stream, KeyRecordDictionary.SerializationOptions? options = null)
Parameters
dictionary
LoudsDictionaryThe dictionary instance to serialize.
stream
StreamThe stream to write the serialized data to.
options
KeyRecordDictionary.SerializationOptionsOptions to control the serialization process. If null, the settings from Default will be used.
Remarks
The serialization format is a custom binary format specific to this LOUDS implementation.
Exceptions
- ArgumentNullException
dictionary
orstream
is null.