-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcount.go
61 lines (51 loc) · 1 KB
/
count.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
type CountByExt map[string]*Count
func (xs CountByExt) Add(s *Count) {
r, ok := xs[s.Ext]
if !ok {
xs[s.Ext] = s
return
}
r.Add(s)
}
type Count struct {
Ext string
Files int
Binary int
Blank int
Code int
}
func (c *Count) Add(s *Count) {
c.Ext = s.Ext
c.Files += s.Files
c.Binary += s.Binary
c.Blank += s.Blank
c.Code += s.Code
}
type Counts []*Count
func (xs Counts) Len() int { return len(xs) }
func (xs Counts) Swap(i, k int) { xs[i], xs[k] = xs[k], xs[i] }
type ByCode struct{ Counts }
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, 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
}