Class PrimitiveRecordStore
- Namespace
- BelNytheraSeiche.TrieDictionary
- Assembly
- BelNytheraSeiche.TrieDictionary.dll
Provides a low-level, memory-efficient data store for variable-length byte records.
public sealed class PrimitiveRecordStore
- Inheritance
-
PrimitiveRecordStore
- Inherited Members
Remarks
This store uses a series of fixed-size byte arrays ("chunks") to avoid allocations on the Large Object Heap. It internally manages a system of linked lists, where each list is a sequence of records. The entire store can be serialized to and deserialized from a compressed, checksummed binary format.
Record Size Limit: Please note that the Content
for any single record
cannot exceed 4,096 bytes. This limit is enforced during operations such as adding or updating records.
Important Usage Note: This is an append-only style store. When records are removed (i.e., unlinked from their respective lists), the underlying space they occupied is not reclaimed or reused. As a result, memory usage will only grow as new records are added. To compact the store and reclaim the space from deleted records, the store must be rebuilt. The correct procedure is to create a new, empty store instance and transfer all valid records from the old store to the new one, for instance by iterating through a known set of root identifiers.
Methods
Clear()
Clears all data from the store and resets it to its initial state.
public void Clear()
Deserialize(byte[])
Deserializes a store from a byte array.
public static PrimitiveRecordStore Deserialize(byte[] data)
Parameters
data
byte[]The byte array containing the serialized data.
Returns
- PrimitiveRecordStore
A new instance of PrimitiveRecordStore.
Exceptions
- ArgumentNullException
data
is null.- InvalidDataException
The data is in an unsupported format or is corrupted.
Deserialize(Stream)
Deserializes a store from a stream.
public static PrimitiveRecordStore Deserialize(Stream stream)
Parameters
stream
StreamThe stream to read the serialized data from.
Returns
- PrimitiveRecordStore
A new instance of PrimitiveRecordStore.
Exceptions
- ArgumentNullException
stream
is null.- InvalidDataException
The data is in an unsupported format or is corrupted.
Deserialize(string)
Deserializes a store from a file.
public static PrimitiveRecordStore Deserialize(string file)
Parameters
file
stringThe path of the file to read from.
Returns
- PrimitiveRecordStore
A new instance of PrimitiveRecordStore.
Exceptions
- ArgumentNullException
file
is null.- ArgumentException
file
is empty or whitespace.- InvalidDataException
The data is in an unsupported format or is corrupted.
GetRecordAccess(int)
Gets a PrimitiveRecordStore.RecordAccess handle for a linked list of records.
public PrimitiveRecordStore.RecordAccess GetRecordAccess(int identifier = 0)
Parameters
identifier
intThe identifier of the record list. Specify 0 to create a new list and get its identifier.
Returns
- PrimitiveRecordStore.RecordAccess
A PrimitiveRecordStore.RecordAccess object to manage the specified record list.
Exceptions
- ArgumentOutOfRangeException
identifier
is negative.- ArgumentException
The specified
identifier
is invalid or does not exist.
Serialize(PrimitiveRecordStore, SerializationOptions?)
Serializes the specified store into a byte array.
public static byte[] Serialize(PrimitiveRecordStore store, PrimitiveRecordStore.SerializationOptions? options = null)
Parameters
store
PrimitiveRecordStoreThe store to serialize.
options
PrimitiveRecordStore.SerializationOptionsOptions to control the serialization process. If null, the settings from Default will be used.
Returns
- byte[]
A byte array containing the serialized data.
Exceptions
- ArgumentNullException
store
is null.
Serialize(PrimitiveRecordStore, Stream, SerializationOptions?)
Serializes the specified store into a stream.
public static void Serialize(PrimitiveRecordStore store, Stream stream, PrimitiveRecordStore.SerializationOptions? options = null)
Parameters
store
PrimitiveRecordStoreThe store to serialize.
stream
StreamThe stream to write the serialized data to.
options
PrimitiveRecordStore.SerializationOptionsOptions to control the serialization process. If null, the settings from Default will be used.
Exceptions
- ArgumentNullException
store
orstream
is null.
Serialize(PrimitiveRecordStore, string, SerializationOptions?)
Serializes the specified store to a file.
public static void Serialize(PrimitiveRecordStore store, string file, PrimitiveRecordStore.SerializationOptions? options = null)
Parameters
store
PrimitiveRecordStoreThe store to serialize.
file
stringThe path of the file to create.
options
PrimitiveRecordStore.SerializationOptionsOptions to control the serialization process. If null, the settings from Default will be used.
Exceptions
- ArgumentNullException
store
orfile
is null.- ArgumentException
file
is empty or whitespace.