Great! I'm really looking forward to it :-) You can add your PR at an early stage and push your commits from time-to-time. The first point might be fixed by leaving PriorityQueue as standalone type that is not implemented by Any opinions on that? I've experimented with Set and Map return types and think that it is ok to work with ? extends. This is a minor issue because Kind* is only relevant for the javaslang-pure module. PriorityQueue cannot extend Kind1, T> because it would be a conflict to Queue implements Kind1, T>.Some of the method return types of PriorityQueue contain ? extends PriorityQueue because of Java's lack of (declaration site) variance.before public class Queue implements Kind1, T>, LinearSeq, Serializable Still unsatisfied undecided with the type hierarchy.Ībove we see two disadvantages of letting Queue inherit PriorityQueue: A Comparator provides us with more options, we are able to create a Priority Queue using a rank/priority function priority: T -> int that induces a Comparator compare: T x T -> int: It implemented a mutable Priority Queue using an underlying Comparator. The second approach (using an ordering) goes well along with Java's standard collection. If the priority is independent of the element attributes, it can be seen as arbitrary/random from our viewpoint. The priority on the one hand is bound to an element but on the other hand it is not derived from that element. The first approach (using an explicit priority) is not intuitive because we may easily add one element with different priorities. Define an underlying ordering (= Comparator) when constructing a Priority Queue (much like in TreeSet).Provide an explicit priority as argument when pushing an element to the Priority Queue.Please note that a Stack is also a special Priority Queue but in Javaslang the Stack is not a collection but a marker interface with a bunch of Stack operations, so Stack will not implement Priority Queue.īefore talking about implementation details there is still a question (and I already have a suggested answer): Which API do we choose to assign an element a priority? the priority of each inserted element is monotonically decreasing", see wikipedia). This will be fun We add the PriorityQueue as interface to the existing type hierarchy:Ī (FIFO) Queue is a special Priority Queue (". Tomorrow I'm able to provide you with some more detailed information. We need to check the pros/cons compared to binary tree/heap impls More recent sources refer to FingerTree impls (, ). the Okasaki paper you referred to is of 1996.Maybe it needs to be a new collection type that extends Traversable, like Tree and Iterator. Is it a Set? What if we insert the same element with different priorities? (see this discussion: ). It would be nice to have a Queue interface but I think the PriorityQueue interface differs regarding the enqueue operation regarding the rank. Currently we have a class Queue which is a LinearSeq -> Seq -> Traversable. Maybe we need to change the existing types (interfaces vs classes). we need to decide how the PriorityQueue fits into the type hierarchy of the Javaslang collections.I'm returning home from vacation and have currently only my mobile phone at hand. In next blog post, we will move on to Graphs.Hi Pap, this is a great idea. Once again we are seeing the power of F#’s pattern matching & overall succinctness in play here. Within the various member definitions, IsEmpty & Size are basically read-only properties.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |