internal NativeMappedAggregator(int capacity, Allocator allocator, TAggregator shell = default) { CollectionHelper.CheckIsUnmanaged <TKey>(); CollectionHelper.CheckIsUnmanaged <TData>(); mAllocator = allocator; // Bucket size is bigger to reduce collisions UnsafeHashMapData.AllocateHashMap <TKey, TData>(capacity, capacity << 1, allocator, out mBuffer); UnsafeHashMapBase <TKey, TData> .Clear(mBuffer); mShell = shell; }
/// <summary> /// Add an element with the specified key and value into the container. /// </summary> /// <param name="key">The key of the element to add.</param> /// <param name="item">The value of the element to add.</param> public void Add(TKey key, TValue item) { UnsafeHashMapBase <TKey, TValue> .TryAdd(m_Buffer, key, item, true, m_AllocatorLabel); }
/// <summary> /// Clears the container. /// </summary> /// <remarks>Containers capacity remains unchanged.</remarks> public void Clear() { UnsafeHashMapBase <TKey, TValue> .Clear(m_Buffer); }
/// <summary> /// Add an element with the specified key and value into the container. /// </summary> /// <param name="key">The key of the element to add.</param> /// <param name="item">The value of the element to add.</param> public void Add(TKey key, TValue item) { Assert.IsTrue(m_ThreadIndex >= 0); UnsafeHashMapBase <TKey, TValue> .AddAtomicMulti(m_Buffer, key, item, m_ThreadIndex); }
/// <summary> /// Replace value at iterator. /// </summary> /// <param name="item">Value.</param> /// <param name="it">Iterator</param> /// <returns>Returns true if value was sucessfuly replaced.</returns> public bool SetValue(TValue item, NativeMultiHashMapIterator <TKey> it) { return(UnsafeHashMapBase <TKey, TValue> .SetValue(m_Buffer, ref it, ref item)); }
/// <summary> /// Retrieve iterator to the next value for the key. /// </summary> /// <param name="item">Output value.</param> /// <param name="it">Iterator.</param> /// <returns>Returns true if next value for the key is found.</returns> public bool TryGetNextValue(out TValue item, ref NativeMultiHashMapIterator <TKey> it) { return(UnsafeHashMapBase <TKey, TValue> .TryGetNextValueAtomic(m_Buffer, out item, ref it)); }
/// <summary> /// Retrieve iterator for the first value for the key. /// </summary> /// <param name="key">The key.</param> /// <param name="item">Output value.</param> /// <param name="it">Iterator.</param> /// <returns>Returns true if the container contains the key.</returns> public bool TryGetFirstValue(TKey key, out TValue item, out NativeMultiHashMapIterator <TKey> it) { return(UnsafeHashMapBase <TKey, TValue> .TryGetFirstValueAtomic(m_Buffer, key, out item, out it)); }
/// <summary> /// Removes all elements with the specified iterator the container. /// </summary> /// <param name="it">Iterator pointing at value to remove.</param> public void Remove(NativeMultiHashMapIterator <TKey> it) { UnsafeHashMapBase <TKey, TValue> .Remove(m_Buffer, it); }
public void Remove <TValueEQ>(TKey key, TValueEQ value) where TValueEQ : struct, IEquatable <TValueEQ> { UnsafeHashMapBase <TKey, TValueEQ> .RemoveKeyValue(m_Buffer, key, value); }
/// <summary> /// Removes all elements with the specified key from the container. /// </summary> /// <param name="key">The key of the element to remove.</param> /// <returns>Returns number of removed items.</returns> public int Remove(TKey key) { return(UnsafeHashMapBase <TKey, TValue> .Remove(m_Buffer, key, true)); }