Function frequency: Difference between revisions
Content added Content deleted
(Go solution) |
(→{{header|Go}}: top ten) |
||
Line 16: | Line 16: | ||
"io/ioutil" |
"io/ioutil" |
||
"os" |
"os" |
||
"sort" |
|||
) |
) |
||
Line 44: | Line 45: | ||
return true |
return true |
||
}) |
}) |
||
cs := make(calls, 0, len(m)) |
|||
for k, v := range m { |
for k, v := range m { |
||
cs = append(cs, &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 { |
|||
⚫ | |||
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: |
Output, when run on source code above: |
||
<pre> |
<pre> |
||
len 3 |
|||
fmt.Println 3 |
|||
⚫ | |||
f.Offset 2 |
|||
1 a.Pos |
|||
make 2 |
|||
1 ast.Inspect |
|||
fmt.Printf 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> |
</pre> |
||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
<lang PicoLisp>(let Freq NIL |
<lang PicoLisp>(let Freq NIL |