コード例 #1
0
    public void UnsafeHashMap_Performance_RepeatLookup([Values(10, 100, 1000, 10000, 100000, 1000000, 2500000, 10000000)] int insertions)
    {
        using (var container = new UnsafeHashMap <int, int>(insertions, Allocator.Persistent))
        {
            using (var addedKeys = new NativeList <int>(insertions, Allocator.Persistent))
            {
                Random.InitState(0);
                for (int i = 0; i < insertions; i++)
                {
                    int randKey = Random.Range(0, insertions);
                    container.Add(randKey, randKey);
                    addedKeys.Add(randKey);
                }

                Measure.Method(() =>
                {
                    for (int i = 0; i < insertions; i++)
                    {
                        int randKey = addedKeys[i];
                        Assert.IsTrue(container.TryGetValue(randKey, out _));
                    }
                })
                .WarmupCount(10)
                .MeasurementCount(10)
                .Run();
            }
        }
    }
コード例 #2
0
    public void UnsafeHashMap_ForEach([Values(10, 1000)] int n)
    {
        var seen = new NativeArray <int>(n, Allocator.Temp);

        using (var container = new UnsafeHashMap <int, int>(32, Allocator.TempJob))
        {
            for (int i = 0; i < n; i++)
            {
                container.Add(i, i * 37);
            }

            var count = 0;
            foreach (var kv in container)
            {
                int value;
                Assert.True(container.TryGetValue(kv.Key, out value));
                Assert.AreEqual(value, kv.Value);
                Assert.AreEqual(kv.Key * 37, kv.Value);

                seen[kv.Key] = seen[kv.Key] + 1;
                ++count;
            }

            Assert.AreEqual(container.Count(), count);
            for (int i = 0; i < n; i++)
            {
                Assert.AreEqual(1, seen[i], $"Incorrect key count {i}");
            }
        }
    }
コード例 #3
0
            private void RecurseChildrenAndEnable(Entity entity, ref UnsafeHashMap <Entity, bool> metadata)
            {
                if (!Children.HasComponent(entity))
                {
                    return;
                }

                var children = Children[entity].AsNativeArray();

                for (int i = 0; i < children.Length; i++)
                {
                    var child = children[i].Value;

                    CmdBuffer.AddComponent <EnableRenderingTag>(child);
                    CmdBuffer.AddComponent <UpdateVertexColorTag>(child);

                    metadata.TryGetValue(child, out bool isActive);

                    if (isActive)
                    {
                        CmdBuffer.RemoveComponent <Disabled>(child);
                    }

                    RecurseChildrenAndEnable(child, ref metadata);
                }
            }
コード例 #4
0
        internal void UnregisterParameter(int parameter)
        {
            if (parameter == 0)
            {
                return;
            }
            if (!uniqueParameters.TryGetValue(parameter, out var item))
            {
                return;
            }
            item.count--;
            if (item.count < 0)
            {
                item.count = 0;
            }
            uniqueParameters[parameter] = item;

            // TODO: have some way to remove parameters (swap with last index? would need to swap things outside of this class as well somehow)
        }
        internal int AddSystemType(long typeHash, FixedString64 debugName, UnmanagedComponentSystemDelegates delegates)
        {
            if (m_TypeHashToIndex.TryGetValue(typeHash, out int index))
            {
                if (m_DebugNames[index] != debugName)
                {
                    Debug.LogError($"Type hash {typeHash} for {debugName} collides with {m_DebugNames[index]}. Skipping this type. Rename the type to avoid the collision.");
                    return(-1);
                }

                m_Delegates[index] = delegates;
                return(index);
            }
            else
            {
                int newIndex = m_Delegates.Length;
                m_TypeHashToIndex.Add(typeHash, newIndex);
                m_DebugNames.Add(debugName);
                m_Delegates.Add(delegates);
                return(newIndex);
            }
        }
コード例 #6
0
 /// <summary>
 /// Gets the value associated with the specified key.
 /// </summary>
 /// <param name="key">The key of the value to get.</param>
 /// <param name="item">If key is found item parameter will contain value</param>
 /// <returns>Returns true if key is found, otherwise returns false.</returns>
 public bool TryGetValue(TKey key, out TValue item)
 {
     CheckRead();
     return(m_HashMapData.TryGetValue(key, out item));
 }
コード例 #7
0
 public ref T TryGetSystemData <T>(uint systemId, out bool success)
     where T : struct
 {
     success = UnsafeHashMap.TryGetValue(SystemData, systemId, out IntPtr ptr);
     return(ref Unsafe.AsRef <T>(ptr.ToPointer()));
 }