pairing-functions
A pairing function is a function that reversibly maps two non-negative integers onto a single non-negative integer.
This package currently supports the following pairing functions:
- Szudzik pairing function
- Cantor pairing function
Install
Simply:
$ pip install pairing-functions
Usage
from pairing_functions import cantor, szudzik
szudzik.pair(3, 4)
// 19
szudzik.unpair(19)
// (3, 4)
cantor.pair(3, 4)
// 32
cantor.unpair(32)
// (3, 4)
You can also work with more than 2 integers:
from pairing_functions import cantor, szudzik
szudzik.pair(1, 2, 3, 4)
// 1126
cantor.pair(1, 2, 3, 4)
// 2705
# by default, unpairing will result in two integers
szudzik.unpair(1126)
// (33, 4)
cantor.unpair(2705)
// (69, 4)
# but going back to the initial integers is also possible
# just specify how many integers you expect
szudzik.unpair(1126, n=4)
// (1, 2, 3, 4)
cantor.unpair(2705, n=4)
// (1, 2, 3, 4)
Documentation
You can find more about pairing functions in the docs.
How to contribute
If you wish to contribute, you can start from here !
Test
You can run the available tests with pytest - code coverage metrics are also available via pytest-cov.
Release files for pairing-functions 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pairing-functions-0.2.1.tar.gz | 3.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pairing_functions-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:8.9 kB
Release files / pairing-functions-0.2.1.tar.gz
| Download URL | pairing-functions-0.2.1.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6afaae6d1c9ef31d207e33963b564d4c9aec772d24c1f377dcd3906c85c96c8e
|
|
BLAKE2b-256 checksum How to use checksums |
7d5fa30f140b78fe5cb2d109d01532f22c890e22744e67510caea0a1ccb32df7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.1 CPython/3.6.9
|
Release files / pairing_functions-0.2.1-py3-none-any.whl
| Download URL | pairing_functions-0.2.1-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fc92ccb0694e90ecace9032308cb884c07334a4d4648490edc5e47dad3cd8720
|
|
BLAKE2b-256 checksum How to use checksums |
311c443d14614a6006b25ac5cde6aaea93a5993a40894f2d817a8f81efed1e1c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.1 CPython/3.6.9
|