Exemplo n.º 1
0
        /// <summary>
        ///     Decreases the element inside a specified element pointer.
        /// </summary>
        /// <param name="element">The pointer to the element to decrease.</param>
        /// <param name="item">The new element.</param>
        /// <remarks>It is undefined behavior to increase the element.</remarks>
        public void Decrease(ElementPointer element, T item)
        {
            Debug.Assert(this._head != null);
            var node = element.Node;

            if (this._head == node)
            {
                node.Value = item;
                return;
            }

            Cut(node);
            node.LeftSiblingOrParent = null;
            node.RightSibling        = null;
            node.Value = item;
            this._head = this.Meld(this._head !, node);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Removes an element from the heap.
        /// </summary>
        /// <param name="element">The pointer to the element to be removed.</param>
        public void Remove(ElementPointer element)
        {
            Debug.Assert(this._head != null);
            var node = element.Node;

            if (this._head == node)
            {
                this._head = this.MergePairs(this._head.FirstChild);
                return;
            }

            Cut(node);
            if (node.FirstChild != null)
            {
                this._head = this.Meld(this._head !, this.MergePairs(node.FirstChild));
            }
        }
Exemplo n.º 3
0
 /// <summary>
 ///     Gets the element inside an element pointer.
 /// </summary>
 /// <param name="element">The pointer to the element.</param>
 /// <returns>The element referenced by the element pointer.</returns>
 public T this[ElementPointer element] => element.Node.Value;