Skip to content

Instantly share code, notes, and snippets.

@edbond
Created May 5, 2009 13:24
Show Gist options
  • Select an option

  • Save edbond/106966 to your computer and use it in GitHub Desktop.

Select an option

Save edbond/106966 to your computer and use it in GitHub Desktop.
-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)]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment