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:

  1. level 1: processor workgroups.
  2. level 2: numa nodes.
  3. level 3: processors (sockets).
  4. level 4: cores.
  5. 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.

share|improve question
2  
this looks kind of problem programmers love sink teeth into. fact no 1 responded far means that, me, not many people understand mean. like, of 3 problems trying solve code? relationship between levels? query, type n, take? chance can elaborate bit, maybe sort of graphical presentation of problem? – gert arnold apr 19 '13 @ 22:47
    
@gertarnold thanks. hope edit helps. – iamic apr 19 '13 @ 23:04

i'm not super clear on you're going for, along these lines?

query = query    .orderby(n => wgsub.first(g => g.key == n.l1.id).value)    .thenby(n => nnsub.first(g => g.key == n.l1.id).value)    ... 
share|improve answer
    
i wrote following, i'm testing: .orderby(o => n in wgsub select n.key) .thenby(o => n in nnsub select n.key) .thenby(o => n in cpsub select n.key) .thenby(o => n in cosub select n.key); – iamic apr 19 '13 @ 23:22
    
i think should show i'm going for. – iamic apr 19 '13 @ 23:22

your answer

 
discard

posting answer, agree privacy policy , terms of service.

not answer you're looking for? browse other questions tagged or ask own question.

Comments