Beispiel #1
0
        public void CopyToTest()
        {
            var set = UnsafeHashSet.Allocate <int>(10);

            // Fill set
            for (int i = 0; i < 10; i++)
            {
                UnsafeHashSet.Add(set, i);
            }

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

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

            // Check
            int num = 0;

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

            UnsafeHashSet.Free(set);
        }
Beispiel #2
0
        public void AddTest()
        {
            var set = UnsafeHashSet.Allocate <int>(10);

            for (int i = 0; i < 10; i++)
            {
                UnsafeHashSet.Add <int>(set, i * i * i);
            }

            int *arr = stackalloc int[10];

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

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

            UnsafeHashSet.Free(set);
        }
Beispiel #3
0
        public void CopyHashCollisionTest()
        {
            // Tests linked-list functionality when hash collisions occur.
            var set = UnsafeHashSet.Allocate <DuplicateKey>(3);

            Assert.IsTrue(UnsafeHashSet.Add(set, new DuplicateKey(1)));
            Assert.IsTrue(UnsafeHashSet.Add(set, new DuplicateKey(2)));
            Assert.IsTrue(UnsafeHashSet.Add(set, new DuplicateKey(3)));

            var arr = stackalloc DuplicateKey[3];

            UnsafeHashSet.CopyTo <DuplicateKey>(set, arr, 0);

            for (int i = 0; i < 3; i++)
            {
                Assert.AreEqual(new DuplicateKey(i + 1), arr[i]);
            }

            UnsafeHashSet.Free(set);
        }
Beispiel #4
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)
                UnsafeHashSet.CopyTo <T>(m_inner, ptr, arrayIndex);
        }