I have the following three-level data structure (bottom to top):
object
C
:{string, T, float}
(where T is also an object)sorted container
B
of objectsC
with samestring
by highest float firstsorted container
A
of objectsB
by lowestmax(C.float)
(i.e.B[0]
) first
So at the beginning I'll have a bunch of C
with pre-computed float
values and my data structure should look like this:
A:
B:
C:
string: "one"
T: {object}
float: 10
C:
string: "one"
T: {object} # different from the above of course
float: 8.3
C:
string: "one"
T: {object}
float: -4
B:
C:
string: "two"
T: {object}
float: 15
C:
string: "two"
T: {object}
float: 2
C:
string: "two"
T: {object}
float: 0
No difficult problem up to now, as I could just simply put all of this into a set of sets (/multisets) and be done with it. Here is where it get's difficult: I will have to extract a subset of these to compute a solution of my problem (the first C
of every B
). If there is no solution, then remove the topmost C
and extract the new subset to try again. In python pseudo-code:
def get_list():
c_list = []
for b in A:
c_list.append(b[0]) # element in B with highest float value
return c_list
def solve():
for i in range(1, 3): # three tries
c_list = get_list()
# do stuff with c_list
if fail:
del A[0][0] # the topmost C element in the first B
continue
But when I delete this A[0][0]
(i.e. the C
with {"one", T, 10}
), I need the whole thing to re-sort itself. Therefore I can't use sets as I'd be modifying A[0]
, which a STL set/multiset doesn't allow.
The other solution would be to create classes, define the operator()
or operator<
for each of the two levels I need to do a comparison on (B
and C
) for std::sort()
and stuff everything into a two-level STL vector. However this just seems overly complicated/my non-professional C++ intuition tells the there should be an easier way to code this neatly.
Performance is important as it's a "real-time" application for a robot, but not of topmost priority as I'll only have say up to 30 C
.