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 Belt_Array.partition #2825

Merged
merged 3 commits into from
May 23, 2018
Merged

Conversation

mikaelbr
Copy link
Contributor

This intends to fix #2753.

I've tried do to an implementation of Array.partition using the same style as the existing file (with unsafe set/get and refs). I tried multiple solutions for implementing partition, trying to make it efficient in space and time (insert tardis joke), but I didn't see a way of reducing it.

I've seen some other implementations as well, and they all do it in like 3-4 loops. So as far as I can think, this is as good as it gets? If anyone has any ideas, please let me know and I'll try to fix them.

Also please let me know if there is anything I can change with this PR.

)
done;
let a1 = slice a1 ~offset:0 ~len:!i in
let a2 = slice a2 ~offset:0 ~len:!j in
Copy link
Member

Choose a reason for hiding this comment

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

instead of doing another copy using slice, would set the length (using the js trick) directly help?

Copy link
Contributor Author

@mikaelbr mikaelbr May 23, 2018

Choose a reason for hiding this comment

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

Ah. I thought the same, and was looking for a way of doing this in OCaml, but couldn't find any. Could you point me in the right direction? Use external?

I see there's a truncateToLengthUnsafe. Didn't catch that. Updating now

let a2 = makeUninitializedUnsafe l in
for ii = 0 to l - 1 do
let v = getUnsafe a ii in
if f v then (
Copy link
Member

Choose a reason for hiding this comment

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

This introduced a currying in the loop, can you rename partition into partitionU and call f v [@bs] here (you can check other examples)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also see I've messed up the order of the arguments. Guess it's intended to use with e.g. fast pipe. I've updated this and the currying now. Does it look OK?

@mikaelbr
Copy link
Contributor Author

@bobzhang Thanks for the feedback. Did some changes now

@bobzhang
Copy link
Member

@mikaelbr looks great, thanks

@bobzhang bobzhang merged commit 33c5320 into rescript-lang:master May 23, 2018
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.

[Belt] Array.partition
3 participants