Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


NativeHashMap<TKey, TValue>

An unordered, expandable associative array.
Read time 2 minutesLast updated 6 days ago

Definition

public struct NativeHashMap<TKey, TValue> : INativeDisposable, IDisposable, IEnumerable<KVPair<TKey, TValue>>, IEnumerable where TKey : unmanaged, IEquatable<TKey> where TValue : unmanaged

Remarks

Not suitable for parallel write access. Use NativeParallelHashMap<TKey, TValue> instead.

Static Fields

Value

Description

MaxCapacityThe maximum number of elements this type of container can hold.

Constructors

Constructor

Description

NativeHashMap`2(System.Int32,Unity.Collections.AllocatorManager.AllocatorHandle)Initializes and returns an instance of UnsafeHashMap.

Properties

Property

Description

CapacityThe number of key-value pairs that fit in the current allocation.
CountThe current number of key-value pairs in this hash map.
IsCreatedWhether this hash map has been allocated (and not yet deallocated).
IsEmptyWhether this hash map is empty.
this[]Gets and sets values by key.

Methods

Method

Description

AddAdds a new key-value pair.
AsReadOnlyReturns a readonly version of this NativeHashMap instance.
ClearRemoves all key-value pairs.
ContainsKeyReturns true if a given key is present in this hash map.
DisposeReleases all resources (memory).
GetEnumeratorReturns an enumerator over the key-value pairs of this hash map.
GetKeyArrayReturns an array with a copy of all this hash map's keys (in no particular order).
GetKeyValueArraysReturns a NativeKeyValueArrays with a copy of all this hash map's keys and values.
GetValueArrayReturns an array with a copy of all this hash map's values (in no particular order).
RemoveRemoves a key-value pair.
TrimExcessSets the capacity to match what it would be if it had been originally initialized with all its entries.
TryAddAdds a new key-value pair.
TryGetValueReturns the value associated with a key.

Structs

Struct

Description

NativeHashMap<TKey, TValue>.EnumeratorAn enumerator over the key-value pairs of a container.
NativeHashMap<TKey, TValue>.ReadOnlyA read-only alias for the value of a NativeHashMap. Does not have its own allocated storage.