Ejemplo n.º 1
0
 private void GrowHeap()
 {
     this._capacity = this._capacity * 2 + 1;
     HeapEntry <T>[] heapEntryArray = new HeapEntry <T> [this._capacity];
     Array.Copy((Array)this._heap, 0, (Array)heapEntryArray, 0, this._count);
     this._heap = heapEntryArray;
 }
Ejemplo n.º 2
0
 private void GrowHeap()
 {
     _capacity = _capacity * 2 + 1;
     HeapEntry <T>[] heapEntryArray = new HeapEntry <T> [_capacity];
     Array.Copy(_heap, 0, heapEntryArray, 0, _count);
     _heap = heapEntryArray;
 }
Ejemplo n.º 3
0
 void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
 {
     info.AddValue("capacity", this._capacity);
     info.AddValue("count", this._count);
     HeapEntry <T>[] heapEntryArray = new HeapEntry <T> [this._count];
     Array.Copy((Array)this._heap, 0, (Array)heapEntryArray, 0, this._count);
     info.AddValue("heap", (object)heapEntryArray, typeof(HeapEntry <T>[]));
 }
Ejemplo n.º 4
0
        private void GrowHeap()
        {
            _capacity = (_capacity * 2) + 1;
            var newHeap = new HeapEntry <T> [_capacity];

            Array.Copy(_heap, 0, newHeap, 0, _count);

            _heap = newHeap;
        }
Ejemplo n.º 5
0
        void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue(CAPACITY_NAME, _capacity);
            info.AddValue(COUNT_NAME, _count);

            var heapCopy = new HeapEntry <T> [_count];

            Array.Copy(_heap, 0, heapCopy, 0, _count);

            info.AddValue(HEAP_NAME, heapCopy, typeof(HeapEntry <T>[]));
        }
Ejemplo n.º 6
0
        private void BubbleUp(int index, HeapEntry <T> he)
        {
            for (int parent = this.GetParent(index);
                 index > 0 && this._heap[parent].Priority.CompareTo((object)he.Priority) < 0;
                 parent = this.GetParent(index))
            {
                this._heap[index] = this._heap[parent];
                index             = parent;
            }

            this._heap[index] = he;
        }
Ejemplo n.º 7
0
        private void BubbleUp(int index, HeapEntry <T> he)
        {
            for (int parent = GetParent(index);
                 index > 0 && _heap[parent].Priority.CompareTo(he.Priority) < 0;
                 parent = GetParent(index))
            {
                _heap[index] = _heap[parent];
                index        = parent;
            }

            _heap[index] = he;
        }
Ejemplo n.º 8
0
        private void BubbleUp(int index, HeapEntry <T> he)
        {
            int parent = GetParent(index);

            // note: (index > 0) means there is a parent

            while ((index > 0) &&
                   (_heap[parent].Priority.CompareTo(he.Priority) < 0))
            {
                _heap[index] = _heap[parent];
                index        = parent;
                parent       = GetParent(index);
            }

            _heap[index] = he;
        }
Ejemplo n.º 9
0
        private void TrickleDown(int index, HeapEntry <T> he)
        {
            for (int leftChild = this.GetLeftChild(index);
                 leftChild < this._count;
                 leftChild = this.GetLeftChild(index))
            {
                if (leftChild + 1 < this._count &&
                    this._heap[leftChild].Priority.CompareTo((object)this._heap[leftChild + 1].Priority) < 0)
                {
                    ++leftChild;
                }
                this._heap[index] = this._heap[leftChild];
                index             = leftChild;
            }

            this.BubbleUp(index, he);
        }
Ejemplo n.º 10
0
        private void TrickleDown(int index, HeapEntry <T> he)
        {
            for (int leftChild = GetLeftChild(index);
                 leftChild < _count;
                 leftChild = GetLeftChild(index))
            {
                if (leftChild + 1 < _count &&
                    _heap[leftChild].Priority.CompareTo(_heap[leftChild + 1].Priority) < 0)
                {
                    ++leftChild;
                }
                _heap[index] = _heap[leftChild];
                index        = leftChild;
            }

            BubbleUp(index, he);
        }
Ejemplo n.º 11
0
        private void TrickleDown(int index, HeapEntry <T> he)
        {
            int child = GetLeftChild(index);

            while (child < _count)
            {
                if (((child + 1) < _count) &&
                    (_heap[child].Priority.CompareTo(_heap[child + 1].Priority) < 0))
                {
                    child++;
                }
                _heap[index] = _heap[child];
                index        = child;
                child        = GetLeftChild(index);
            }
            BubbleUp(index, he);
        }