/// <summary> /// Returns whether or not the given NativeHeapIndex is a valid index for this container. If true, /// that index can be used to Remove the element tied to that index from the container. /// /// This method will always return true if IsUsingSafetyChecks returns false. /// </summary> public bool IsValidIndex(NativeHeapIndex index, out string error) { error = null; #if NHEAP_SAFE unsafe { AtomicSafetyHandle.CheckReadAndThrow(m_Safety); if (index.StructureId != _id) { error = "The provided ItemHandle was not valid for this NativeHeap. It was taken from a different instance."; return(false); } if (index.TableIndex >= _data->Capacity) { error = "The provided ItemHandle was not valid for this NativeHeap."; return(false); } TableValue tableValue = _data->Table[index.TableIndex]; if (tableValue.Version != index.Version) { error = "The provided ItemHandle was not valid for this NativeHeap. The item it pointed to might have already been removed."; return(false); } } #endif return(true); }
/// <summary> /// Returns whether or not the given NativeHeapIndex is a valid index for this container. If true, /// that index can be used to Remove the element tied to that index from the container. /// /// This method will always return true if IsUsingSafetyChecks returns false. /// </summary> public bool IsValidIndex(NativeHeapIndex index) { return(IsValidIndex(index, out _)); }