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

WIP: Heap Sort #18

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

WIP: Heap Sort #18

wants to merge 4 commits into from

Conversation

bluesign
Copy link
Contributor

No description provided.

//heap sort
//TODO: @bluesign: we need to add some generic comparators
pub fun comparatorUInt64(a:AnyStruct, b:AnyStruct, _ reverse:Bool):Bool{
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we follow what other languages so here and return -1, 0, or 1 depending on how the two elements compare?

}

pub fun heapSort(_ arr: &[AnyStruct], _ comparator: ((AnyStruct, AnyStruct, Bool): Bool), _ reverse:Bool ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Passing in a function to do the comparison makes a lot of sense to me. It would be great if cadence could expose this kind of interface in general but that seems like a much more involved task

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.

2 participants