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}");
            }
        }
    }
        UndoPropertyModification[] PostprocessModifications(UndoPropertyModification[] modifications)
        {
            foreach (var mod in modifications)
            {
                var target = GetGameObjectFromAny(mod.currentValue.target);
                if (target)
                {
                    var liveLink = GetLiveLink(target.scene);
                    if (liveLink != null)
                    {
                        liveLink.AddChanged(target);
                        EditorUpdateUtility.EditModeQueuePlayerLoopUpdate();
                    }
                }
            }

            if (m_AssetDependencies.Count() > 0)
            {
                foreach (var mod in modifications)
                {
                    AssetDatabase.TryGetGUIDAndLocalFileIdentifier(mod.currentValue.target, out var guid, out long _);
                    if (m_AssetDependencies.ContainsKey(new GUID(guid)))
                    {
                        GlobalDirtyLiveLink();
                        break;
                    }
                }
            }

            return(modifications);
        }
    public void UnsafeHashMap_Performance_Count([Values(10, 100, 1000, 10000, 100000, 1000000, 2500000, 10000000)] int capacity)
    {
        using (var container = new UnsafeHashMap <int, int>(capacity, Allocator.Persistent))
        {
            container.Add(1, 1);

            Measure.Method(() =>
            {
                container.Count();
            })
            .WarmupCount(10)
            .MeasurementCount(10)
            .Run();
        }
    }
示例#4
0
 /// <summary>
 /// The current number of items in the container.
 /// </summary>
 /// <returns>The item count.</returns>
 public int Count()
 {
     CheckRead();
     return(m_HashMapData.Count());
 }
示例#5
0
 /// <summary>
 /// The current number of items in the container.
 /// </summary>
 /// <returns>The item count.</returns>
 public int Count() => m_Data.Count();