Multiple Key Maps

Next time you find yourself writing "Dictionary<..., Dictionary<..." stop and ask yourself why are you not using Maps!

Use case

I want to store a collection of entities in a 3D space and be able to look them up very fast by x, y, and z coordinates. For clarity, let's assume the coordinate variable types are XCoor, YCoor, and ZCoor for x, y, and z respectively. I could use a Dictionary:

Dictionary<XCoor, Dictionary<YCoor, Dictionary<ZCoor, Entity>>> _entities;
That looks so ugly. Seriously. Or I could use a Map:

Map<XCoor, YCoor, ZCoor, Entity> _entities;

Last edited Apr 19, 2010 at 10:33 PM by payonel, version 3


No comments yet.