Question on Count();

Can you count based on a selection of keys?

For instance:
Code:
string [int][string][string] Stuff;
Stuff [0, dog, cat] = good;
Stuff [1, dog, cat] = good;
Stuff [2, dog, bird] = good;

If I count(Stuff), I'd get 3. If I count(Stuff[0-2]), I get 1. What I want to do is count(Stuff[dog][cat]) and get 2, but I don't think this is possible.

Okay, after playing with it more it seems count(Stuff) only counts the first set of keys. So, if I had [boolean] instead of [int] in the front then I'd only get 2 when counting. This makes me think there is a way I can count a specific key(s)... I just can't figure out how :(
 

jasonharper

Developer
count() of a multidimensional map requires you to explicitly specify some number of keys, starting from the left, and gives you the count of distinct values of the first (leftmost) key that you didn't specify. If you want to count values of that int key, for given values of the other two keys, then it needs to be the rightmost key, not the leftmost. If you can't structure the map in that way for some reason, then you'd have to iterate over the whole thing and count matching values.
 
Top