digitalmars.D.learn - How to search for an element in the array. D2 phobos.
- Eldar Insafutdinov (13/13) Jul 12 2009 I am a little bit confused with a simple operation of searching in the a...
- bearophile (5/6) Jul 12 2009 Yes, it's too much complex. It tries to do many different things in the ...
- Bill Baxter (12/16) Jul 12 2009 ost efficient way possible, the result is a high complexity in usage. Th...
- Daniel Keep (6/17) Jul 12 2009 That said, find is too complex for his purposes. Amazingly, Phobos
I am a little bit confused with a simple operation of searching in the array with D2-phobos. With tango I used to use: size_t find( Elem[] buf, Elem pat, Pred2E pred = Pred2E.init ); Performs a linear scan of buf from [0 .. buf.length), returning the index of the first element matching pat, or buf.length if no match was found. Comparisons will be performed using the supplied predicate or '==' if none is supplied. I tried std.algorithm.find: class Node { ... } Node[] v; Node node; ... int pos = find(v, node); I get this error: /home/eldar/d/bin/../src/phobos/std/algorithm.d(1617): Error: no property 'empty' for type 'model_d2.Node' I think I completely misunderstood how to use it. Many thanks in advance, Eldar.
Jul 12 2009
Eldar Insafutdinov:I think I completely misunderstood how to use it.Yes, it's too much complex. It tries to do many different things in the most efficient way possible, the result is a high complexity in usage. That's one of the faults of Andrei's code, it's not tested by letting average coders use it. A solution for this problem is to offer simple functions (like you can find in Tango. In my dlibs the situation is intermediate, I think) with a simple API for the most common purposes. Bye, bearophile
Jul 12 2009
On Sun, Jul 12, 2009 at 3:56 PM, bearophile<bearophileHUGS lycos.com> wrote= :Eldar Insafutdinov:ost efficient way possible, the result is a high complexity in usage. That'= s one of the faults of Andrei's code, it's not tested by letting =A0average= coders use it.I think I completely misunderstood how to use it.Yes, it's too much complex. It tries to do many different things in the m=A solution for this problem is to offer simple functions (like you can fi=nd in Tango. In my dlibs the situation is intermediate, I think) with a sim= ple API for the most common purposes. Isn't that a matter of built-in arrays not yet sporting the range interface= ? I assume if .empty is part of the range interface then arrays are supposed to support it. --bb
Jul 12 2009
bearophile wrote:Eldar Insafutdinov:It should work. Taken from the algorithm docs:I think I completely misunderstood how to use it.Yes, it's too much complex. It tries to do many different things in the most efficient way possible, the result is a high complexity in usage. That's one of the faults of Andrei's code, it's not tested by letting average coders use it. A solution for this problem is to offer simple functions (like you can find in Tango. In my dlibs the situation is intermediate, I think) with a simple API for the most common purposes. Bye, bearophileExample:That said, find is too complex for his purposes. Amazingly, Phobos still appears to lack a basic indexOf function. Phobos2: can build a working sentient AI that can feel love up from individual atoms, but can't find the index of an array element. :Pint[] a = [ 1, 4, 2, 3 ]; assert(find(a, 4) == [ 4, 2, 3 ]);
Jul 12 2009