This is a minimal, vectorised and batchable library for computing Lehmer codes.
Project description
Lehmer
A minimal, vectorized, and batchable implementation of Lehmer codes.
Lehmer codes, named after D.H. Lehmer, offer a method for enumerating the permutations of a set. The Lehmer code counts the number of inversions in a permutation. Together with the factoradic base, it provides a way to uniquely encode permutations as integers. This encoding therefore provides a bijection between integers and permutations. In other words, it is a perfect, memory-efficient hashing function for permutations.
Installation
Installing from PyPI:
[uv] pip install lehmer
Installing from source:
git clone ...
cd lehmer
uv venv
uv sync
Description
The class Lehmer provides two pairs of methods (depicted below in blue). Additionally, there are two convenience functions encode and decode (depicted below in orange) that combine the pairs for encoding and decoding permutations to and from integer indices.
$$ \underbrace{\text{permutation} \xrightarrow{\text{\color{blue}{perm2code}}} \text{code} \xrightarrow{\text{\color{blue}{code2index}}} \text{index} \in \mathbb{Z}}_{\text{\color{orange}{encode}}} $$
$$ \underbrace{\text{permutation} \xleftarrow{\text{\color{blue}{code2perm}}} \text{code} \xleftarrow{\text{\color{blue}{index2code}}} \text{index} \in \mathbb{Z}}_{\text{\color{orange}{decode}}} $$
Examples
Coming soon
Contributing
Please read the contributing guidelines if you wish to contribute to this project.
Credits
- Image source Wikimedia
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lehmer-0.1.0.tar.gz.
File metadata
- Download URL: lehmer-0.1.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
131cb3c0bacbd0aa94cc03683a2e488e6cfac4cddb1e50fa70bf657d9d52ddfd
|
|
| MD5 |
220f4d442000c10e304f27305037076f
|
|
| BLAKE2b-256 |
385b71e6da4ea8b5cca876ef181660b008d6689c7db11221c87f3d468bfa16ca
|
File details
Details for the file lehmer-0.1.0-py3-none-any.whl.
File metadata
- Download URL: lehmer-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92b01894a43cb1f8dfc9bad9a85471a16196e941dcc2b3953b1008ff1d4f0a4e
|
|
| MD5 |
6ed0bb994ed9d0c1ec983422c4a030ff
|
|
| BLAKE2b-256 |
3e7553003b8c6adf71944a19b649a6345b888a4ff7ad4e82bf622c1d869de13a
|