Class KeyRecordDictionary
- Namespace
- BelNytheraSeiche.TrieDictionary
- Assembly
- BelNytheraSeiche.TrieDictionary.dll
An abstract base class for advanced key-record dictionaries.
public abstract class KeyRecordDictionary
- Inheritance
-
KeyRecordDictionary
- Derived
- Inherited Members
Remarks
This class provides a framework for mapping byte array keys to linked lists of data records. It features a dual-storage system (transient and persistent) for records, supports different key search directions (LTR/RTL), and allows for custom metadata storage. Concrete implementations are expected to provide the specific key management structure (e.g., a trie).
Constructors
KeyRecordDictionary(SearchDirectionType)
An abstract base class for advanced key-record dictionaries.
protected KeyRecordDictionary(KeyRecordDictionary.SearchDirectionType searchDirection)
Parameters
searchDirection
KeyRecordDictionary.SearchDirectionTypeThe key search direction for the new dictionary.
Remarks
This class provides a framework for mapping byte array keys to linked lists of data records. It features a dual-storage system (transient and persistent) for records, supports different key search directions (LTR/RTL), and allows for custom metadata storage. Concrete implementations are expected to provide the specific key management structure (e.g., a trie).
Properties
Additional1
Gets or sets a small, general-purpose byte array for additional persistent data.
public byte[] Additional1 { get; set; }
Property Value
- byte[]
Remarks
The size of the byte array cannot exceed 4096 bytes.
Exceptions
- ArgumentNullException
The assigned value is null.
- ArgumentOutOfRangeException
The length of the assigned byte array is greater than 4096.
Additional2
Gets or sets a large, general-purpose byte array for additional persistent data.
public byte[] Additional2 { get; set; }
Property Value
- byte[]
Remarks
The size of the byte array cannot exceed 1,073,741,824 bytes (1 GB).
Exceptions
- ArgumentNullException
The assigned value is null.
- ArgumentOutOfRangeException
The length of the assigned byte array is greater than 1 GB.
SearchDirection
Gets the search direction (Left-To-Right or Right-To-Left) for key operations.
public KeyRecordDictionary.SearchDirectionType SearchDirection { get; }
Property Value
Methods
Create<T>(SearchDirectionType)
Creates a new instance of a derived dictionary type with an empty set of keys.
public static T Create<T>(KeyRecordDictionary.SearchDirectionType searchDirection = SearchDirectionType.LTR) where T : KeyRecordDictionary
Parameters
searchDirection
KeyRecordDictionary.SearchDirectionTypeThe key search direction for the new dictionary.
Returns
- T
A new instance of the specified dictionary type.
Type Parameters
T
The concrete type of the dictionary to create.
Create<T>(IEnumerable<byte[]>, SearchDirectionType)
Creates a new instance of a derived dictionary type, populated with an initial set of keys.
public static T Create<T>(IEnumerable<byte[]> keys, KeyRecordDictionary.SearchDirectionType searchDirection = SearchDirectionType.LTR) where T : KeyRecordDictionary
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
- T
A new instance of the specified dictionary type.
Type Parameters
T
The concrete type of the dictionary to create.
Remarks
This method uses reflection to invoke the static Create
method on the concrete derived type T
.
Exceptions
- ArgumentNullException
keys
is null.
Create<T>(IEnumerable<string>, Encoding?, SearchDirectionType)
Creates a new instance of a derived dictionary type, populated with an initial set of string keys.
public static T Create<T>(IEnumerable<string> keys, Encoding? encoding = null, KeyRecordDictionary.SearchDirectionType searchDirection = SearchDirectionType.LTR) where T : KeyRecordDictionary
Parameters
keys
IEnumerable<string>An enumerable collection of strings 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 strings.
encoding
EncodingThe encoding to use for converting strings to bytes. Defaults to UTF-8.
searchDirection
KeyRecordDictionary.SearchDirectionTypeThe key search direction for the new dictionary.
Returns
- T
A new instance of the specified dictionary type.
Type Parameters
T
The concrete type of the dictionary to create.
Exceptions
- ArgumentNullException
keys
is null.
Deserialize<T>(byte[])
Deserializes a dictionary from a byte array.
public static T Deserialize<T>(byte[] data) where T : KeyRecordDictionary
Parameters
data
byte[]The byte array containing the serialized data.
Returns
- T
A new instance of
T
.
Type Parameters
T
The concrete type of the dictionary to deserialize.
Remarks
This static method uses reflection to invoke the static Deserialize
method on the specified type T
.
Exceptions
- ArgumentNullException
data
is null.
Deserialize<T>(Stream)
Deserializes a dictionary from a stream.
public static T Deserialize<T>(Stream stream) where T : KeyRecordDictionary
Parameters
stream
StreamThe stream to read the serialized data from.
Returns
- T
A new instance of
T
.
Type Parameters
T
The concrete type of the dictionary to deserialize.
Exceptions
- ArgumentNullException
stream
is null.- NotSupportedException
The type
T
does not have a public staticDeserialize(Stream)
method.
Deserialize<T>(string)
Deserializes a dictionary from a file.
public static T Deserialize<T>(string file) where T : KeyRecordDictionary
Parameters
file
stringThe path of the file to read from.
Returns
- T
A new instance of
T
.
Type Parameters
T
The concrete type of the dictionary to deserialize.
Remarks
This static method uses reflection to invoke the static Deserialize
method on the specified type T
.
Exceptions
- ArgumentNullException
file
is null.- ArgumentException
file
is empty or whitespace.
Serialize<T>(T, SerializationOptions?)
Serializes the specified dictionary instance into a byte array.
public static byte[] Serialize<T>(T obj, KeyRecordDictionary.SerializationOptions? options = null) where T : KeyRecordDictionary
Parameters
obj
TThe dictionary instance to serialize.
options
KeyRecordDictionary.SerializationOptionsOptions to control the serialization process. If null, the settings from Default will be used.
Returns
- byte[]
A byte array containing the serialized data.
Type Parameters
T
The concrete type of the dictionary.
Remarks
This static method uses reflection to invoke the static Serialize
method on the concrete derived type T
.
Exceptions
- ArgumentNullException
obj
is null.
Serialize<T>(T, Stream, SerializationOptions?)
Serializes the specified dictionary instance into a stream.
public static void Serialize<T>(T obj, Stream stream, KeyRecordDictionary.SerializationOptions? options = null) where T : KeyRecordDictionary
Parameters
obj
TThe 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.
Type Parameters
T
The concrete type of the dictionary.
Exceptions
- ArgumentNullException
obj
orstream
is null.- NotSupportedException
The type
T
does not have a public staticSerialize(T, Stream)
method.
Serialize<T>(T, string, SerializationOptions?)
Serializes the specified dictionary instance to a file.
public static void Serialize<T>(T obj, string file, KeyRecordDictionary.SerializationOptions? options = null) where T : KeyRecordDictionary
Parameters
obj
TThe dictionary instance to serialize.
file
stringThe path of the file to create.
options
KeyRecordDictionary.SerializationOptionsOptions to control the serialization process. If null, the settings from Default will be used.
Type Parameters
T
The concrete type of the dictionary.
Remarks
This static method uses reflection to invoke the static Serialize
method on the concrete derived type T
.
Exceptions
- ArgumentNullException
obj
orfile
is null.- ArgumentException
file
is empty or whitespace.