Class HashMapRecordStore
- Namespace
- BelNytheraSeiche.TrieDictionary
- Assembly
- BelNytheraSeiche.TrieDictionary.dll
A concrete implementation of BasicRecordStore that uses a hash map as its underlying data structure.
public sealed class HashMapRecordStore : BasicRecordStore, ICloneable
- Inheritance
-
HashMapRecordStore
- Implements
- Inherited Members
Remarks
This class uses a Dictionary<TKey, TValue> to store records. It provides fast, average-case O(1) time complexity for record lookups, additions, and removals. Unlike the tree-based stores, this implementation does not store or enumerate records in a sorted order.
Serialization Limits: The binary serialization format for this class imposes certain constraints on the data. Exceeding these limits will result in an InvalidDataException during serialization.
- Max Records per List: A single identifier can have a maximum of 16,777,215 records in its linked list.
- Max Record Content Size: The
Content
byte array of any single record cannot exceed 65,535 bytes.
Constructors
HashMapRecordStore()
Initializes a new, empty instance of the HashMapRecordStore class.
public HashMapRecordStore()
Methods
Clone()
Creates a deep copy of the HashMapRecordStore.
public object Clone()
Returns
- object
A new HashMapRecordStore instance with the same keys and record data as the original.
Remarks
The method creates a new dictionary and copies all key-value pairs and their associated record lists, ensuring that the new store is independent of the original.
Contains(int)
Determines whether a record with the specified identifier exists in the hash map.
public override bool Contains(int identifier)
Parameters
identifier
intThe identifier to locate.
Returns
- bool
true if a record with the specified identifier is found; otherwise, false.
Deserialize(Stream)
Deserializes a HashMapRecordStore from a stream.
public static HashMapRecordStore Deserialize(Stream stream)
Parameters
stream
StreamThe stream to read the serialized data from.
Returns
- HashMapRecordStore
A new instance of HashMapRecordStore reconstructed from the stream.
Exceptions
- ArgumentNullException
stream
is null.- InvalidDataException
The stream data is corrupted, in an unsupported format, or contains invalid values.
Enumerate()
Returns an enumerator that iterates through all records in the store.
public override IEnumerable<(int, BasicRecordStore.RecordAccess)> Enumerate()
Returns
- IEnumerable<(int, BasicRecordStore.RecordAccess)>
An IEnumerable<T> of tuples, each containing an identifier and its corresponding BasicRecordStore.RecordAccess.
Remarks
The order of enumeration is not guaranteed to be sorted, as it depends on the internal implementation of the hash map.
GetRecordAccess(int, out bool)
Gets the accessor for a record's list of data. If an entry for the identifier does not exist, it is created.
public override BasicRecordStore.RecordAccess GetRecordAccess(int identifier, out bool createNew)
Parameters
identifier
intThe identifier of the record list.
createNew
boolWhen this method returns, contains true if a new entry was created; otherwise, false.
Returns
- BasicRecordStore.RecordAccess
A BasicRecordStore.RecordAccess for the found or newly created record list.
Remove(int)
Removes the record (and its associated list of data) with the specified identifier from the hash map.
public override void Remove(int identifier)
Parameters
identifier
intThe identifier of the record to remove.
Serialize(HashMapRecordStore, Stream, SerializationOptions?)
Serializes the entire state of the hash map store into a stream.
public static void Serialize(HashMapRecordStore store, Stream stream, BasicRecordStore.SerializationOptions? options = null)
Parameters
store
HashMapRecordStoreThe HashMapRecordStore instance to serialize.
stream
StreamThe stream to write the serialized data to.
options
BasicRecordStore.SerializationOptionsOptions to control the serialization process. If null, the settings from Default will be used.
Remarks
The serialization format is specific to this hash map implementation, using Brotli compression and an XxHash32 checksum for data integrity.
Exceptions
- ArgumentNullException
store
orstream
is null.
TryGetRecordAccess(int, out RecordAccess?)
Tries to get the accessor for a record's list of data.
public override bool TryGetRecordAccess(int identifier, out BasicRecordStore.RecordAccess? access)
Parameters
identifier
intThe identifier to locate.
access
BasicRecordStore.RecordAccessWhen this method returns, contains the BasicRecordStore.RecordAccess object if the identifier was found; otherwise, null.
Returns
- bool
true if an entry with the specified identifier was found; otherwise, false.