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
databyte[]The byte array containing the serialized data.
Returns
- PrimitiveRecordStore
A new instance of PrimitiveRecordStore.
Exceptions
- ArgumentNullException
datais 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
streamStreamThe stream to read the serialized data from.
Returns
- PrimitiveRecordStore
A new instance of PrimitiveRecordStore.
Exceptions
- ArgumentNullException
streamis 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
filestringThe path of the file to read from.
Returns
- PrimitiveRecordStore
A new instance of PrimitiveRecordStore.
Exceptions
- ArgumentNullException
fileis null.- ArgumentException
fileis 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
identifierintThe 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
identifieris negative.- ArgumentException
The specified
identifieris 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
storePrimitiveRecordStoreThe store to serialize.
optionsPrimitiveRecordStore.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
storeis 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
storePrimitiveRecordStoreThe store to serialize.
streamStreamThe stream to write the serialized data to.
optionsPrimitiveRecordStore.SerializationOptionsOptions to control the serialization process. If null, the settings from Default will be used.
Exceptions
- ArgumentNullException
storeorstreamis 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
storePrimitiveRecordStoreThe store to serialize.
filestringThe path of the file to create.
optionsPrimitiveRecordStore.SerializationOptionsOptions to control the serialization process. If null, the settings from Default will be used.
Exceptions
- ArgumentNullException
storeorfileis null.- ArgumentException
fileis empty or whitespace.