cashew.utils.array 0.1a.2
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Sat Sep 16 13:13:26 PDT 2006
Reiner Pope wrote:
> 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.
Possibly true, so for now I took out some of the 'inout's.
>>> 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
So it does... although I could swear that it didn't behave right before. Ah well, it
works fine now.
Also I've written a new version of .unique(), in the process of which I've added a
.removeRange() function. A quick note on .removeRange() though: it mimics the slicing
logic of D arrays. So, foo.removeRange(1, 4) actually removes [1, 2, 3], not [1, 2, 3, 4].
-- Chris Nicholson-Sauls
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: array.d
Url: http://lists.puremagic.com/pipermail/digitalmars-d-announce/attachments/20060916/4834377d/attachment.txt
More information about the Digitalmars-d-announce
mailing list