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.
Deprecated; use decode_tuple/2 or decode_list/2 instead.
Deprecated; use decode_tuple/4 or decode_list/4 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.
Deprecated; use encode/3 instead.
Types
-opaque config()
-type config_params() :: #{dimensions := non_neg_integer(), min_component := integer(), max_component := integer()}.
-type coordinates() :: vector().
-type list_coordinates() :: list_vector().
-type list_vector() :: [integer()].
-type tuple_coordinates() :: tuple_vector().
-type tuple_vector() :: tuple().
-type vector() :: tuple_vector() | list_vector().
Functions
-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.
-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.
-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.
-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.
-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.
-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.
-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.
-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.
-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.
-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.
-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.