Function frequency: Difference between revisions

(Go solution)
Line 16:
"io/ioutil"
"os"
"sort"
)
 
Line 44 ⟶ 45:
return true
})
cs := make(calls, 0, len(m))
for k, v := range m {
fmt.Printlncs = append(vcs, &call{k, v})
}
sort.Sort(cs)
}</lang>
for i, c := range cs {
fmt.Printf("%-20s %4d\n", c.expr, c.count)
if i == 9 {
break
}
}
}
 
type call struct {
1 expr string
count int
}
type calls []*call
 
func (c calls) Len() int { return len(c) }
func (c calls) Swap(i, j int) { c[i], c[j] = c[j], c[i] }
func (c calls) Less(i, j int) bool { return c[i].count > c[j].count }</lang>
Output, when run on source code above:
<pre>
len 3
4 fmt.Println 3
1 string
f.Offset 2
1 a.Pos
make 2
1 ast.Inspect
fmt.Printf 1
1 ioutil.ReadFile 1
1 len
a.Pos 1
2 f.Offset
string 1
1 token.NewFileSet
skeys byron 81> 1
1 ce.Pos
append 1
1 make
1 fs.File
1 parser.ParseFile
</pre>
 
=={{header|PicoLisp}}==
<lang PicoLisp>(let Freq NIL
1,707

edits