示例#1
0
 private void Link(FibHeapNode <T> y, FibHeapNode <T> x)
 {
     min            = RemoveNode(min, y);
     y.Parent       = x;
     y.RightSibling = y;
     y.LeftSibling  = y;
     x.Child        = ConcatenanteNode(x.Child, y);
     x.Degree++;
     y.Mark = false;
 }
示例#2
0
 private FibHeapNode <T> RemoveNode(FibHeapNode <T> list, FibHeapNode <T> node)
 {
     if (node.LeftSibling == node)
     {
         return(null);
     }
     node.LeftSibling.RightSibling = node.RightSibling;
     node.RightSibling.LeftSibling = node.LeftSibling;
     return(list);
 }
示例#3
0
        public void DecreaseKey(FibHeapNode <T> node, T key)
        {
            if (key.CompareTo(node.Key) > 0)
            {
                throw new Exception("new key cant be larger than previous key");
            }
            node.Key = key;
            var y = node.Parent;

            if (y != null && node.Key.CompareTo(y.Key) < 0)
            {
                Cut(node, y);
                CascadingCut(y);
            }
            if (node.Key.CompareTo(min.Key) == 0)
            {
                min = node;
            }
        }
示例#4
0
        private void Consolidate()
        {
            int arraySize = (int)(Math.Floor(Math.Log(nodeCount) / Math.Log(phi))) + 1;
            var array     = new FibHeapNode <T> [arraySize];

            if (min != null)
            {
                foreach (var node in min.SiblingsList)
                {
                    var x = node;
                    int d = x.Degree;
                    while (array[d] != null)
                    {
                        var y = array[d];
                        if (x.Key.CompareTo(y.Key) > 0)
                        {
                            var tmp = x;
                            x = y;
                            y = tmp;
                        }
                        Link(y, x);
                        array[d] = null;
                    }
                    array[d] = x;
                }
            }
            min = null;
            for (int i = 0; i < array.Length; i++)
            {
                if (array[i] != null)
                {
                    min = ConcatenanteNode(min, array[i]);
                    if (min == null || array[i].Key.CompareTo(min.Key) < 0)
                    {
                        min = array[i];
                    }
                }
            }
        }
示例#5
0
 public FibHeap()
 {
     min       = null;
     nodeCount = 0;
 }