Skip to content

Comments

WIP: Heap Sort#18

Draft
bluesign wants to merge 4 commits intogreen-goo-dao:mainfrom
bluesign:main
Draft

WIP: Heap Sort#18
bluesign wants to merge 4 commits intogreen-goo-dao:mainfrom
bluesign:main

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