Skip to content

Commit

Permalink
Update documentation, fix wording
Browse files Browse the repository at this point in the history
  • Loading branch information
asaaki committed Feb 18, 2015
1 parent 550e859 commit 5cfe583
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/fnv/fnv_1.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule FNV.FNV1 do

use Bitwise, only: [{ :bxor, 2 }, { :<<<, 2}]

for { bit, prime, offset_base } <- Params.all_params do
for { bit, prime, offset_basis} <- Params.all_params do
function_name = :"hash_#{bit}"

@doc """
Expand All @@ -32,7 +32,7 @@ defmodule FNV.FNV1 do
#=> <integer value>
"""
def unquote(function_name)(data) when is_binary(data) do
hash(unquote(bit), unquote(prime), unquote(offset_base), data)
hash(unquote(bit), unquote(prime), unquote(offset_basis), data)
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/fnv/fnv_1a.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule FNV.FNV1a do

use Bitwise, only: [{ :bxor, 2 }, { :<<<, 2}]

for { bit, prime, offset_base } <- Params.all_params do
for { bit, prime, offset_basis} <- Params.all_params do
function_name = :"hash_#{bit}"

@doc """
Expand All @@ -32,7 +32,7 @@ defmodule FNV.FNV1a do
#=> <integer value>
"""
def unquote(function_name)(data) when is_binary(data) do
hash(unquote(bit), unquote(prime), unquote(offset_base), data)
hash(unquote(bit), unquote(prime), unquote(offset_basis), data)
end
end

Expand Down
16 changes: 10 additions & 6 deletions lib/fnv/params.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule FNV.Params do
use Bitwise, only: [{:<<<, 2}]

@moduledoc "Support module, not intended to be used directly"

# Supported output lengths
@bits [32, 64, 128, 256, 512, 1024]

Expand Down Expand Up @@ -28,26 +30,28 @@ defmodule FNV.Params do
@params List.zip([@bits, @primes, @offset_bases])

@doc """
Returns the prime and offset base for the given bit length (must be one of #{inspect @bits}).
Returns the prime and offset basisfor the given bit length (must be one of #{inspect @bits}).
For invalid values it returns an empty dict/list.
## Examples
FNV.Params.bits(64)
#=> [prime: 1099511628211, offset_base: 14695981039346656037]
FNV.Params.params_for(64)
#=> [prime: 1099511628211, offset_basis: 14695981039346656037]
FNV.Params.bits(99)
FNV.Params.params_for(99)
#=> []
"""
def params_for(desired_bit_length)
for { bit, prime, offset_base } <- @params do
for { bit, prime, offset_basis} <- @params do
def params_for(unquote(bit)) do
[prime: unquote(prime), offset_base: unquote(offset_base)]
[prime: unquote(prime), offset_basis: unquote(offset_basis)]
end
end
def params_for(_), do: []

@doc "Returns a list of all supported bit lengths"
def supported_bit_lengths, do: @bits

@doc "Returns a list of all necessary data for calculating the hashes (bit length, prime and offset basis)"
def all_params, do: @params
end

0 comments on commit 5cfe583

Please sign in to comment.