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

feat: immutable sort #255

Open
hg-pyun opened this issue Mar 11, 2024 · 5 comments
Open

feat: immutable sort #255

hg-pyun opened this issue Mar 11, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@hg-pyun
Copy link
Collaborator

hg-pyun commented Mar 11, 2024

Suggestion

Since the sort of an array refers to a reference, the original array changes. Usually, functional programming treats an array in an immutable way.

The sort function of fxts does not support immutable.

As 'toSorted' is added as a new method of array, it would be good to support 'toSorted' in fxts. After implementing internally, if 'native to Sorted' compatibility is guaranteed, it would be better to replace the internal implementation then.

Reference

@hg-pyun hg-pyun added the enhancement New feature or request label Mar 11, 2024
@hg-pyun hg-pyun self-assigned this Mar 12, 2024
@hg-pyun
Copy link
Collaborator Author

hg-pyun commented Mar 12, 2024

I will take it.

@jin-Pro
Copy link

jin-Pro commented Oct 22, 2024

I want to develop a toSorted method.

I think I should develop it using the heap data structure.

Do you agree with this idea?

@hg-pyun
Copy link
Collaborator Author

hg-pyun commented Oct 26, 2024

Sorry for the late reply. Due to personal work, I’m unable to continue with this ticket at the moment. If it’s alright with you, could you take over? Please include @hg-pyun and @ppeeou in the code review. Thank you.

@ppeeou
Copy link
Member

ppeeou commented Oct 27, 2024

@jin-Pro

Thank you for your interest in fxts.

I’m curious about your reason for choosing a heap. A heap is an unstable sort, meaning that if there are elements with the same value, their initial order may not be preserved after sorting.

For the toSorted spec, please refer to the polyfill in this link.

The sort method uses Array.prototype.sort here, which is known to be implemented with timSort.

How about implementing it with timSort?

@jin-Pro
Copy link

jin-Pro commented Nov 24, 2024

I'm sorry to my answer is too late.

I �failed to consider heap is an unstable sort.
I thought that if I use min heap, It will operate lazily by executing operations when extracting the value of the iterator.

but, I agree with your suggestion of timSort.
This is because Array.prototype.toSorted and Array.prototype.sort use timSort.
so, I will use 'timSort' when I develop 'toSorted'.

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants