Associative array and ranges

Steven Schveighoffer schveiguy at yahoo.com
Thu Feb 3 05:15:31 PST 2011


On Wed, 02 Feb 2011 05:11:34 -0500, Nrgyzer <nrgyzer at gmail.com> wrote:

> Hey guys,
>
> I have an associative array like this: T[hash_t] myArray; (T means
> the template type).
>
> Is there any chance to cast/convert this array to an indexed array or
> is it possible to iterate over specific indices? I know that there is
> something like next() for the foreach-statement but when the array
> contains some thousand instances and I only want iterate over (for
> example) 5 elements I think that's the wrong way. It's for a game and
> I think every next()-call influences the fps.
>
> I hope there is any solution for my problem :) - Thanks!

dcollections contains more functionality than builtin AAs.  The equivalent  
type in dcollections would be HashMap!(hash_t, T):

http://www.dsource.org/projects/dcollections

You might find this helps solve some problems.  I don't really understand  
what you are asking for, if you want to iterate over "specific" indexes,  
wouldn't you just use those indexes to look up the elements you desire?   
i.e.:

foreach(i; specific_indexes) // specific_indexes is an array of the  
indexes you wish to use
{
    auto elem = myArray[i];
    ...
}

-Steve


More information about the Digitalmars-d-learn mailing list