コード例 #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
ファイル: FibonacciHeap.cs プロジェクト: techtician/Cogito
        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
ファイル: FibonacciHeap.cs プロジェクト: techtician/Cogito
        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
ファイル: FibonacciHeap.cs プロジェクト: techtician/Cogito
 /// <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;
 }