Пример #1
0
        public void Remove(FibonacciHeapCell <TPriority, TValue> node)
        {
            if (node is null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            if (node.Previous != null)
            {
                node.Previous.Next = node.Next;
            }
            else if (first == node)
            {
                first = node.Next;
            }

            if (node.Next != null)
            {
                node.Next.Previous = node.Previous;
            }
            else if (last == node)
            {
                last = node.Previous;
            }

            node.Next     = null;
            node.Previous = null;
        }
Пример #2
0
        public FibonacciHeapCell <TPriority, TValue> Enqueue(TPriority priority, TValue value)
        {
            var newNode = new FibonacciHeapCell <TPriority, TValue>()
            {
                Priority = priority,
                Value    = value,
                Marked   = false,
                Degree   = 1,
                Next     = null,
                Previous = null,
                Parent   = null,
                Removed  = false
            };

            // we don't do any book keeping or maintenance of the heap on Enqueue,
            // we just add this node to the end of the list of Heaps, updating the Next if required
            nodes.AddLast(newNode);
            if (next == null || comparer(newNode.Priority, next.Priority) * directionMultiplier < 0)
            {
                next = newNode;
            }

            count++;

            return(newNode);
        }
Пример #3
0
        public void Delete(FibonacciHeapCell <TPriority, TValue> node)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            ChangeKeyInternal(node, default, true);
Пример #4
0
        public void AddLast(FibonacciHeapCell <TPriority, TValue> node)
        {
            if (node is null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            if (last != null)
            {
                last.Next = node;
            }

            node.Previous = last;
            last          = node;

            if (first == null)
            {
                first = node;
            }
        }
Пример #5
0
        public void Merge(FibonacciHeapLinkedList <TPriority, TValue> list)
        {
            if (list is null)
            {
                throw new ArgumentNullException(nameof(list));
            }

            if (list.First != null)
            {
                if (last != null)
                {
                    last.Next = list.First;
                }

                list.First.Previous = last;
                last = list.Last;

                if (first == null)
                {
                    first = list.First;
                }
            }
        }
Пример #6
0
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 internal FibonacciHeapLinkedList()
 {
     first = null;
     last  = null;
 }
Пример #7
0
 public void Clear()
 {
     first = null;
     last  = null;
 }
Пример #8
0
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 /// <param name="node"></param>
 /// <param name="level"></param>
 public NodeLevel(FibonacciHeapCell <TPriority, TValue> node, int level)
 {
     this.node  = node;
     this.level = level;
 }