Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add priority queue to generic collections #13903

Closed
thoren-d opened this issue Nov 28, 2014 · 7 comments
Closed

Add priority queue to generic collections #13903

thoren-d opened this issue Nov 28, 2014 · 7 comments
Labels
api-needs-work API needs work before it is approved, it is NOT ready for implementation
Milestone

Comments

@thoren-d
Copy link

I see the generic collections haven't been incorporating into this project yet, but when that happens, I'd like to contribute a priority queue to the library. It's a pretty commonly used data structure and I'm surprised there isn't one in there already.

What I've got is based on a flat binary heap and either uses items that implement IComparable or takes an IComparer.

@dilijev
Copy link

dilijev commented Dec 1, 2014

My understanding is that some datastructures already use PQ internally, but I could very well be mistaken about this. The documentation isn't especially clear on this point.

@karldodd
Copy link

Will be a nice API addition :) Java has had its PriorityQueue for quite some time.

Even better if there is a thread-safe concurrent priority queue under System.Collections.Concurrent.

@colombod
Copy link
Member

I totally like @karldodd suggestion, would love to contribute!

@ebickle
Copy link

ebickle commented Jan 29, 2015

Absolutely agree. I have my own person implementation of a priority queue in C#, if we want to use it as a starting point. This is a data structure that's been sorely needed for a long time.

'Priority queue' is the traditional name for the data structure, but if you look at the existing naming conventions for collections in .NET they use more user-friendly names. Perhaps SortedQueue, to match SortedDictionary<TKey, TValue> and SortedSet?

My current API looks a bit like this:

public class PriorityQueue<T>
{
    public PriorityQueue();
    public PriorityQueue(Comparison<T>);
    public PriorityQueue(IComparer<T>);
    public PriorityQueue(IEnumerable<T>);
    public PriorityQueue(IEnumerable<T>, Comparison<T>);
    public PriorityQueue(IEnumerable<T>, IComparer<T>);
    public bool IsEmpty { get; }
    public int Count { get; }
    public void Enqueue(T item);
    public T Dequeue();
    public T Peek();
    public void CopyTo(T[] array, int index);
    public T[] ToArray();
} 

Will need to add ICollection, IReadOnlyCollection, IEnumerable, and IEnumerable at very least. Constructors to set the initial capacity as well.

Open to drafting up an API proposal.

@stephentoub
Copy link
Member

Closing to consolidate with same feature being requested in detail in dotnet/corefx#574

@hickford
Copy link
Contributor

Data structures are the fundamental primitives of algorithm design. It's important for the standard library to have fast reliable well-documented implementations. Otherwise developers waste time reinventing the wheel.

.NET is desperately missing a priority queue, please add one.

@colombod
Copy link
Member

I think priority queue are implemented in top of the sorted collection.

On 27 Nov 2015, at 14:32, Mirth Hickford notifications@github.com wrote:

Data structures are the fundamental primitives of algorithm design. It's important for the standard library to have fast reliable well-documented implementations. Otherwise developers waste time reinventing the wheel.

.NET is desperately missing a priority queue, please add one.


Reply to this email directly or view it on GitHub.

Olafski referenced this issue in Olafski/corefx Jun 15, 2017
Fix contributor list links for the dotnet/cli repository.
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 1.0.0-rtm milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-needs-work API needs work before it is approved, it is NOT ready for implementation
Projects
None yet
Development

No branches or pull requests

9 participants