Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you may want to try maintaining a min-heap and measure the performance difference. Here is a data structure called a Fibonacci heap that I've been working on. It probably could use a bit of work but you can at least test my hypothesis.</p> <pre><code>public sealed class FibonacciHeap&lt;TKey, TValue&gt; { readonly List&lt;Node&gt; _root = new List&lt;Node&gt;(); int _count; Node _min; public void Push(TKey key, TValue value) { Insert(new Node { Key = key, Value = value }); } public KeyValuePair&lt;TKey, TValue&gt; Peek() { if (_min == null) throw new InvalidOperationException(); return new KeyValuePair&lt;TKey,TValue&gt;(_min.Key, _min.Value); } public KeyValuePair&lt;TKey, TValue&gt; Pop() { if (_min == null) throw new InvalidOperationException(); var min = ExtractMin(); return new KeyValuePair&lt;TKey,TValue&gt;(min.Key, min.Value); } void Insert(Node node) { _count++; _root.Add(node); if (_min == null) { _min = node; } else if (Comparer&lt;TKey&gt;.Default.Compare(node.Key, _min.Key) &lt; 0) { _min = node; } } Node ExtractMin() { var result = _min; if (result == null) return null; foreach (var child in result.Children) { child.Parent = null; _root.Add(child); } _root.Remove(result); if (_root.Count == 0) { _min = null; } else { _min = _root[0]; Consolidate(); } _count--; return result; } void Consolidate() { var a = new Node[UpperBound()]; for (int i = 0; i &lt; _root.Count; i++) { var x = _root[i]; var d = x.Children.Count; while (true) { var y = a[d]; if (y == null) break; if (Comparer&lt;TKey&gt;.Default.Compare(x.Key, y.Key) &gt; 0) { var t = x; x = y; y = t; } _root.Remove(y); i--; x.AddChild(y); y.Mark = false; a[d] = null; d++; } a[d] = x; } _min = null; for (int i = 0; i &lt; a.Length; i++) { var n = a[i]; if (n == null) continue; if (_min == null) { _root.Clear(); _min = n; } else { if (Comparer&lt;TKey&gt;.Default.Compare(n.Key, _min.Key) &lt; 0) { _min = n; } } _root.Add(n); } } int UpperBound() { return (int)Math.Floor(Math.Log(_count, (1.0 + Math.Sqrt(5)) / 2.0)) + 1; } class Node { public TKey Key; public TValue Value; public Node Parent; public List&lt;Node&gt; Children = new List&lt;Node&gt;(); public bool Mark; public void AddChild(Node child) { child.Parent = this; Children.Add(child); } public override string ToString() { return string.Format("({0},{1})", Key, Value); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload