Re: Suggestion: specify what value should be used when an ephemeron is used as a weak box
Daphne Preston-Kendal 26 Sep 2024 18:32 UTC
On 26 Sep 2024, at 20:27, Marc Nieper-Wißkirchen <xxxxxx@gmail.com> wrote:
> Given the example of a weak hash table, when an existing association is updated, why do we want to add the inefficiency of replacing the whole ephemeron/weak pair when a simple mutation would work?
I don’t accept that it would be more inefficient in all cases. Under the optimization I suggest, replacing a potentially-circular ephemeron with a weak pair (whose value is of a type that can’t possibly link back to the key) would probably be a performance win. But without benchmarks we are speculating here, and this has nothing to do with my original suggestion, which is about using them as weak boxes, not as weak pairs.
> Another example I have in mind is a linked list of weak pairs (say, as part of a cache structure) modelling a list of weak keys.
Don’t you also need a strong pair to maintain the link to the next weak pair in that case? Otherwise, one weak pair being broken will cause the entire rest of the list to be lost.
Daphne