Table of Contents

Struct UnsafeMultiHashMap<TKey, TValue>

Namespace
Misaki.HighPerformance.LowLevel.Collections
Assembly
Misaki.HighPerformance.LowLevel.dll
public struct UnsafeMultiHashMap<TKey, TValue> : IUnsafeHashCollection<KeyValuePair<TKey, TValue>>, IDisposable where TKey : unmanaged, IEquatable<TKey> where TValue : unmanaged

Type Parameters

TKey
TValue
Implements
Inherited Members

Constructors

UnsafeMultiHashMap()

Initializes a new instance of UnsafeMultiHashMap with a default size of 1 and a persistent allocation handle.

public UnsafeMultiHashMap()

UnsafeMultiHashMap(int, AllocationHandle, AllocationOption)

Initializes a new instance of UnsafeMultiHashMap with the specified initial capacity and allocation handle.

public UnsafeMultiHashMap(int capacity, AllocationHandle handle, AllocationOption allocationOption = AllocationOption.None)

Parameters

capacity int

The initial capacity of the hash map.

handle AllocationHandle

The allocation handle.

allocationOption AllocationOption

The allocation option.

Properties

Capacity

public readonly int Capacity { get; }

Property Value

int

Count

Gets the number of elements in a collection. The value is read-only.

public readonly int Count { get; }

Property Value

int

IsCreated

Indicates whether the object has been created. Returns true if the object is created, otherwise false.

public readonly bool IsCreated { get; }

Property Value

bool

Methods

Add(scoped in TKey, TValue)

Adds a key-value pair to the UnsafeMultiHashMap. If the key already exists, the new value will be added alongside the existing value(s) for that key, allowing multiple values to be associated with the same key.

public void Add(scoped in TKey key, TValue item)

Parameters

key TKey

The key to add.

item TValue

The value to add.

Clear()

Removes all elements from the collection. The collection will be empty after this operation.

public void Clear()

ContainsKey(scoped in TKey)

Checks if the UnsafeMultiHashMap contains at least one value associated with the specified key.

public bool ContainsKey(scoped in TKey key)

Parameters

key TKey

The key to check for.

Returns

bool

true if the key is found; otherwise, false.

CountValuesForKey(scoped in TKey)

Counts the number of values associated with the specified key in the UnsafeMultiHashMap.

public int CountValuesForKey(scoped in TKey key)

Parameters

key TKey

The key for which to count values.

Returns

int

The number of values associated with the specified key.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

GetEnumerator()

[UnscopedRef]
public UnsafeMultiHashMap<TKey, TValue>.Enumerator GetEnumerator()

Returns

UnsafeMultiHashMap<TKey, TValue>.Enumerator

GetKeyArray(AllocationHandle)

Gets an unsafe array containing all keys in the UnsafeMultiHashMap.

public UnsafeArray<TKey> GetKeyArray(AllocationHandle allocationHandle)

Parameters

allocationHandle AllocationHandle

The handle for the allocation.

Returns

UnsafeArray<TKey>

An unsafe array containing all keys in the UnsafeMultiHashMap.

GetKeyValueArrays(AllocationHandle)

Gets an unsafe array containing all key-value pairs in the UnsafeMultiHashMap.

public UnsafeArray<KeyValuePair<TKey, TValue>> GetKeyValueArrays(AllocationHandle allocationHandle)

Parameters

allocationHandle AllocationHandle

The handle for the allocation.

Returns

UnsafeArray<KeyValuePair<TKey, TValue>>

An unsafe array containing all key-value pairs in the UnsafeMultiHashMap.

GetUnsafePtr()

Get a pointer to the internal buffer of the UnsafeMultiHashMap, which contains the key, values, and buckets. The caller must ensure that the pointer is not used after the UnsafeMultiHashMap has been disposed.

public readonly void* GetUnsafePtr()

Returns

void*

A pointer to the internal buffer.

GetValueArray(AllocationHandle)

Gets an unsafe array containing all values in the UnsafeMultiHashMap.

public UnsafeArray<TValue> GetValueArray(AllocationHandle allocationHandle)

Parameters

allocationHandle AllocationHandle

The handle for the allocation.

Returns

UnsafeArray<TValue>

An unsafe array containing all values in the UnsafeMultiHashMap.

GetValueOrDefault(scoped in TKey, TValue)

Gets the first value associated with the specified key, or returns a default value if the key is not found in the UnsafeMultiHashMap.

public TValue GetValueOrDefault(scoped in TKey key, TValue defaultValue = default)

Parameters

key TKey

The key for which to get the value.

defaultValue TValue

The default value to return if the key is not found.

Returns

TValue

The first value associated with the specified key, or the default value if the key is not found.

GetValuesForKey(scoped in TKey)

Gets an enumerable of all values associated with the specified key in the UnsafeMultiHashMap.

[UnscopedRef]
public UnsafeMultiHashMap<TKey, TValue>.ValueEnumerable GetValuesForKey(scoped in TKey key)

Parameters

key TKey

The key for which to get the values.

Returns

UnsafeMultiHashMap<TKey, TValue>.ValueEnumerable

An enumerable of all values associated with the specified key.

Remove(scoped in TKey)

Removes all values associated with the specified key from the UnsafeMultiHashMap.

public bool Remove(scoped in TKey key)

Parameters

key TKey

The key for which to remove values.

Returns

bool

bool indicating whether any values were removed.

Resize(int, AllocationOption)

Changes the size of a collection to the specified value.

public void Resize(int newSize, AllocationOption option = AllocationOption.None)

Parameters

newSize int

Specifies the new size to which the collection should be adjusted.

option AllocationOption

Specifies allocation options that may affect how memory is managed during the resize operation.

Remarks

This is to adjust the element count of the collection, not the size of the underlying buffer in memory.

TrimExcess()

Trim the excess capacity of the UnsafeMultiHashMap, reducing the capacity to match the current count of key-value pairs.

public void TrimExcess()

TryGetFirstValue(scoped in TKey, out TValue, out Iterator)

Tries to get the first value associated with the specified key.

public bool TryGetFirstValue(scoped in TKey key, out TValue item, out UnsafeMultiHashMap<TKey, TValue>.Iterator iterator)

Parameters

key TKey

The key for which to get the first value.

item TValue

When this method returns, contains the first value associated with the specified key, if the key is found; otherwise, the default value for the type of the item parameter.

iterator UnsafeMultiHashMap<TKey, TValue>.Iterator

When this method returns, contains the iterator for the first value associated with the specified key, if the key is found; otherwise, an invalid iterator.

Returns

bool

true if the key was found and the first value was retrieved; otherwise, false.

TryGetNextValue(out TValue, ref Iterator)

Tries to get the next value associated with the key from the UnsafeMultiHashMap using the provided iterator.

public bool TryGetNextValue(out TValue item, ref UnsafeMultiHashMap<TKey, TValue>.Iterator iterator)

Parameters

item TValue

When this method returns, contains the next value associated with the specified key, if the key is found; otherwise, the default value for the type of the item parameter.

iterator UnsafeMultiHashMap<TKey, TValue>.Iterator

The iterator to use for finding the next value.

Returns

bool

true if a value was found for the specified key; otherwise, false.

TryGetValue(scoped in TKey, out TValue)

Tries to get the first value associated with the specified key.

public bool TryGetValue(scoped in TKey key, out TValue item)

Parameters

key TKey

The key for which to get the first value.

item TValue

When this method returns, contains the first value associated with the specified key, if the key is found; otherwise, the default value for the type of the item parameter.

Returns

bool

true if the key was found and the first value was retrieved; otherwise, false.