using System;
namespace Unity.Collections.LowLevel.Unsafe
{
public static class UnsafeHashMapAsRefExtensions
{
public static ref TValue TryGetValueAsRef<TKey, TValue>(
this ref UnsafeHashMap<TKey, TValue> hashMap,
in TKey key,
ref TValue defaultRef)
where TValue : unmanaged
where TKey : unmanaged, IEquatable<TKey>
{
ref var data = ref hashMap.m_Data;
int idx = data.Find(key);
if (-1 != idx)
return ref data.GetElementAt<TValue>(idx);
return ref defaultRef;
}
}
}
For me there was no GetElementAt<TValue>(idx) method in the UnsafeHashMapHelper struct. It may have gotten removed at some point so I replaced that line with the following:
if (-1 != idx)
return ref UnsafeUtility.ArrayElementAsRef<TValue>(data.Ptr, idx);