F# priority queue

后端 未结 8 2086
鱼传尺愫
鱼传尺愫 2020-12-29 08:44

Does the F# library include a priority queue? Else can someone point to me an implementation of priority queue in F#?

8条回答
  •  [愿得一人]
    2020-12-29 09:10

    Just use an F# Set of pairs of your element type with a unique int (to allow duplicates) and extract your elements with set.MinElement or set.MaxElement. All of the relevant operations are O(log n) time complexity. If you really need O(1) repeated access to the minimum element you can simply cache it and update the cache upon insertion if a new minimum element is found.

    There are many kinds of heap data structures that you could try (skew heaps, splay heaps, pairing heaps, binomial heaps, skew binomial heaps, bootstrapped variants of the above). For a detailed analysis of their design, implementation and real-world performance see the article Data structures: heaps in The F#.NET Journal.

提交回复
热议问题