示例#1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FibonacciHeap{TPriority,TValue}"/> class.
 /// </summary>
 /// <param name="direction">Heap direction.</param>
 /// <param name="priorityComparison">Priority comparer.</param>
 /// <exception cref="T:System.ArgumentNullException"><paramref name="priorityComparison"/> is <see langword="null"/>.</exception>
 public FibonacciHeap(HeapDirection direction, [NotNull] Comparison <TPriority> priorityComparison)
 {
     _cells               = new FibonacciHeapLinkedList <TPriority, TValue>();
     _degreeToCell        = new Dictionary <int, FibonacciHeapCell <TPriority, TValue> >();
     _directionMultiplier = (short)(direction == HeapDirection.Increasing ? 1 : -1);
     Direction            = direction;
     PriorityComparison   = priorityComparison ?? throw new ArgumentNullException(nameof(priorityComparison));
     Count = 0;
 }
示例#2
0
        /// <summary>
        /// Merges the given <paramref name="cells"/> at the end of this cells list.
        /// </summary>
        /// <param name="cells">Cells to merge.</param>
        internal void MergeLists([NotNull] FibonacciHeapLinkedList <TPriority, TValue> cells)
        {
            Debug.Assert(cells != null);

            if (cells.First is null)
            {
                return;
            }

            if (_last != null)
            {
                _last.Next = cells.First;
            }

            cells.First.Previous = _last;
            _last = cells._last;

            if (First is null)
            {
                First = cells.First;
            }
        }