Example #1
0
        /// <summary>
        /// Returns arrays populated with keys and values.
        /// </summary>
        /// <remarks>If key contains multiple values, returned key array will contain multiple identical keys.</remarks>
        /// <param name="allocator">A member of the
        /// [Unity.Collections.Allocator](https://docs.unity3d.com/ScriptReference/Unity.Collections.Allocator.html) enumeration.</param>
        /// <returns>Array of keys-values.</returns>
        public NativeKeyValueArrays <TKey, TValue> GetKeyValueArrays(Allocator allocator)
        {
            var result = new NativeKeyValueArrays <TKey, TValue>(Count(), allocator, NativeArrayOptions.UninitializedMemory);

            UnsafeHashMapData.GetKeyValueArrays(m_Buffer, result);
            return(result);
        }
Example #2
0
 /// <summary>
 /// Constructs a new container with the specified initial capacity and type of memory allocation.
 /// </summary>
 /// <param name="capacity">The initial capacity of the container. If the list grows larger than its capacity,
 /// the internal array is copied to a new, larger array.</param>
 /// <param name="allocator">A member of the
 /// [Unity.Collections.Allocator](https://docs.unity3d.com/ScriptReference/Unity.Collections.Allocator.html) enumeration.</param>
 public UnsafeMultiHashMap(int capacity, Allocator allocator)
 {
     m_AllocatorLabel = allocator;
     // Bucket size if bigger to reduce collisions
     UnsafeHashMapData.AllocateHashMap <TKey, TValue>(capacity, capacity * 2, allocator, out m_Buffer);
     Clear();
 }
Example #3
0
        public NativeArray <TData> ToDataArray(Allocator allocator)
        {
            var result = new NativeArray <TData>(Count(), allocator, NativeArrayOptions.UninitializedMemory);

            UnsafeHashMapData.GetValueArray(mBuffer, result);
            return(result);
        }
Example #4
0
        //---------------------------------------------------------------------------------------------------------
        #region To Array

        public NativeArray <TKey> ToKeyArray(Allocator allocator)
        {
            var keys = new NativeArray <TKey>(Count(), allocator, NativeArrayOptions.UninitializedMemory);

            UnsafeHashMapData.GetKeyArray(mBuffer, keys);
            return(keys);
        }
Example #5
0
        /// <summary>
        /// The current number of items in the container.
        /// </summary>
        /// <returns>The item count.</returns>
        public int Count()
        {
            if (m_Buffer->allocatedIndexLength <= 0)
            {
                return(0);
            }

            return(UnsafeHashMapData.GetCount(m_Buffer));
        }
Example #6
0
        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;
        }
Example #7
0
 public bool TryRead(ref UnsafeHashMapEntryIterator itr, out TKey key, out TValue value, out TResult result)
 {
     if (itr.entryIndex != -1)
     {
         key = UnsafeHashMapData.KeyAtEntry <TKey>(itr, mBuffer);
         var data = UnsafeHashMapData.ValueAtEntry <TData>(itr, mBuffer);
         value  = data.Value;
         result = data.Result;
         return(true);
     }
     else
     {
         key    = default;
         value  = default;
         result = default;
         return(false);
     }
 }
Example #8
0
 /// <summary>
 /// Disposes of this multi-hashmap and deallocates its memory immediately.
 /// </summary>
 public void Dispose()
 {
     UnsafeHashMapData.DeallocateHashMap(m_Buffer, m_AllocatorLabel);
     m_Buffer = null;
 }
Example #9
0
 public bool TryGetNext(ref UnsafeHashMapEntryIterator itr) => UnsafeHashMapData.NextEntryIndex(mBuffer, ref itr);
Example #10
0
        //---------------------------------------------------------------------------------------------------------
        #region iterator Access

        public bool TryGetFirst(out UnsafeHashMapEntryIterator itr) => UnsafeHashMapData.FirstEntryIndex(mBuffer, out itr);