Could this library support customized function as comparator for priority property?
See original GitHub issueHey, when I use this in leetcode, the use case is when I want a complicated comparator rather than simply compare by one value:
const biddersQueue = new MaxPriorityQueue({ priority: (bid) => bid.value });
// something i want:
const biddersQueue = new MaxPriorityQueue({ priority: (a,b) =>{ // comparator function} } );
maybe can this library support a comparator function in constructor?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Java Priority Queue with a custom anonymous comparator
You can use a PriorityQueue based on an anonymous Comparator passed to the constructor: ... Furthermore, PriorityQueues support generic data types.
Read more >Custom Comparator in Priority_queue in C++ STL
Comparator in the case of priority_queue decides the ordering of elements, which is basically in the competition among the elements, it decides ...
Read more >PriorityBlockingQueue (Java Platform SE 7 )
If you need to enforce an ordering, you can define custom classes or comparators that use a secondary key to break ties in...
Read more >Use the STL PRIORITY_QUEUE class with a custom type
This article provides a code sample that describes how to use the priority_queue template container of STL with custom types like classes ...
Read more >Underscore.js
Underscore provides over 100 functions that support both your favorite workaday functional ... This function can currently only compare numbers reliably.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @eyas-ranjous, I feel the same need as @jialihan.
One example is this question. Here, we are required to sort words by frequency, but if the word frequencies of two words are the same, then we need to sort them alphabetically.
For example, this is the initialization in Java:
Here is a mocked-up implementation of the expected functionality in JS.
Basically, priority number of a single item isn’t enough to decide the result of the comparison - we need to be able to write a custom comparator.
Cheers
feature released.
usage: https://github.com/datastructures-js/priority-queue#with-comparator