I submitted my container library to code.dlang.org
Martin Nowak via Digitalmars-d
digitalmars-d at puremagic.com
Sun Mar 29 15:32:12 PDT 2015
On 03/29/2015 05:19 PM, w0rp wrote:
> 4. I ended up writing my own library hashmap, which when I tested ages
> ago competed with the standard associative array in terms of
> performance. This allows me to mark many things @safe pure nothrow.
Always use open addressing when implementing a hash table.
> Also, I was able to implement setDefault in a hopefully efficient
> manner. I have tried to push setDefault as an awesome thing a few times,
> but I've never been able to explain why it's good eloquently.
I guess that's the counterpart to `get(key, default)` that also inserts
the default value. That's a very much needed primitive for our AA,
because currently you end up doing at least 1 unnecessary lookup.
Often I even write this.
auto p = key in aa;
if (p is null)
aa[key] = default;
p = key in aa;
It's called getOrElseUpdate in Scala, but I'd prefer getOrSet.
More information about the Digitalmars-d