Skip to content

Conversation

craigfe
Copy link

@craigfe craigfe commented May 5, 2021

This PR adds some functions that I found useful when porting https://github.com/backtracking/vector to use a nullable array internally.

I haven't yet added tests for these functions beyond just exercising them from within vector (and so some of them are very likely broken), but I'm happy to do so if you think these functions are a fit for the API. Just let me know :-)

@craigfe craigfe force-pushed the add-various-functions branch from cfd4f8c to 0874331 Compare May 5, 2021 11:00
[to_start] and [len] do not designate a valid subarray of [to].
*)

val of_array : 'a array -> 'a t
Copy link
Author

Choose a reason for hiding this comment

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

These functions might want to be called of_some_array / of_some_list or some such.

Comment on lines +244 to +245
(* Include an extra element at the start of the new array,
then set it to [null]. *)
Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure whether this trick is actually worthwhile.

Comment on lines +150 to +152
Array.init (n+1) (function
| 0 -> (null:elt)
| i -> (Obj.magic (f (i-1)) : elt))
Copy link
Author

Choose a reason for hiding this comment

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

(I'd guess it's more efficient to first create a null array and then set the elements, vs. allocating a closure.)

The `(alias ...)` field on rules requires at least Dune lang 2.0.
@craigfe
Copy link
Author

craigfe commented Sep 3, 2021

Gentle ping @chambart, if you have any spare cycles for a review 🙂

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.

1 participant