-
Notifications
You must be signed in to change notification settings - Fork 17
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 slice method to array #287
Add slice method to array #287
Conversation
5458b81
to
e283b91
Compare
src/array.cpp
Outdated
@@ -48,6 +49,13 @@ namespace sparrow | |||
return array_element(*p_array, index); | |||
} | |||
|
|||
void array::slice(size_type start, size_type end) |
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 would prefer slice to return a array which is a view to the original array.
ie auto sliced_arr = arr.slice(start, end);
With the view function of the arrow_proxy it should be possible to create a cheap "view-copy" of the array and than change the offset and size there
Or maybe we should be explicit
auto sliced_arr = arr.slice(start, end); #deep copy
auto sliced_arr = arr.slice_view(start, end); #view
arr.slice_inplace(start, end) #modify
(not sure if the last one is needed or a good idea as mutating an array should be avoided if possible,imho)
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.
Now we have arr.slice and arr.slice_view
test/test_array.cpp
Outdated
ar.slice(2, 8); | ||
|
||
REQUIRE_EQ(ar.size(), 6); | ||
CHECK_EQ(std::get<const_reference>(ar[0]), make_nullable<scalar_value_type>(2)); |
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.
we should add this to the consistency test instead of implementing this by hand
69e5ac8
to
c6174cf
Compare
src/array.cpp
Outdated
ArrowArray* ar = new ArrowArray; | ||
*ar = arrow_proxy_copy.array(); | ||
ar->offset = static_cast<int64_t>(start); | ||
ar->length = static_cast<int64_t>(end - start); |
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.
This method creates a memory leak, since as
and ar
will not be deleted. A way to fix this would be to allocate these structures on the stack and move them in the returned array. The release methods should be set to empty methods to avoid destruciton of the data when the view is destroyed.
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.
You are right. But we can't set the release to null as it means that the array is invalid.
I have to create another release callback which don't delete the buffers
18e747d
to
2dc35be
Compare
No description provided.