-
Notifications
You must be signed in to change notification settings - Fork 106
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
Make Set.to_array use Enum instead of Bigarray #724
Make Set.to_array use Enum instead of Bigarray #724
Conversation
7097c4f
to
522aa3c
Compare
You meant DynArray rather than BigArray. Could you please compare with a third implementation that would (1) compute the size of the set, (2) allocate an array of the right size and (3) iterate on the set again to define elements. |
522aa3c
to
b10fc08
Compare
I considered this at first, but I do not know how to allocate an uninitialised array, and I thought using |
Well you can ask the set for an element, with I think on the contrary that |
This breaks the dependency Set -> Dynarray -> Int. A quick benchmark also shows that the new function is approximately twice as fast and can avoid Out_of_memory.
b10fc08
to
4e5dbab
Compare
It is approximately twice as fast indeed. I updated and rebased. |
| Node (_, e, _, _) -> | ||
let arr = Array.make (cardinal s) e in | ||
let i = ref 0 in | ||
iter (fun x -> Array.unsafe_set arr (!i) x; incr i) s; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is the recommended style to write (!i)
instead of !i
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong preference, do as you think is best.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep it this way then, unless someone else objects. Are you ok to merge ?
You should add a Changes entry, otherwise this seems ready to go. One thing though, it would be nice if we had a couple tests for this function. |
This breaks the dependency Set -> Bigarray -> Int. A quick benchmark
also shows that the new function has comparable performances and can avoid
Out_of_memory.
This is required for having
Int.Set
as an instantion ofSet
, see #712.