digitalmars.D.learn - is Associative Arrays good for integer type as key?
- %u (5/5) Nov 14 2006 such as
- %u (3/3) Nov 14 2006 And what's the internal implementation of Associative Arrays for things ...
- Jarrett Billingsley (8/12) Nov 14 2006 All associative arrays in D, no matter the key or value types, are
- Stewart Gordon (12/20) Nov 17 2006 Depends on how you're using it.
- Steve Horne (6/11) Nov 26 2006 Associative arrays are sometimes called sparse arrays. They can be
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.
Nov 14 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?
Nov 14 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.
Nov 14 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.
Nov 17 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.
Nov 26 2006