Example #1
0
        public IMinHeapVertex <TKey, TValue> Insert(TKey key, TValue value)
        {
            var vertex = new FibonacciHeapVertex <TKey, TValue>(this, key, value);

            if (IsEmpty)
            {
                vertex.Left  = vertex;
                vertex.Right = vertex;

                Min = vertex;
            }
            else
            {
                Insert(vertex);

                if (Comparer.Compare(vertex.Key, Min.Key) < 0)
                {
                    Min = vertex;
                }
            }

            Count++;

            return(vertex);
        }
Example #2
0
 /// <summary>
 ///     Inserts a vertex into the root list.
 /// </summary>
 /// <param name="vertex">The vertex that will be inserted into the root list.</param>
 internal void Insert(FibonacciHeapVertex <TKey, TValue> vertex)
 {
     vertex.Left       = Min;
     vertex.Right      = Min.Right;
     Min.Right         = vertex;
     vertex.Right.Left = vertex;
 }
Example #3
0
        private void Link(FibonacciHeapVertex <TKey, TValue> child, FibonacciHeapVertex <TKey, TValue> parent)
        {
            if (child == null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            if (parent == null)
            {
                throw new ArgumentNullException(nameof(parent));
            }

            child.Left.Right = child.Right;
            child.Right.Left = child.Left;

            child.Parent = parent;

            if (parent.Child == null)
            {
                child.Left  = child;
                child.Right = child;

                parent.Child = child;
            }
            else
            {
                child.Left         = parent.Child;
                child.Right        = parent.Child.Right;
                parent.Child.Right = child;
                child.Right.Left   = child;
            }

            parent.Degree++;

            child.IsMarked = false;
        }