Created
April 4, 2011 07:01
-
-
Save alexbowe/901235 to your computer and use it in GitHub Desktop.
Generates a tuple of popcounts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(popcount_table). | |
-export([gen_table/1]). | |
gen_table(Bits) -> gen_table(1, 2 bsl (Bits - 1), {0}). | |
gen_table(Stop, Stop, Table) -> Table; | |
gen_table(Value, Stop, Table) -> | |
New = (Value band 1) + erlang:element((Value bsr 1) + 1, Table), | |
NewTable = erlang:append_element(Table, New), | |
gen_table(Value + 1, Stop, NewTable). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment