Associative Arrays in the data segment

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 10 06:04:43 PDT 2015


On Fri, 10 Apr 2015 17:54:47 +1000, Daniel Murphy wrote:

> One long-standing issue with AAs has been that you can't generate
> constant ones at compile time and access them at run-time.  Workarounds
> are available, like initializing them in static this or using horribly
> inefficient enum AAs.
> 
> I've opened https://github.com/D-Programming-Language/dmd/pull/4571
> which allows code like this:
> 
> immutable int[int] aa = [1 : 7, 3 : 2];
> 
> void main()
> {
>     assert(aa[1] == 7);
>     assert(aa[3] == 2);
> }
> 
> It only works with integral types of at most 32-bits at the moment, but
> most built-in types are fairly easy to support.  The downside is
> requires re-implementing druntime's AA and hashing algorithms in the
> compiler, and keeping them in sync when either changes.
> 
> I think it's worthwhile, even if only integral and string keys are
> supported for now.  That would cover 99% of my AA use.
> 
> Is anybody else interested in seeing this in the next release?

this has a majour drawback, methinks: an inability to change AA 
implementation without fixing the compiler too. i.e. i can't no longer to 
simply rewrite the relevant parts of druntime (change hashing function, 
for example) and be happy.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20150410/348d5beb/attachment.sig>


More information about the Digitalmars-d mailing list