WIP: add priority queue using a binary heap internally#6873
WIP: add priority queue using a binary heap internally#6873simonvonhackewitz wants to merge 1 commit intotokiwa-software:mainfrom
Conversation
|
|
||
| # create a string representation of the binary heap | ||
| # | ||
| public dbg_str String => |
There was a problem hiding this comment.
please avoid using abbreviations in public API features
|
|
||
| # check if the heap property still holds | ||
| # | ||
| public check_heap_property bool => # NYI: CLEANUP: remove debug code |
There was a problem hiding this comment.
reminder to possibly keep debug code separately and explain why you wrote it and how it was useful for development and why it is no longer necessary in the final version in your project work
michaellilltokiwa
left a comment
There was a problem hiding this comment.
Lots of small(er) comments from me, sorry. Overall structure is pretty much what I would expect. We have a mutable queue definition with enqueue/dequeue functionality. Of to a good start!
| # | ||
| # ----------------------------------------------------------------------- | ||
|
|
||
| module:public Mutable_Priority_Queue(public T type) ref is |
There was a problem hiding this comment.
It may make sense to constraint this T to orderable and thus avoid all the other constraints.
There was a problem hiding this comment.
Should probably be just public since others may want to provide different implementations?
|
|
||
| # all elements in this queue as an unordered Sequence | ||
| # | ||
| public as_unordered Sequence T => abstract |
There was a problem hiding this comment.
Not sure if/why this is needed?
| # Create an empty priority queue that determines which element | ||
| # to return first by the given comparator | ||
| # | ||
| public type.empty_comp(first_or_same Binary bool T1 T1) container.Mutable_Priority_Queue T1 |
There was a problem hiding this comment.
The name first_or_same is a little confusing? Is it basically just a comparator?
|
|
||
| # unordered elements to construct the queue from | ||
| # | ||
| initial_elements option (Sequence T)) ref : container.Mutable_Priority_Queue T is |
There was a problem hiding this comment.
Since this constructor is not public anyway, I would probably prefer all initialization to be done outside of the constructor. So it would have elements as an arg instead of initial_elements.
This way the constructor does not not contain any code which may make error handling more easy.
| else | ||
| # width of current node, left and right subtree | ||
| cur_w, sub_l_w, sub_r_w := | ||
| { |
There was a problem hiding this comment.
Are the braces needed?
|
|
||
|
|
||
| # binary heap with the elements in the queue | ||
| # implemented as an array with ahnentafel ordering |
There was a problem hiding this comment.
What is ahnentafel ordering?
| # | ||
| # ----------------------------------------------------------------------- | ||
|
|
||
| module:public Binary_Heap_Queue( |
There was a problem hiding this comment.
Would be good to have some ascii art or text to describe on a high level how this queue is built.
| # | ||
| # Tokiwa Software GmbH, Germany | ||
| # | ||
| # Source code of Fuzion standard library feature mutable_priority_queue |
There was a problem hiding this comment.
| # Source code of Fuzion standard library feature mutable_priority_queue | |
| # Source code of Fuzion standard library feature Binary_Heap_Queue |
| # binary heap with the elements in the queue | ||
| # implemented as an array with ahnentafel ordering | ||
| # | ||
| elements := |
There was a problem hiding this comment.
I'm failing to understand how subtrees, mentioned elsewhere, are reflected/stored in these elements.
No description provided.