Created
July 31, 2019 02:29
-
-
Save tony612/27d5f835ac36018fae002bbee270d98d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
defmodule BinaryParseSlow do | |
def parse(bin) do | |
parse(bin, 0) | |
end | |
def parse(bin, acc) do | |
case do_parse(bin) do | |
{:nofin, x, rest} -> | |
parse(rest, acc + x) | |
{:fin, x} -> | |
acc + x | |
end | |
end | |
def do_parse(<<0::1, x::7, _::bits>>) do | |
{:fin, x} | |
end | |
def do_parse(<<1::1, x::7, rest::bits>>) do | |
{:nofin, x, rest} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment