View Source ehashids (ehashids v0.1.4)

Link to this section Summary

Functions

Encode the hashids_ref() data in to a tuple to be cached.

This data needs to be treated as opaque changing the values can be dangerous!

Decode a hash id into a list of numbers.

Note that decode here is not safe the Id can contain additional invalid data. If this is a problem use the equivalent decode_safe/2 function.

Decode a hash id into a list of numbers in a safe way.

This function decodes and also checks if the result is commutative with encode/2.

Returns the default hashids alphabet.
Returns the default hashids salt.
Returns the default hashids separators.
Encode a list of numbers into a hash id.

Numbers here are 64 bit unsigned integers internally larger integers will cause an error. For larger values multiple numbers can be used instead.

Encode a number into a hash id.

Number here is a 64 bit unsigned integer internally larger values will cause an error. For larger values multiple numbers can be used instead using the encode/2 function.

Estimate the size of the encoding for an input (for REPL use only).
Create a new hashids_ref() from cached data avoiding shuffling.

The compiled data needs to be treated as opaque changing the values can be dangerous! Only use an input produced by the compile/1 function.

Returns the default hashids minimum alphabet length.
Returns the default hashids minimum hash length.
Creates a new hashids context. With the default parameters.

IMPORTANT do not share these references between processes. This can cause stability issues. Avoiding the shuffle overhead at initialization can be accomplished by caching the compiled output of the reference using the compile/1 function and then recreating the reference in each process.

Creates a new hashids context. With the default parameters but specify a custom salt.

IMPORTANT do not share these references between processes. This can cause stability issues. Avoiding the shuffle overhead at initialization can be accomplished by caching the compiled output of the reference using the compile/1 function and then recreating the reference in each process.

Creates a new hashids context. With the default parameters but specify a custom salt and minimum hash length.

IMPORTANT do not share these references between processes. This can cause stability issues. Avoiding the shuffle overhead at initialization can be accomplished by caching the compiled output of the reference using the compile/1 function and then recreating the reference in each process.

Creates a new hashids context. With the default parameters but specify a custom salt and minimum hash length as well as a custom alphabet.

Keep in mind that the alphabet only supports the ASCII character set. If this a problem consider adding UTF-8 support to the underlying library.

Link to this section Types

Link to this opaque

compiled_hashids_ref/0

View Source (opaque)
-opaque compiled_hashids_ref()
-opaque hashids_ref()

Link to this section Functions

-spec compile(Ref :: hashids_ref()) -> {ok, compiled_hashids_ref()} | {error, atom()}.
Encode the hashids_ref() data in to a tuple to be cached.

This data needs to be treated as opaque changing the values can be dangerous!

-spec decode(Ref :: hashids_ref(), Id :: binary()) ->
          {ok, Numbers :: [non_neg_integer()]} | {error, atom()}.
Decode a hash id into a list of numbers.

Note that decode here is not safe the Id can contain additional invalid data. If this is a problem use the equivalent decode_safe/2 function.

-spec decode_safe(Ref :: hashids_ref(), Id :: binary()) ->
               {ok, Numbers :: [non_neg_integer()]} | {error, unsafe} | {error, atom()}.
Decode a hash id into a list of numbers in a safe way.

This function decodes and also checks if the result is commutative with encode/2.

-spec default_alphabet() -> binary().
Returns the default hashids alphabet.
-spec default_salt() -> binary().
Returns the default hashids salt.
-spec default_separators() -> binary().
Returns the default hashids separators.
-spec encode(Ref :: hashids_ref(), Numbers :: [non_neg_integer()]) ->
          {ok, Id :: binary()} | {error, atom()}.
Encode a list of numbers into a hash id.

Numbers here are 64 bit unsigned integers internally larger integers will cause an error. For larger values multiple numbers can be used instead.

-spec encode_one(Ref :: hashids_ref(), Number :: non_neg_integer()) ->
              {ok, Id :: binary()} | {error, atom()}.
Encode a number into a hash id.

Number here is a 64 bit unsigned integer internally larger values will cause an error. For larger values multiple numbers can be used instead using the encode/2 function.

Link to this function

estimate_encoded_size(Ref, Numbers)

View Source
-spec estimate_encoded_size(Ref :: hashids_ref(), [non_neg_integer()]) ->
                         {ok, Size :: non_neg_integer()} | {error, atom()}.
Estimate the size of the encoding for an input (for REPL use only).
Link to this function

from_compiled(CompiledData)

View Source
-spec from_compiled(CompiledData :: compiled_hashids_ref()) -> hashids_ref() | {error, atom()}.
Create a new hashids_ref() from cached data avoiding shuffling.

The compiled data needs to be treated as opaque changing the values can be dangerous! Only use an input produced by the compile/1 function.

-spec min_alphabet_length() -> pos_integer().
Returns the default hashids minimum alphabet length.
-spec min_hash_length() -> non_neg_integer().
Returns the default hashids minimum hash length.
-spec new() -> hashids_ref().
Creates a new hashids context. With the default parameters.

IMPORTANT do not share these references between processes. This can cause stability issues. Avoiding the shuffle overhead at initialization can be accomplished by caching the compiled output of the reference using the compile/1 function and then recreating the reference in each process.

-spec new(Salt :: binary()) -> hashids_ref() | {error, Reason :: atom()}.
Creates a new hashids context. With the default parameters but specify a custom salt.

IMPORTANT do not share these references between processes. This can cause stability issues. Avoiding the shuffle overhead at initialization can be accomplished by caching the compiled output of the reference using the compile/1 function and then recreating the reference in each process.

-spec new(Salt :: binary(), MinHashLen :: non_neg_integer()) ->
       hashids_ref() | {error, Reason :: atom()}.
Creates a new hashids context. With the default parameters but specify a custom salt and minimum hash length.

IMPORTANT do not share these references between processes. This can cause stability issues. Avoiding the shuffle overhead at initialization can be accomplished by caching the compiled output of the reference using the compile/1 function and then recreating the reference in each process.

Link to this function

new(Salt, MinHashLen, Alphabet)

View Source
-spec new(Salt :: binary(), MinHashLen :: non_neg_integer(), Alphabet :: binary()) ->
       hashids_ref() | {error, Reason :: atom()}.
Creates a new hashids context. With the default parameters but specify a custom salt and minimum hash length as well as a custom alphabet.

Keep in mind that the alphabet only supports the ASCII character set. If this a problem consider adding UTF-8 support to the underlying library.

IMPORTANT do not share these references between processes. This can cause stability issues. Avoiding the shuffle overhead at initialization can be accomplished by caching the compiled output of the reference using the compile/1 function and then recreating the reference in each process.