http://play.golang.org/p/BXl0IIQ-qS

You can see from the program's output that after Sort(), all entries catA,

catB and catC int categories are grouped together (hierarchically) and only within

these clusters sorted/ordered by the float64 dist value.

(Technically the catA/catB/catC int categories are also sort-ordered

ascendingly but this isn't necessary at all. They just need to stay

together but instead of 2,2,4,4,6,6 might as well be 4,4,6,6,2,2...)

This works fine with a single sort.Sort() call but now I want to 1up this

as follows:

Suppose, (without losing the cluster groupings) I want to move those

groups/clusters which have "the most 'low' dist values" first, and those

which have on-average/more "higher" dist values last.

The above program randomizes the data each time but consider the following

example result:

SORTED:

===>

catA=2 catB=5 catC=0 dist=10

catA=2 catB=5 catC=0 dist=80

catA=2 catB=5 catC=0 dist=80

catA=2 catB=5 catC=0 dist=80

catA=2 catB=5 catC=1 dist=80

catA=2 catB=7 catC=1 dist=80

catA=4 catB=5 catC=0 dist=40

catA=4 catB=5 catC=0 dist=80

catA=4 catB=5 catC=1 dist=20

catA=4 catB=5 catC=1 dist=80

catA=4 catB=7 catC=0 dist=10

catA=4 catB=7 catC=0 dist=80

catA=6 catB=3 catC=1 dist=10

catA=6 catB=5 catC=0 dist=10

catA=6 catB=5 catC=0 dist=10

catA=6 catB=5 catC=0 dist=40

The above program randomizes the data each time but consider the following

example result:

The entire catA=2 group should be at the end, since most dists are "high"

(80). The entire catA=6 group should be first, because it gets us 3

"low-distance" entries.

I realize this is a bit of a fuzzy / impresicely-defined requirement, but

working with averages here would be sufficient to get to this benefit.

Ideally I'm looking for some ideas / tricks / algos that could integrate

this final need right into the current entries.(sort.Interface).Less()

method but a second Sort() pass would also be OK.

The problem I see with a naive "do a second sort.Sort() with a different

Less() method" approach: as per godoc, "the sort is not guaranteed to be

stable". So the previous groupings would get lost if I just did a simple

"sort the entire now-grouped slice just by dist values".

So... seems like I missed that class back in Computer Science -- any

algorithmics-ninjas out there got some neat ideas?

--

You received this message because you are subscribed to the Google Groups "golang-nuts" group.

To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.