Skip to content

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 : unmanaged

Type 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.

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.

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.

Clears the entry and index buffers and resets the count.

public void Clear()

Determines whether the key has an entry.

public bool ContainsKey(TKey key)

Parameters:

key — TKey

The lookup key.

Returns: bool

Whether the key exists.

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.

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.

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.

Copies entries into an independently owned array in their current order.

public KeyValuePair<TKey, TValue>[] ToArray()

Returns: KeyValuePair<TKey, TValue>[]

The key-value pairs.

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.

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.

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.

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

Borrows the initialized entries in their current order, without permitting key mutation.

public ReadOnlySpan<PgFixedMapEntry<TKey, TValue>> Entries { get; }

Value: ReadOnlySpan<PgFixedMapEntry<TKey, TValue>>

Gets whether the dictionary contains no entries.

public bool IsEmpty { get; }

Value: bool

Gets whether a new key would exceed capacity. Existing values can still be replaced.

public bool IsFull { get; }

Value: bool

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