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

Add unsafeFrom sortedArray initializer? #34

Open
Swoorup opened this issue May 12, 2023 · 3 comments
Open

Add unsafeFrom sortedArray initializer? #34

Swoorup opened this issue May 12, 2023 · 3 comments

Comments

@Swoorup
Copy link
Contributor

Swoorup commented May 12, 2023

When working with web workers, all methods are stripped away during transfer. Is there a way to initialize the sortedArray at the other end, without the end to sort it again? https://github.com/zandaqo/structurae/blob/master/sorted-array.ts#L30

@Swoorup
Copy link
Contributor Author

Swoorup commented May 12, 2023

Looks like you could do.

new SortedArray(...[10,9])`

Is that the preferred solution?

@zandaqo
Copy link
Owner

zandaqo commented May 12, 2023

const sorted = new SortedArray(...array)

Just use the constructor, it doesn't trigger sorting.

EDIT:

Is that the preferred solution?

Yes, at least for now, I have to test how much/and if spreading adds overhead and whether it's worth having a special logic for this situation.

@Swoorup
Copy link
Contributor Author

Swoorup commented May 12, 2023

I heavily use web workers for short bursts of computation,

I could use the native array methods, but the methods in this library are quite useful 😄 to pass up. Thanks for the library.

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

No branches or pull requests

2 participants