예제 #1
0
        public unsafe void Test()
        {
            const int cnt = 1000;

            using var stack = new NativeStack <int>(0);
            var managed = new Stack <int>(cnt);

            var arr  = new int[cnt];
            var rand = new Random();

            for (int i = 0; i < cnt; i++)
            {
                arr[i] = rand.Next(cnt);
            }

            for (int i = 0; i < cnt; i++)
            {
                managed.Push(arr[i]);
                stack.Push(arr[i]);
            }

            var se = stack.GetEnumerator();
            var me = managed.GetEnumerator();

            for (var i = 0; i < cnt; i++)
            {
                se.MoveNext();
                me.MoveNext();
                Assert.True(se.Current == me.Current);
            }

            se.Dispose();
            me.Dispose();

            for (int i = 0; i < cnt; i++)
            {
                Assert.True(managed.Count == stack.Count);
                var l = managed.Pop();
                var r = stack.Peek();
                Assert.True(l == r);
                stack.Pop();
            }

            stack.Clear();
            stack.TrimExcess();

            Assert.True(!stack.IsDisposed);

            stack.Dispose();

            Assert.True(stack.Ptr == null);
            Assert.True(stack.IsDisposed);
        }
        public void IsEmpty()
        {
            var stack = new NativeStack <int>(Allocator.Temp);

            Assert.AreEqual(0, stack.Count);
            Assert.IsTrue(stack.IsEmpty);

            stack.Push(0);
            stack.Pop();

            Assert.AreEqual(0, stack.Count);
            Assert.IsTrue(stack.IsEmpty);

            stack.Push(1);
            stack.Push(2);
            stack.Clear();

            Assert.AreEqual(0, stack.Count);
            Assert.IsTrue(stack.IsEmpty);

            stack.Dispose();
        }
        private void AddPage()
        {
            var arr = new NativeArray <Entity>(_memory, ENTITIES_PER_POOL);

            _freeIds.EnsureCapacity(ENTITIES_PER_POOL);
            var newMax = (uint)_entityMap.Count * (uint)ENTITIES_PER_POOL + (uint)ENTITIES_PER_POOL;

            for (uint i = 0; i < ENTITIES_PER_POOL; i++)
            {
                _freeIds.Push(newMax - i - 1);
            }
            _free     += ENTITIES_PER_POOL;
            _capacity += ENTITIES_PER_POOL;
            _entityMap.Add(arr);
        }
 public void Push(VALUE item)
 {
     _stack.Push(item);
     MinHeapifyUp(_stack.LastItemIndex);
 }