Skip to content

WIP: add priority queue using a binary heap internally#6873

Draft
simonvonhackewitz wants to merge 1 commit intotokiwa-software:mainfrom
simonvonhackewitz:priority_queue
Draft

WIP: add priority queue using a binary heap internally#6873
simonvonhackewitz wants to merge 1 commit intotokiwa-software:mainfrom
simonvonhackewitz:priority_queue

Conversation

@simonvonhackewitz
Copy link
Copy Markdown
Collaborator

No description provided.


# create a string representation of the binary heap
#
public dbg_str String =>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

@michaellilltokiwa michaellilltokiwa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may make sense to constraint this T to orderable and thus avoid all the other constraints.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :=
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the braces needed?



# binary heap with the elements in the queue
# implemented as an array with ahnentafel ordering
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is ahnentafel ordering?

#
# -----------------------------------------------------------------------

module:public Binary_Heap_Queue(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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 :=
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm failing to understand how subtrees, mentioned elsewhere, are reflected/stored in these elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants