[Issue 17526] Add a set method for AA
    via Digitalmars-d-bugs 
    digitalmars-d-bugs at puremagic.com
       
    Fri Jul  7 11:13:26 PDT 2017
    
    
  
https://issues.dlang.org/show_bug.cgi?id=17526
--- Comment #5 from Vladimir Panteleev <dlang-bugzilla at thecybershadow.net> ---
BTW, the performance use case of the proposed set method (which I called
getOrAdd in my hashmap implementation):
struct S { int i, j, k, l, m; /* etc. */ }
S[int] aa;
// The goal is to increment aa[x].k
// If aa[x] doesn't exist, initialize it with S.init
// Currently, you have to do this:
if (auto p = x in aa)
    (*p).k++;
else
{
    S s;
    s.k = 1;
    aa[x] = s;  // Wasteful - double lookup
}
--
    
    
More information about the Digitalmars-d-bugs
mailing list