public void CopyToTest()
        {
            var set = UnsafeSortedSet.Allocate <int>(10);

            // Fill set
            for (int i = 10; i >= 0; i--)
            {
                UnsafeSortedSet.Add(set, i);
            }

            var  count = UnsafeSortedSet.GetCount(set);
            int *arr   = stackalloc int[count];

            UnsafeSortedSet.CopyTo <int>(set, arr, 0);

            // Check
            int num = 0;

            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual(i, arr[num++]);
            }

            UnsafeSortedSet.Free(set);
        }
        public void AddRandomTest()
        {
            var set = UnsafeSortedSet.Allocate <int>(10);

            Random r = new Random();

            for (int i = 0; i < 10; i++)
            {
                UnsafeSortedSet.Add <int>(set, r.Next());
            }

            int *arr = stackalloc int[10];

            UnsafeSortedSet.CopyTo <int>(set, arr, 0);

            // Validate values are from low to high
            int last = arr[0];

            for (int i = 1; i < 10; i++)
            {
                Assert.IsTrue(last <= arr[i]);
                last = arr[i++];
            }

            UnsafeSortedSet.Free(set);
        }
        public void InvalidTypeTest()
        {
            var set = UnsafeSortedSet.Allocate <int>(10);

            Assert.Catch <AssertException>(() => { UnsafeSortedSet.Add <float>(set, 4); });

            UnsafeSortedSet.Free(set);
        }
        public void ConstructorTest()
        {
            var set = UnsafeSortedSet.Allocate <int>(10);

            Assert.AreEqual(0, UnsafeSortedSet.GetCount(set));
            Assert.AreEqual(10, UnsafeSortedSet.GetCapacity(set));

            UnsafeSortedSet.Free(set);
        }
        public void ClearTest()
        {
            var set = UnsafeSortedSet.Allocate <int>(16, fixedSize: false);

            // Add some random data
            Random r = new Random();

            for (int i = 0; i < 10; i++)
            {
                UnsafeSortedSet.Add <int>(set, r.Next());
            }

            // Verify data has been added
            Assert.AreEqual(10, UnsafeSortedSet.GetCount(set));
            Assert.AreEqual(16, UnsafeSortedSet.GetCapacity(set));

            // Clear set and verify it's cleared
            UnsafeSortedSet.Clear(set);

            Assert.AreEqual(0, UnsafeSortedSet.GetCount(set));
            Assert.AreEqual(16, UnsafeSortedSet.GetCapacity(set));


            // Validate we can still add data and have it be valid
            // Add data to cleared set
            for (int i = 10; i >= 0; i--)
            {
                UnsafeSortedSet.Add(set, i);
            }

            var  count = UnsafeSortedSet.GetCount(set);
            int *arr   = stackalloc int[count];

            UnsafeSortedSet.CopyTo <int>(set, arr, 0);

            // Validate data has been written
            int num = 0;

            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual(i, arr[num++]);
            }

            Assert.AreEqual(count, UnsafeSortedSet.GetCount(set));
            Assert.AreEqual(16, UnsafeSortedSet.GetCapacity(set));

            UnsafeSortedSet.Free(set);
        }
        public void ExpandTest()
        {
            var set = UnsafeSortedSet.Allocate <int>(8, fixedSize: false);

            // Valid adds
            for (int i = 0; i < 8; i++)
            {
                UnsafeSortedSet.Add(set, i + 1);
            }

            Assert.AreEqual(8, UnsafeSortedSet.GetCount(set));
            Assert.AreEqual(8, UnsafeSortedSet.GetCapacity(set));

            UnsafeSortedSet.Add(set, 42);

            Assert.AreEqual(9, UnsafeSortedSet.GetCount(set));
            Assert.AreEqual(16, UnsafeSortedSet.GetCapacity(set));

            UnsafeSortedSet.Free(set);
        }
        public void ExpandFailedTest()
        {
            var set = UnsafeSortedSet.Allocate <int>(8, true);

            // Valid adds
            for (int i = 0; i < 8; i++)
            {
                UnsafeSortedSet.Add(set, i + 1);
            }

            Assert.AreEqual(8, UnsafeSortedSet.GetCount(set));
            Assert.AreEqual(8, UnsafeSortedSet.GetCapacity(set));

            Assert.Throws <InvalidOperationException>(() =>
            {
                UnsafeSortedSet.Add(set, 42);
            });

            UnsafeSortedSet.Free(set);
        }
        public void IteratorTest()
        {
            var set = UnsafeSortedSet.Allocate <int>(10);

            // Fill set
            for (int i = 10; i >= 0; i--)
            {
                // Add in reverse order
                UnsafeSortedSet.Add(set, i);
            }

            var enumerator = UnsafeSortedSet.GetEnumerator <int>(set);

            for (int i = 0; i < 10; i++)
            {
                enumerator.MoveNext();
                Assert.AreEqual(i, enumerator.Current);
            }

            UnsafeSortedSet.Free(set);
        }
        public void RemoveTest()
        {
            var set = UnsafeSortedSet.Allocate <int>(10);

            Assert.IsFalse(UnsafeSortedSet.Remove <int>(set, 1));

            UnsafeSortedSet.Add(set, 1);
            UnsafeSortedSet.Add(set, 7);
            UnsafeSortedSet.Add(set, 51);
            UnsafeSortedSet.Add(set, 13);

            Assert.IsFalse(UnsafeSortedSet.Remove <int>(set, 3));

            Assert.IsTrue(UnsafeSortedSet.Remove <int>(set, 1));
            Assert.IsTrue(UnsafeSortedSet.Remove <int>(set, 7));
            Assert.IsTrue(UnsafeSortedSet.Remove <int>(set, 13));
            Assert.IsTrue(UnsafeSortedSet.Remove <int>(set, 51));

            Assert.IsFalse(UnsafeSortedSet.Remove <int>(set, 13));

            UnsafeSortedSet.Free(set);
        }
Exemple #10
0
        public void CopyTo(T[] array, int arrayIndex)
        {
            if (array == null)
            {
                throw new ArgumentNullException(nameof(array));
            }

            if ((uint)arrayIndex > array.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(arrayIndex));
            }

            if (array.Length - arrayIndex < Count)
            {
                throw new ArgumentException("Insufficient space in the target location to copy the information.");
            }

            if (array.Length == 0)
            {
                return;

                fixed(void *ptr = array)
                UnsafeSortedSet.CopyTo <T>(m_inner, ptr, arrayIndex);
        }
Exemple #11
0
 public void Clear()
 {
     UnsafeSortedSet.Clear(m_inner);
 }
Exemple #12
0
 public void Add(T item)
 {
     UnsafeSortedSet.Add <T>(m_inner, item);
 }
Exemple #13
0
 public NativeSortedSet(int capacity, bool fixedSize)
 {
     m_inner = UnsafeSortedSet.Allocate <T>(capacity, fixedSize);
 }
Exemple #14
0
 public NativeSortedSet(int capacity)
 {
     m_inner = UnsafeSortedSet.Allocate <T>(capacity, false);
 }
Exemple #15
0
 public bool Remove(T item)
 {
     return(UnsafeSortedSet.Remove <T>(m_inner, item));
 }
Exemple #16
0
 public bool Contains(T item)
 {
     return(UnsafeSortedSet.Contains <T>(m_inner, item));
 }