Thread overview | |||||
---|---|---|---|---|---|
|
August 11, 2015 countUntil for SortedRange | ||||
---|---|---|---|---|
| ||||
Hi. Basic question: suppose I have a SortedRange and want to find the index of the first entry of an array of structs matching a needle struct. What's the best way to do that? It's not clear that countUntil treats a SortedRange specially. I could get the lowerBound and then length or walkLength (can't remember which applies). But I figure there must be a better way. Thanks. Laeeth. |
August 11, 2015 Re: countUntil for SortedRange | ||||
---|---|---|---|---|
| ||||
Posted in reply to Laeeth Isharc | On Tuesday, 11 August 2015 at 19:30:02 UTC, Laeeth Isharc wrote:
> Hi.
>
> Basic question: suppose I have a SortedRange and want to find the index of the first entry of an array of structs matching a needle struct.
>
> What's the best way to do that? It's not clear that countUntil treats a SortedRange specially.
>
> I could get the lowerBound and then length or walkLength (can't remember which applies).
>
> But I figure there must be a better way.
>
> Thanks.
>
>
> Laeeth.
Yeah, I was wrong when I said it was treated specially. lowerBound followed by length should do it without any notable inefficiencies. I guess you could wrap it as `sortedCountUntil` for convenience if you like.
|
August 12, 2015 Re: countUntil for SortedRange | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Colvin | On Tuesday, 11 August 2015 at 21:38:49 UTC, John Colvin wrote:
> On Tuesday, 11 August 2015 at 19:30:02 UTC, Laeeth Isharc wrote:
>> Hi.
>>
>> Basic question: suppose I have a SortedRange and want to find the index of the first entry of an array of structs matching a needle struct.
>>
>> What's the best way to do that? It's not clear that countUntil treats a SortedRange specially.
>>
>> I could get the lowerBound and then length or walkLength (can't remember which applies).
>>
>> But I figure there must be a better way.
>>
>> Thanks.
>>
>>
>> Laeeth.
>
> Yeah, I was wrong when I said it was treated specially. lowerBound followed by length should do it without any notable inefficiencies. I guess you could wrap it as `sortedCountUntil` for convenience if you like.
Thanks, John.
Laeeth
|
Copyright © 1999-2021 by the D Language Foundation