I have four group of data:
//group 1
2 2 6
2 2 7
2 3 5
2 3 6
2 3 7
3 2 5
3 2 6
3 2 7
3 3 4
3 3 5
3 3 6
3 3 7
...
...
7 2 2
7 2 3
7 2 5
7 2 7
7 3 2
7 5 2
7 6 2
//group 2
2 2 2
2 2 3
2 2 4
2 2 5
2 3 2
2 3 3
3 3 2
3 3 3
3 4 2
...
...
5 2 2
//group 3
2 4
2 5
3 3
3 4
3 5
3 6
...
...
7 2
//group 4
6
7
8
And what I want to do is for given input number(s), give all the possible results.
A example might help to explain what I want to do:
Say input is 7, then the output should be the following:
from group 1
7 2 2
7 2 3
7 2 5
7 2 7
7 3 2
7 5 2
7 6 2
from group 2
//nothing
from group 3
7 2
from group 4
7
Then I add second input 2 (so the total input is 7 2), then the result should be
from group 1
7 2 2
7 2 3
7 2 5
7 2 7
from group 2
//nothing
from group 3
7 2
from group 4
//nothing
Then I add a 3rd input 5 (so the total input is 7 2 5), then the result should be
from group 1
7 2 5
from group 2
//nothing
from group 3
//nothing
from group 4
//nothing
It appears to be I need a forest(several trees) for this, correct ?
If so , is there any good c++ tree implementation of forest for this task or I better hand made one myself ?
Many Thanks
Something like to hold the data
Now you can create one of these for each group if there is no guarantee that the number of items in each group is the same, or if you know what each group is a specific number of items, then put them all in the same set.
Then use
std::find_ifwith a custom predicate with the abovedata. And in this predicate have astd::vectorwhich is the sequence you are looking for.Now applying this with
std::find_ifwill find all sequences indatawhich start with the search sequence.EDIT: To store in the single instance, wrap the vector, e.g.
Now your set contains
Add all the data from all the groups
Modify the predicate: