cashew.utils.array 0.1a.2
Reiner Pope
reiner.pope at REMOVE.THIS.gmail.com
Thu Sep 14 13:19:44 PDT 2006
Chris Nicholson-Sauls wrote:
>
>
> Reiner Pope wrote:
>> Chris Nicholson-Sauls wrote:
>>
>>> I've been pushing for some array utilities to get into Phobos, yes,
>>> but in the meantime I updated the array module in my personal Cashew
>>> lib. Included in the updates are the rotl/rotr that I recall someone
>>> asking about. In the process I've discovered two bugs, as well: the
>>> behavior of 'is' versus '==' is incompatable if the operands are
>>> arrays, and DDoc for abbreviated function templates is borked. For
>>> an example of the latter, just look at Cashew's own docs.
>>>
>>> That said: if people think this is a decent collection, and Walter
>>> would take it, I would be willing to release it to public domain for
>>> Phobos' sake.
>>>
>>> The array module is attached, and the docs are at:
>>> http://www.codemeu.com:81/~pontiff/projects/cashew/doc/array.html
>>>
>>> -- Christopher Nicholson-Sauls
>>>
>> It looks good. Thanks for doing this.
>>
>> Some comments/questions:
>>
>> Why does indexOfSub have bale as 'inout', not simply 'in'?
>> Same question for fill
>
> Because I'm mildly paranoid and wanted to avoid memory allocation where
> I could. :) I do suppose it could safely be 'in' though.
>
Passing by 'inout' is probably less efficient and certainly doesn't save
any memory allocation. 'inout' is equivalent to passing a pointer to the
array reference, which itself contains a pointer to the data. The extra
level of indirection can only add computation time.
>> Also, couldn't you avoid the temporary in removeAll by doing this:
>> void removeAll (T) (inout T[] haystack, T needle)
>> {
>> size_t index = 0U;
>> size_t indices;
>>
>> while ((index = haystack.indexOf(needle, index)) != size_t.max) {
>> haystack.removeIndex(index);
>> }
>> }
>
> That's exactly how it was written (once I'd modified .indexOf) but it
> doesn't act quite right for some reason. Until I figure out what the
> bug is, I figured I could slap together a less pretty but working version.
This passes the unit tests, though.
Cheers,
Reiner
More information about the Digitalmars-d-announce
mailing list