From 78aeb2c38b8cb0a7b9db2b49527aa43e7947a1bf Mon Sep 17 00:00:00 2001 From: Egon Elbre Date: Tue, 17 Apr 2018 08:13:24 +0300 Subject: [PATCH] better output sorting --- count.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/count.go b/count.go index 7303782..75bbfeb 100644 --- a/count.go +++ b/count.go @@ -30,12 +30,32 @@ func (c *Count) Add(s *Count) { type Counts []*Count func (xs Counts) Len() int { return len(xs) } -func (xs Counts) Swap(i, j int) { xs[i], xs[j] = xs[j], xs[i] } +func (xs Counts) Swap(i, k int) { xs[i], xs[k] = xs[k], xs[i] } type ByCode struct{ Counts } -func (xs ByCode) Less(i, j int) bool { return xs.Counts[i].Code > xs.Counts[j].Code } +func (xs ByCode) Less(i, k int) bool { + a, b := xs.Counts[i], xs.Counts[k] + if a.Code == b.Code { + if a.Binary == b.Binary { + return a.Ext < b.Ext + } + return a.Binary > b.Binary + } + return a.Code > b.Code +} type ByExt struct{ Counts } -func (xs ByExt) Less(i, j int) bool { return xs.Counts[i].Ext < xs.Counts[j].Ext } +func (xs ByExt) Less(i, k int) bool { + a, b := xs.Counts[i], xs.Counts[k] + if a.Ext == b.Ext { + if a.Code == b.Code { + if a.Binary == b.Binary { + return a.Blank < b.Blank + } + return a.Binary > b.Binary + } + } + return a.Ext < b.Ext +}