Has AA a bad implementation?

frame frame86 at live.com
Sat Feb 13 03:43:13 UTC 2021


On Friday, 12 February 2021 at 22:23:45 UTC, Steven Schveighoffer 
wrote:
> On 2/12/21 4:56 PM, frame wrote:

> The intent of clear is to reset the array so I DON'T have to 
> reallocate the bucket array.

I know.

> Other types in Phobos treat clear the same way (e.g. appender).

Is this really the same? This looks more like clearing in 
Appender:

> void clear() @trusted pure nothrow
> {
>    if (_data)
>    {
>        _data.arr = _data.arr.ptr[0 .. 0];
>    }
> }

> I think you are just misunderstanding what clear is for. It 
> means, reset but don't deallocate.

So it should be called reset() or blank() then.

> I'm not really sure if it's a problem, just a weird 
> inconsistency. Technically nobody should care about the bucket 
> array, it's an implementation detail.

I just don't like a widely used but leaky standard element that 
imply it does not. Better correct than error. But ok, it's not a 
big deal. Should be maybe documented that null can be useful.



More information about the Digitalmars-d mailing list