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 slice method to array #287

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Alex-PLACET
Copy link
Collaborator

No description provided.

@Alex-PLACET Alex-PLACET marked this pull request as draft November 14, 2024 14:15
@@ -48,6 +49,13 @@ namespace sparrow
return array_element(*p_array, index);
}

void array::slice(size_type start, size_type end)
Copy link
Collaborator

@DerThorsten DerThorsten Nov 14, 2024

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)

ar.slice(2, 8);

REQUIRE_EQ(ar.size(), 6);
CHECK_EQ(std::get<const_reference>(ar[0]), make_nullable<scalar_value_type>(2));
Copy link
Collaborator

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

@DerThorsten DerThorsten mentioned this pull request Nov 18, 2024
18 tasks
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.

2 participants