erlzord (erlzord v2.0.0)

Copy Markdown View Source

N-dimensional Z-order curve (Morton code) encoding and decoding.

Any number of dimensions is supported and there is no limit on the bitsize of the encoded values.

Example

Config = erlzord:config(#{
    dimensions => 2,
    min_component => -1000,
    max_component => +1000
}),

1595729 = erlzord:encode({245, -456}, Config),
{245, -456} = erlzord:decode_tuple(1595729, Config).

Summary

Functions

Builds a pre-validated config/0 from a config_params/0 map.

Deprecated; use config/1 instead.

decode(Z, Config) deprecated

Deprecated; use decode_tuple/2 or decode_list/2 instead.

Decodes a Z-order value back into its component vector, as a list, using a config/0.

Like decode_list/2, but with Dimensions and the component bounds given inline instead of a prebuilt config/0.

Decodes a Z-order value back into its component vector, as a tuple, using a config/0.

Like decode_tuple/2, but with Dimensions and the component bounds given inline instead of a prebuilt config/0.

Encodes Vector into its Z-order (Morton) value using a config/0.

Encodes Vector with the component bounds given inline, without a prebuilt config/0.

Types

config()

-opaque config()

config_params()

-type config_params() ::
          #{dimensions := non_neg_integer(), min_component := integer(), max_component := integer()}.

coordinates()

-type coordinates() :: vector().

list_coordinates()

-type list_coordinates() :: list_vector().

list_vector()

-type list_vector() :: [integer()].

tuple_coordinates()

-type tuple_coordinates() :: tuple_vector().

tuple_vector()

-type tuple_vector() :: tuple().

vector()

-type vector() :: tuple_vector() | list_vector().

Functions

config(Params)

-spec config(Params) -> Config when Params :: config_params(), Config :: config().

Builds a pre-validated config/0 from a config_params/0 map.

The returned config can be reused across any number of encode/2, decode_tuple/2 and decode_list/2 calls that share the same bounds.

config(Dimensions, MinComponent, MaxComponent)

This function is deprecated. erlzord:config/3 is deprecated; Use config/1 instead.
-spec config(Dimensions, MinComponent, MaxComponent) -> Config
                when
                    Dimensions :: non_neg_integer(),
                    MinComponent :: integer(),
                    MaxComponent :: integer(),
                    Config :: config().

Deprecated; use config/1 instead.

Builds a config/0 from positional arguments rather than a config_params/0 map.

decode(Z, Config)

This function is deprecated. erlzord:decode/2 is deprecated; Use decode_tuple/2 or decode_list/2 instead.
-spec decode(Z, Config) -> Vector
                when Z :: non_neg_integer(), Config :: config(), Vector :: tuple_vector().

Deprecated; use decode_tuple/2 or decode_list/2 instead.

Equivalent to decode_tuple/2.

decode(Z, Dimensions, MinComponent, MaxComponent)

This function is deprecated. erlzord:decode/4 is deprecated; Use decode_tuple/4 or decode_list/4 instead.
-spec decode(Z, Dimensions, MinComponent, MaxComponent) -> Vector
                when
                    Z :: non_neg_integer(),
                    Dimensions :: non_neg_integer(),
                    MinComponent :: integer(),
                    MaxComponent :: integer(),
                    Vector :: tuple_vector().

Deprecated; use decode_tuple/4 or decode_list/4 instead.

Equivalent to decode_tuple/4.

decode_list(Z, Config)

-spec decode_list(Z, Config) -> Vector
                     when Z :: non_neg_integer(), Config :: config(), Vector :: list_vector().

Decodes a Z-order value back into its component vector, as a list, using a config/0.

decode_list(Z, Dimensions, MinComponent, MaxComponent)

-spec decode_list(Z, Dimensions, MinComponent, MaxComponent) -> Vector
                     when
                         Z :: non_neg_integer(),
                         Dimensions :: non_neg_integer(),
                         MinComponent :: integer(),
                         MaxComponent :: integer(),
                         Vector :: list_vector().

Like decode_list/2, but with Dimensions and the component bounds given inline instead of a prebuilt config/0.

decode_tuple(Z, Config)

-spec decode_tuple(Z, Config) -> Vector
                      when Z :: non_neg_integer(), Config :: config(), Vector :: tuple_vector().

Decodes a Z-order value back into its component vector, as a tuple, using a config/0.

decode_tuple(Z, Dimensions, MinComponent, MaxComponent)

-spec decode_tuple(Z, Dimensions, MinComponent, MaxComponent) -> Vector
                      when
                          Z :: non_neg_integer(),
                          Dimensions :: non_neg_integer(),
                          MinComponent :: integer(),
                          MaxComponent :: integer(),
                          Vector :: tuple_vector().

Like decode_tuple/2, but with Dimensions and the component bounds given inline instead of a prebuilt config/0.

encode(Vector, Config)

-spec encode(Vector, Config) -> Z when Vector :: vector(), Config :: config(), Z :: non_neg_integer().

Encodes Vector into its Z-order (Morton) value using a config/0.

Vector is a tuple or list of dimensions integer components. Raises error({badarg, _}) for a malformed vector and on components outside the configured min_component/max_component bounds.

encode(Vector, MinComponent, MaxComponent)

-spec encode(Vector, MinComponent, MaxComponent) -> Z
                when
                    Vector :: vector(),
                    MinComponent :: integer(),
                    MaxComponent :: integer(),
                    Z :: non_neg_integer().

Encodes Vector with the component bounds given inline, without a prebuilt config/0.

Prefer config/1 together with encode/2 when encoding many vectors that share the same bounds.

encode(Vector, Dimensions, MinComponent, MaxComponent)

This function is deprecated. erlzord:encode/4 is deprecated; Use encode/3 instead.
-spec encode(Vector, Dimensions, MinComponent, MaxComponent) -> Z
                when
                    Vector :: vector(),
                    Dimensions :: non_neg_integer(),
                    MinComponent :: integer(),
                    MaxComponent :: integer(),
                    Z :: non_neg_integer().

Deprecated; use encode/3 instead.

Dimensions is redundant — it is inferred from the size of Vector.