### 2 releases

0.1.1 | Mar 26, 2021 |
---|---|

0.1.0 | Mar 25, 2021 |

#**1555** in Algorithms

**61** downloads per month

Used in fractal-analysis

**MIT/Apache**

64KB

1K
SLoC

# Lindel (lineariser-delineariser)

## Introduction

The

crate offers functions for transforming arrays of primitive unsigned integers to Morton or Hilbert keys and back, via the eponymous encoding processes. This helps linearise data points while preserving some measure of locality.`lindel`

This crate is an extension of the

crate.`morton-encoding`

## Getting started

If it is not necessary to use

with `lindel`

, it is sufficient to insert the line`nalgebra`

`lindel = "0.1"
`

under the

section. Otherwise, the following section must be inserted to the project's `[``dependencies``]`

file:`Cargo .toml`

`[``dependencies.lindel``]`
`version ``=` `"`0.1`"`
`features ``=` `[``"`nalgebra`"``]`

## Usage

### Primitive integers

`use` `lindel``::``*``;`
`let` input `=` `99251``;`
`let` output_1`:` `[``u8``;` `5``]` `=` `hilbert_decode``(`input`)``;`
`let` output_2`:` `[``u32``;` `2``]` `=` `morton_decode``(`input`)``;`
`let` input `=` `[``543``u32``,` `23765``]``;`
`let` output_1 `=` input`.``hilbert_index``(``)``;`
`let` output_2 `=` input`.``z_index``(``)``;`

Please note the necessity of specifying the output data-types for the decoding operations.

`Point`

s:

`Point`

`use` `nalgebra``::`Point`;`
`use` `nalgebra``::``U4``;`
`use` `lindel``::``nalgebra_points``::`Lineariseable`;`
`type` `FourDees` `=` `Point``<``u32`, U4`>``;`
`let` input `=` `26327612``u128``;`
`let` pnt `=` `FourDees``::`from_z_index`(`input`)``;`
`let` result `=` pnt`.``hilbert_index``(``)``;`

### New large uints:

`lindel``::`create_lineariseable_data_type`!``(``u128``,` `33``,` NewKey`)``;`
`let` input `=` `[``870``u128``;` `33``]``;`
`let` hind `=` `NewKey``::`hilbert_index`(`input`)``;`
`let` zind `=` `NewKey``::`z_index`(`input`)``;`
`let` reinstated_input `=` hind`.``from_hilbert_index``(``)``;`
`assert_eq!``(`input`,` reinstated_input`)``;`
`let` reinstated_input `=` `NewKey``::`from_z_index`(`zind`)``;`
`assert_eq!``(`input`,` reinstated_input`)``;`

## Advantages and Disadvantages

Long story short: Choose Morton encoding (“z-indexing”) if speed is more important than locality. Otherwise, feel free to use Hilbert encoding everywhere.

#### Dependencies

~0.5–1MB

~21K SLoC