Is logical subsetting of an array possible ?

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 14 06:50:42 PDT 2016


On 7/14/16 7:03 AM, Sahil wrote:
> On Thursday, 14 July 2016 at 10:51:33 UTC, Nicholas Wilson wrote:
>> On Thursday, 14 July 2016 at 10:43:12 UTC, Sahil wrote:
>>> This is with reference to documentation about use of array in D
>>> (https://dlang.org/spec/arrays.html#array-setting).
>
>> easily. The function you are looking for is called 'filter'
>>
>> import std.algorithm;
>> import std.array;
>> int[] a = [ 4,5,8,1,3,2,9,10];
>> auto b = a.filter!(e => e>3).array; //b contains the elements 4,5,8,9,10
>
> Thanks for a prompt reply. This gives me confidence to explore D for
> faster implementations in data mining.
> Thanks a lot :-)

Please be aware, however, that filter is going to still iterate the 
array. So the subset operation may not be as performant as a subset 
operation and data type that is written to deal with these kinds of 
operations.

-Steve


More information about the Digitalmars-d-learn mailing list