示例#1
0
 public void PeakEmptyHeapReturnsNull()
 {
     using (NativeBinaryHeap <int> heap = CreateEmptyHeap())
     {
         Assert.That(heap.Peak(), Is.Null);
     }
 }
示例#2
0
 public void ConstructorChoosesCapacityClosestToNextPowerOfTwo(int capacity, int expected)
 {
     using (NativeBinaryHeap <int> heap = new NativeBinaryHeap <int>(capacity, Allocator.Temp))
     {
         Assert.That(heap.Capacity, Is.EqualTo(expected));
     }
 }
示例#3
0
 public void ConstructorClampsToMinimumCapacity()
 {
     using (NativeBinaryHeap <int> heap = new NativeBinaryHeap <int>(1, Allocator.Temp))
     {
         Assert.That(heap.Capacity, Is.GreaterThan(1));
     }
 }
示例#4
0
 public void ConstructorCreatesEmptySet()
 {
     using (NativeBinaryHeap <int> heap = new NativeBinaryHeap <int>(1, Allocator.Temp))
     {
         Assert.That(heap.Length, Is.EqualTo(0));
     }
 }
示例#5
0
 public void GetLengthRequiresReadAccess()
 {
     using (NativeBinaryHeap <int> heap = CreateEmptyHeap())
     {
         int len;
         AssertRequiresReadOrWriteAccess(
             heap,
             () => len = heap.Length);
     }
 }
示例#6
0
 private static void AssertRequiresReadOrWriteAccess(
     NativeBinaryHeap <int> heap,
     Action action)
 {
     heap.TestUseOnlySetAllowReadAndWriteAccess(false);
     try
     {
         Assert.That(
             () => action(),
             Throws.TypeOf <InvalidOperationException>());
     }
     finally
     {
         heap.TestUseOnlySetAllowReadAndWriteAccess(true);
     }
 }
示例#7
0
        public void PushAndPopFunctionsCorrectly()
        {
            using (NativeBinaryHeap <int> heap = CreateEmptyHeap())
            {
                heap.Push(1);
                heap.Push(5);
                heap.Push(2);

                Assert.That(heap.Peak(), Is.EqualTo(5));
                Assert.That(heap.Length, Is.EqualTo(3));

                Assert.That(heap.Pop(), Is.EqualTo(5));
                Assert.That(heap.Pop(), Is.EqualTo(2));
                Assert.That(heap.Pop(), Is.EqualTo(1));
                Assert.That(heap.Pop(), Is.Null);
            }
        }
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log(UnsafeUtility.SizeOf(typeof(NativeQuadTreeNode)));

        binaryHeap = new NativeBinaryHeap <int>(100000, Allocator.Persistent);
        var binaryHeap2 = new BinaryHeap <int>((a, b) => { return(a < b); });

        var date2 = DateTime.UtcNow;

        for (var i = 0; i < 100000; i++)
        {
            binaryHeap2.Push(i);
        }

        for (var i = 10000; i >= 0; i--)
        {
            binaryHeap2.Remove(i);
        }

        Debug.Log((DateTime.UtcNow - date2).TotalSeconds);
        Debug.Log(binaryHeap2.Count);
        Debug.Log(binaryHeap2.Peek());

        var date = DateTime.UtcNow;

        new AddJob()
        {
            p = binaryHeap,
        }.Run();
        new RemoveJob()
        {
            p = binaryHeap
        }.Run();

        Debug.Log((DateTime.UtcNow - date).TotalSeconds);
        Debug.Log(binaryHeap.Count);
        Debug.Log(binaryHeap.Peek());
    }