R
RayLopez99
Recently I found that dictionaries cannot be used easily if a certain
format is not observed for the key rather than the value.
I had this dictionary:
Dictionary<Point, Rectangle> aDictionary = new Dictionary<Point,
Rectangle>();
then later, inside of a massive (million iteration) loop, I had this:
aRectangle = new Rectangle (i,j);
aDictionary.Add(new point(i,j), aRectangle);
After several hundred iterations, the program slowed down dramatically
on a fast PC. But, strangely, if I switched the value (here a
Rectangle type) and the key (here a Point), it worked fine (fast).
That is, this worked fast: aDictionary.Add(aRectangle, new point
(i,j)); //order reversed, and key is not created 'inline' or 'on the
fly'
Anybody observe this? I think it has to do with the fact a 'new' key
is being created everytime in the loop, rather than a 'new' value.
For some reason, because of the algorithm used for key pairs, keys
cannot easily be created 'behind the scenes'.
Or so it seems (to my mind's eye)
RL
format is not observed for the key rather than the value.
I had this dictionary:
Dictionary<Point, Rectangle> aDictionary = new Dictionary<Point,
Rectangle>();
then later, inside of a massive (million iteration) loop, I had this:
aRectangle = new Rectangle (i,j);
aDictionary.Add(new point(i,j), aRectangle);
After several hundred iterations, the program slowed down dramatically
on a fast PC. But, strangely, if I switched the value (here a
Rectangle type) and the key (here a Point), it worked fine (fast).
That is, this worked fast: aDictionary.Add(aRectangle, new point
(i,j)); //order reversed, and key is not created 'inline' or 'on the
fly'
Anybody observe this? I think it has to do with the fact a 'new' key
is being created everytime in the loop, rather than a 'new' value.
For some reason, because of the algorithm used for key pairs, keys
cannot easily be created 'behind the scenes'.
Or so it seems (to my mind's eye)
RL