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

RFC: Implementation of deleteat! (Fixes #5118) #5176

Merged
merged 2 commits into from
Jan 22, 2014
Merged

Conversation

kmsquire
Copy link
Member

As noted in #5118, delindex! was previously proposed but never implemented. Here is an implementation delindex! deleteat! for

  • single indexes
  • Range1
  • general iterable of indices (must be sorted)

delindex! deleteat! is more efficient than splice! when the items being removed from the collection are not needed and returning them is costly.

This PR also changes/fixes the return type of one of the splice! implementations for BitArrays, which was returning the modified array instead of the spliced-out region. cc:@carlobaldassi

Edit: changed name from delindex! to deleteat!.

@StefanKarpinski
Copy link
Sponsor Member

How about calling this operation deleteat! instead of delindex. The former name seems to have more historical precedent.

@StefanKarpinski
Copy link
Sponsor Member

#bikeshed

@kmsquire
Copy link
Member Author

After thinking about it, I kind of like the parallels with getindex and setindex!.

@kmsquire
Copy link
Member Author

If we had deleteat!, would we also want insertat!? This is already handled by splice!, of course, except that insertat! could return the modified vector...

Like all of these things, it's easy to get carried away. delindex (or deleteat), at least, I've had a need for.

@ivarne
Copy link
Sponsor Member

ivarne commented Dec 16, 2013

You should document the need for a sorted iterable.

Why only sorted anyway? I see that it is good for performance, but could we have a slow fallback instead of an error?

@StefanKarpinski
Copy link
Sponsor Member

The abbreviated del just doesn't sit well with me. We've expunged almost all other abbreviations in collection operations. I'm also not sure that analogy to getindex and setindex! is very important – because no one every uses those names except when they want to overload x[i] and x[i] = v.

@kmsquire
Copy link
Member Author

Why only sorted anyway? I see that it is good for performance, but could we have a slow fallback instead of an error?

This was the easiest way to implement the function without worrying about explicitly storing/copying/modifying the iterable. That version currently starts to modify the array immediately on iteration through the indices, so if something is out of order, it's not possible to undo the changes already made.

I don't think it's possible to have a slow fallback without considerably slowing down the fast version. If we want a version which checks the input order, we might as well always copy/collect and sort it and get rid of this version.

It does need documentation, though, if it doesn't change.

@kmsquire
Copy link
Member Author

The abbreviated del just doesn't sit well with me. We've expunged almost all other abbreviations in collection operations.

Just so I'm clear, it's the del at the beginning of delindex! you're reacting to, not that someone suggested using del, right?

I'm also not sure that analogy to getindex and setindex! is very important – because no one every uses those names except when they want to overload x[i] and x[i] = v.

Okay, I can certainly change it to deleteat!.

@StefanKarpinski
Copy link
Sponsor Member

Right, it's the del at the beginning that rubs me a bit wrong. I think deleteat! feels much better.

@JeffBezanson
Copy link
Sponsor Member

This strikes me as a lot of repeated code from splice!.

@kmsquire
Copy link
Member Author

I refactored one of the BitArray versions, but the rest didn't jump out as
quickly. But I'll take a look.

On Monday, December 16, 2013, Jeff Bezanson wrote:

This strikes me as a lot of repeated code from splice!.


Reply to this email directly or view it on GitHubhttps://github.com//pull/5176#issuecomment-30725050
.

@kmsquire
Copy link
Member Author

Okay, factored out common code between deleteat! and splice!.

@StefanKarpinski
Copy link
Sponsor Member

bump. @JeffBezanson, @ViralBShah? thoughts on this operation?

@StefanKarpinski
Copy link
Sponsor Member

I'm cool with this and it is still mergeable.

StefanKarpinski added a commit that referenced this pull request Jan 22, 2014
Implementation of deleteat! (Fixes #5118)
@StefanKarpinski StefanKarpinski merged commit 7b82845 into master Jan 22, 2014
@StefanKarpinski StefanKarpinski deleted the kms/delindex branch January 22, 2014 23:56
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.

4 participants