LINQ - order by results of subset -
edit
i'm going illustrate exact problem i'm trying solve. simplified problem explanation wasn't working.
i'm writing framework requires me assign threads cpu cores based on load factor. please let's not debate point why i'm doing this.
when framework boots, forms map of following hardware:
- level 1: processor workgroups.
- level 2: numa nodes.
- level 3: processors (sockets).
- level 4: cores.
- level 5: logical processors (only applicable smt systems).
i represent complex 5-level hierarchy.
users may query hardware info. user can specify nothing, desired workgroup, desired numa nodes, etc. down level 4. in case, framework filters out full data set , returns matches input, long complies hierarchy (i.e. user doesn't specify cores don't appear under specified processors).
next, user specify ranges, in "give me 1 workgroup, 1 numa node, , 3 cpus", example. in case, framework should return 3 cpus lowest assignment. filter & sort process.
again, user may specify filter level.
the user specify nothing, means framework must return hardware info, sorted according load assignment @ each level.
the process filter & sort, regardless of user specifies. difference user may specify range, count, or nothing.
to begin process, raw hardware data filtered according info supplied user. comes flattened enumeration of object {l1, l2, l3, l4, l5) each l5 object.
next, following:
ienumerable<keyvaluepair<int, double>> wgsub; ienumerable<keyvaluepair<int, double>> nnsub; ienumerable<keyvaluepair<int, double>> cpsub; ienumerable<keyvaluepair<int, double>> cosub; wgsub = ( n in query group n n.l1.id g select new keyvaluepair<int, double>(g.key, g.sum(n => n.l1.assignment)) ) .orderby(o => o.value); nnsub = ( n in query group n n.l2.id g select new keyvaluepair<int, double>(g.key, g.sum(n => n.l2.assignment)) ) .orderby(o => o.value); cpsub = ( n in query group n n.l3.id g select new keyvaluepair<int, double>(g.key, g.sum(n => n.l3.assignment)) ) .orderby(o => o.value); cosub = ( n in query group n n.l4.id g select new keyvaluepair<int, double>(g.key, g.sum(n => n.l4.assignment)) ) .orderby(o => o.value); query = ( n in query join wgj in wgsub on n.l1.id equals wgj.key join nnj in nnsub on n.l2.id equals nnj.key join cpj in cpsub on n.l3.id equals cpj.key join coj in cosub on n.l4.id equals coj.key select n ) .orderby(o => o.l1.id == wgsub.key) .thenby(o => o.l2.id == nnsub.key) .thenby(o => o.l3.id == cpsub.key) .thenby(o => o.l4.id == cosub.key);
where i'm stuck on orderby (which 4 levels deep). need sort input query id in each sub-query, "thenby" next, etc. wrote not correct.
if user specified range or count (both imply quantity), need implement take, possibly each level.
query
, typen
,take
? chance can elaborate bit, maybe sort of graphical presentation of problem? – gert arnold apr 19 '13 @ 22:47