Thread overview
is Associative Arrays good for integer type as key?
Nov 15, 2006
%u
Nov 15, 2006
%u
Nov 17, 2006
Stewart Gordon
Nov 27, 2006
Steve Horne
November 15, 2006
such as

int[short] hashtable;

where KeyType = short, and ValueType = int?

will this work? and as optimized (memory-wise, and CPU-wise)?

Thanks in advance for your conmments.
November 15, 2006
And what's the internal implementation of Associative Arrays for things like:

int[short] hashtable;

Is it a tree, or raw array with linked-list?
November 15, 2006
"%u" <newbie@dd.com> wrote in message news:ejdukb$otl$1@digitaldaemon.com...
> And what's the internal implementation of Associative Arrays for things like:
>
> int[short] hashtable;
>
> Is it a tree, or raw array with linked-list?

All associative arrays in D, no matter the key or value types, are implemented as a closed-addressed hash table with binary trees at each hash table location to resolve collisions (as opposed to the more common linked-list at each location).  If you'd like, you can see how AAs are implemented in /dmd/src/phobos/internal/aaA.d, and you can see how all the hashes are computed for the various types in the phobos/typeinfo directory. For shorts, the hash is simply the value itself.


November 17, 2006
%u wrote:
> such as
> 
> int[short] hashtable;
> 
> where KeyType = short, and ValueType = int?
> 
> will this work?

Have you tried it?  Does it work?

> and as optimized (memory-wise, and CPU-wise)?

Depends on how you're using it.

Stewart.

-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d- s:-@ C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++++ h-- r-- !y
------END GEEK CODE BLOCK------

My e-mail is valid but not my primary mailbox.  Please keep replies on the 'group where everyone may benefit.
November 27, 2006
On Wed, 15 Nov 2006 02:36:58 +0000 (UTC), %u <newbie@dd.com> wrote:

>such as
>
>int[short] hashtable;
>
>where KeyType = short, and ValueType = int?
>
>will this work? and as optimized (memory-wise, and CPU-wise)?
>
>Thanks in advance for your conmments.

Associative arrays are sometimes called sparse arrays. They can be good with integer indexes, if those indexes tend to be widely distributed, with lots of unused indexes in between.

-- 
Remove 'wants' and 'nospam' from e-mail.