[h2o]
July 4th, 2007, 09:48 AM
I have a multidimensional vector which contain indices (it is a subset of a larger multidimensional vector).
A = [
[1, 3, 5],
[4, 6],
[1, 2, 5, 6]
]
I want to use these indices to index a 1-d array of 1/0:
B = [ 1 0 0 0 1 1 1 1 0 0 0 ...]
The goal is to get the number of 1's in the particular subset.
In this example I want:
sum = B[ (1,4,1) ] + B[ (1,4,2) ] + B[ (1,4,5) ] + ... + B[(5,6,5)] + B[ (5,6,6) ]
The size for array A is not known at compile time. It can have 1 to 4 rows where each row can have an arbitrarly number of elements.
How do I go about iterating over A to get the sum of B for my subset A?
I am using C++ with A being a *std::vector<int> and B a *bool.
A = [
[1, 3, 5],
[4, 6],
[1, 2, 5, 6]
]
I want to use these indices to index a 1-d array of 1/0:
B = [ 1 0 0 0 1 1 1 1 0 0 0 ...]
The goal is to get the number of 1's in the particular subset.
In this example I want:
sum = B[ (1,4,1) ] + B[ (1,4,2) ] + B[ (1,4,5) ] + ... + B[(5,6,5)] + B[ (5,6,6) ]
The size for array A is not known at compile time. It can have 1 to 4 rows where each row can have an arbitrarly number of elements.
How do I go about iterating over A to get the sum of B for my subset A?
I am using C++ with A being a *std::vector<int> and B a *bool.