Creating an array of user-defined structs
Mike Parker via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Aug 22 02:18:40 PDT 2016
On Monday, 22 August 2016 at 07:00:23 UTC, brian wrote:
>
> That's a terribly confusing naming convention for beginners
> then! :P
> Is this D-specific terminology, or is this a more general
> convention that AA are not actually arrays?
> This might help my understanding of when to use or not use one
> or the other. :)
AA is an existing term and the concept is not specific to D (see
the Wikipedia article [1]). Several other languages have them.
An AA is quite a distinct data structure from an array. Whereas
arrays hold their items directly and tend to be laid out
sequentially in memory (though they don't have to be), AAs do not
and are not -- they might have linked lists, red-black trees or
other data structures holding the items under the hood, all
requiring the allocation of special nodes to associate meta data
with each item. Arrays are indexed with sequential integers, AAs
can be indexed with any properly configured key. It's only the
read/write syntax in D that's similar, i.e. foo[key], though it
didn't have to be that way. Take the [] syntax away from an AA
and you might end up with something like the Java
HashMap/HashTable or the C++ std::unordered_map. The name almost
certainly derives from the [] syntax.
Because AAs and arrays distinct data structures (there are things
you can do with one, but not the other), it's important to
distinguish them in conversation.
[1] https://en.wikipedia.org/wiki/Associative_array
More information about the Digitalmars-d-learn
mailing list