Revamping associative arrays
Steven Schveighoffer
schveiguy at yahoo.com
Tue Oct 20 06:04:24 PDT 2009
On Sat, 17 Oct 2009 14:28:51 -0400, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:
> Associative arrays are today quite problematic because they don't offer
> any true iteration. Furthermore, the .keys and .values properties create
> new arrays, which is wasteful.
>
> Another issue with associative arrays is that ++a[k] is hacked, which
> reflects a grave language limitation. That needs to be replaced with a
> true facility.
>
> Any other issues with AAs that you want to see fixed, and ideas guiding
> a redesign?
Do not require opCmp for AAs. There are some good hashmap implementations
do not require using a tree for collisions. This would also eliminate at
least one pointer in the element struct.
It also causes some problems with using arbitrary classes as keys. It is
easy to define a default hash and default opEquals for a class, but it is
difficult to define a default opCmp. In fact, the default opCmp in object
simply throws an exception, making it a nuisance to have the compiler
allow using a class as a key, and then throwing an exception at runtime
when you use it.
Removing the requirement for opCmp would also eliminate the requirement
for opCmp to be in object (it currently by default throws an exception),
so it could be in an interface instead.
-Steve
More information about the Digitalmars-d
mailing list