std way to remove multiple indices from an array at once
aliak
something at something.com
Thu Dec 21 13:57:55 UTC 2017
On Thursday, 21 December 2017 at 00:52:29 UTC, Nicholas Wilson
wrote:
> On Thursday, 21 December 2017 at 00:23:08 UTC, Steven
> Schveighoffer wrote:
>>
>> I'm assuming here indices is sorted? Because it appears you
>> expect that in your code. However, I'm going to assume it
>> isn't sorted at first.
>>
>> auto sortedIdxs = indices.assumeSorted; // also could be =
>>
>> It's not going to be as good as hand-written code, complexity
>> wise, but it's definitely shorter to write :)
>>
>> -Steve
> If indices is sorted with no duplicates and random access then
> you can do it in linear time.
Ah yes, I guess sorted and unique as well would be the expected
input. But nice to see the handling of non-sorted indices.
I tried to search for an assumeUnique function as well (the
assumeSorted one was nice to see) but it's not what I thought
it'd be - seems to be more of an assumeUnaliased. And I guess
there's no assumeUniqueElements.
And the filter approach is nice! :) (just need to account for the
last ii++ (when filter comes back in I think one case would be ii
== indices.length and you'd get a range error)
Thanks for the feedback!
More information about the Digitalmars-d-learn
mailing list