edbond (owner)

Revisions

  • eceb66 edbond Tue May 05 06:24:04 -0700 2009
gist: 106966 Download_button fork
public
Public Clone URL: git://gist.github.com/106966.git
Embed All Files: show embed
freq.erl #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
-module(freq).
-export([main/0]).
 
freq(B) when is_binary(B) ->
  Arr = array:new([{size,256}, {fixed,true}, {default,0}]),
  freq(B, Arr).
 
freq(<<>>, Arr) -> Arr;
freq(<<B:8,Rest/binary>>, Arr) ->
  Old = array:get(B, Arr),
  New = array:set(B, Old+1, Arr),
  freq(Rest, New).
 
main() ->
  F = freq(<<"abcdefabc">>),
  io:format("~p~n", [array:to_list(F)]).