Associative array and ranges

Jonathan M Davis jmdavisProg at gmx.com
Wed Feb 2 08:26:48 PST 2011


On Wednesday 02 February 2011 02:11:34 Nrgyzer 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!

If you know which keys you want, then just have a list of those and iterate over 
them, and then use them to grab their corresponding values from the AA on each 
iteration. As far as iterating over the AA itself goes, either you're iterating 
over the keys, the values, or both. You can't iterate over just part of it. I 
haven't a clue how such a thing would be implemented anyway. But there's nothing 
to stop you from iterating over a list of the keys that you want and then using 
those keys to grab the values from the AA.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list