< Summary

Class:GDX.Collections.Generic.ExpandingArray[T]
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Collections/Generic/ExpandingArray.cs
Covered lines:0
Uncovered lines:58
Coverable lines:58
Total lines:102
Line coverage:0% (0 of 58)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:13
Method coverage:0% (0 of 13)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ExpandingArray(...)0%2100%
Add(...)0%2100%
AddRange()0%2100%
AddRangeUnchecked()0%2100%
AddUnchecked(...)0%2100%
Clear()0%6200%
Ensure(...)0%6200%
GetSpan()0%2100%
GetSpan(...)0%2100%
GetReadOnlySpan()0%2100%
GetReadOnlySpan(...)0%2100%
HasData()0%2100%
Reset()0%2100%

File(s)

./Packages/com.dotbunny.gdx/GDX/Collections/Generic/ExpandingArray.cs

#LineLine coverage
 1// Copyright (c) 2020-2024 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5using System;
 6
 7namespace GDX.Collections.Generic
 8{
 9#if UNITY_2021_2_OR_NEWER
 10    public struct ExpandingArray<T>
 11    {
 12        T[] m_Array;
 13        int m_Head;
 14        int m_Size;
 15
 16        public ExpandingArray(int size)
 017        {
 018            m_Array = new T[size];
 019            m_Head = 0;
 020            m_Size = size;
 021        }
 22
 23        public void Add(T item)
 024        {
 025            Ensure(1);
 026            m_Array[m_Head] = item;
 027            m_Head++;
 028        }
 29
 30        public void AddRange(T[] items)
 031        {
 032            int size = items.Length;
 033            Ensure(size);
 034            Array.Copy(items, 0, m_Array, m_Head, size);
 035            m_Head += size;
 036        }
 37
 38        public void AddRangeUnchecked(T[] items)
 039        {
 040            int size = items.Length;
 041            Array.Copy(items, 0, m_Array, m_Head, size);
 042            m_Head += size;
 043        }
 44        public void AddUnchecked(T item)
 045        {
 046            m_Array[m_Head] = item;
 047            m_Head++;
 048        }
 49
 50        public void Clear()
 051        {
 052            for (int i = 0; i < m_Size; i++)
 053            {
 054                m_Array[i] = default;
 055            }
 056            m_Head = 0;
 057        }
 58
 59        void Ensure(int needed)
 060        {
 061            int space = m_Size - m_Head;
 062            if (space >= needed)
 063            {
 064                return;
 65            }
 66
 067            m_Size += needed;
 068            Array.Resize(ref m_Array, m_Size);
 069        }
 70
 71        public Span<T> GetSpan()
 072        {
 073            return new Span<T>(m_Array, 0, m_Head);
 074        }
 75
 76        public Span<T> GetSpan(int startIndex, int count)
 077        {
 078            return new Span<T>(m_Array, startIndex, count);
 079        }
 80
 81        public ReadOnlySpan<T> GetReadOnlySpan()
 082        {
 083            return new ReadOnlySpan<T>(m_Array, 0, m_Head);
 084        }
 85
 86        public ReadOnlySpan<T> GetReadOnlySpan(int startIndex, int count)
 087        {
 088            return new ReadOnlySpan<T>(m_Array, startIndex, count);
 089        }
 90
 91        public bool HasData()
 092        {
 093            return m_Head > 0;
 094        }
 95
 96        public void Reset()
 097        {
 098            m_Head = 0;
 099        }
 100    }
 101#endif // UNITY_2021_2_OR_NEWER
 102}