Has AA a bad implementation?

Steven Schveighoffer schveiguy at gmail.com
Sat Feb 13 01:01:28 UTC 2021


On 2/12/21 6:13 PM, Joseph Rushton Wakeling wrote:
> On Friday, 12 February 2021 at 22:23:45 UTC, Steven Schveighoffer wrote:
>> Note, I thought rehash would shrink the bucket array down, but it 
>> looks like it ignores that when the AA is empty. That seems like an 
>> omission.
> 
> Do we necessarily want that shrinkage by default?  If an AA has had a 
> certain size in the past, and then is cleared, it seems likely that the 
> typical use case is that it will fill up to a similar size again.

The shrinkage happens by default if you remove an element and it goes 
below a threshold.

It does not shrink on clear (on purpose, for the reason you say).

> 
> For comparison, does `rehash` shrink the bucket array when the AA is 
> non-empty but much, much smaller than the bucket array?

Yes. If it has one element, then it will resize the array.

> I don't object to the possibility to shrink the bucket array where 
> possible but it should probably require an explicit and unambiguous 
> request.

I think it already does shrink for a rehash. It's just set up to not 
shrink when the AA is "empty". 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.

-Steve


More information about the Digitalmars-d mailing list