PgFixedMap<TKey, TValue>
Namespace: Ankus
Assembly: Ankus.Runtime.dll
Borrows fixed unmanaged entry and index buffers as an insertion-ordered dictionary.
public readonly ref struct PgFixedMap<TKey, TValue> where TKey : unmanaged where TValue : unmanagedType parameters:
TKey
The unmanaged key.
TValue
The unmanaged value.
The caller owns and synchronizes the buffers and count. Zero-initialized storage is empty. The index buffer has one slot per entry; both remain fixed in size. Removal moves the last entry into the removed position, as with heapless IndexMap. A custom comparer must produce identical equality and hash results in every process using this storage, without mutable external state. Never use randomized hashes, process-local addresses or a different comparer when attaching to populated storage. Do not modify the raw buffers while the dictionary is populated.
Constructors
Section titled “Constructors”PgFixedMap(Span<PgFixedMapEntry<TKey, TValue>>, Span<int>, ref int, IEqualityComparer<TKey>?)
Section titled “PgFixedMap(Span<PgFixedMapEntry<TKey, TValue>>, Span<int>, ref int, IEqualityComparer<TKey>?)”Borrows existing dictionary storage without clearing or rehashing it.
public PgFixedMap(Span<PgFixedMapEntry<TKey, TValue>> entries, Span<int> indices, ref int count, IEqualityComparer<TKey>? comparer = null)Parameters:
entries — Span<PgFixedMapEntry<TKey, TValue>>
The complete dense entry buffer.
indices — Span<int>
An equally sized index buffer; zero denotes an unused slot.
count — int
The number of populated entries.
comparer — IEqualityComparer<TKey>
An explicit process-stable comparer, or the built-in scalar comparer.
Methods
Section titled “Methods”Add(TKey, TValue)
Section titled “Add(TKey, TValue)”Adds a new entry, throwing for an existing key or insufficient capacity.
public void Add(TKey key, TValue value)Parameters:
key — TKey
The new key.
value — TValue
The new value.
Clear()
Section titled “Clear()”Clears the entry and index buffers and resets the count.
public void Clear()ContainsKey(TKey)
Section titled “ContainsKey(TKey)”Determines whether the key has an entry.
public bool ContainsKey(TKey key)Parameters:
key — TKey
The lookup key.
Returns: bool
Whether the key exists.
GetEnumerator()
Section titled “GetEnumerator()”Enumerates entries in their current order without allocating a snapshot.
public ReadOnlySpan<PgFixedMapEntry<TKey, TValue>>.Enumerator GetEnumerator()Returns: ReadOnlySpan<PgFixedMapEntry<TKey, TValue>>.Enumerator
An enumerator invalidated by structural changes to the map.
Remove(TKey, out TValue)
Section titled “Remove(TKey, out TValue)”Removes a key, moving the last entry into its position and repairing the probe chain.
public bool Remove(TKey key, out TValue value)Parameters:
key — TKey
The key to remove.
value — TValue
The removed value, or default when absent.
Returns: bool
Whether an entry was removed.
Set(TKey, TValue)
Section titled “Set(TKey, TValue)”Inserts or replaces a value, throwing if a new key cannot fit.
public TValue? Set(TKey key, TValue value)Parameters:
key — TKey
The key to insert or update.
value — TValue
The new value.
Returns: TValue?
The old value on replacement, or null on insertion.
ToArray()
Section titled “ToArray()”Copies entries into an independently owned array in their current order.
public KeyValuePair<TKey, TValue>[] ToArray()Returns: KeyValuePair<TKey, TValue>[]
The key-value pairs.
TryAdd(TKey, TValue)
Section titled “TryAdd(TKey, TValue)”Adds a new key, leaving storage unchanged if the key already exists or the buffer is full.
public bool TryAdd(TKey key, TValue value)Parameters:
key — TKey
The new key.
value — TValue
The new value.
Returns: bool
Whether a new entry was appended.
TryGetValue(TKey, out TValue)
Section titled “TryGetValue(TKey, out TValue)”Looks up a key using the shared index and stable equality contract.
public bool TryGetValue(TKey key, out TValue value)Parameters:
key — TKey
The lookup key.
value — TValue
The associated value, or default if absent.
Returns: bool
Whether the key exists.
TrySet(TKey, TValue, out TValue?)
Section titled “TrySet(TKey, TValue, out TValue?)”Inserts or replaces a value, preserving the original key and position on replacement.
public bool TrySet(TKey key, TValue value, out TValue? previous)Parameters:
key — TKey
The key to insert or update.
value — TValue
The new value.
previous — TValue?
The old value for replacement, or null for insertion or a full-buffer rejection.
Returns: bool
False without changes only when a new key cannot fit.
Properties
Section titled “Properties”Capacity
Section titled “Capacity”Gets the maximum entry count.
public int Capacity { get; }Value: int
Gets the current count, rejecting a default view or invalid count metadata.
public int Count { get; }Value: int
Entries
Section titled “Entries”Borrows the initialized entries in their current order, without permitting key mutation.
public ReadOnlySpan<PgFixedMapEntry<TKey, TValue>> Entries { get; }Value: ReadOnlySpan<PgFixedMapEntry<TKey, TValue>>
IsEmpty
Section titled “IsEmpty”Gets whether the dictionary contains no entries.
public bool IsEmpty { get; }Value: bool
IsFull
Section titled “IsFull”Gets whether a new key would exceed capacity. Existing values can still be replaced.
public bool IsFull { get; }Value: bool
this[TKey]
Section titled “this[TKey]”Gets an existing value, or inserts or replaces a value through the setter.
public TValue this[TKey key] { get; set; }Parameters:
key — TKey
The lookup or insertion key.
Value: TValue