A collection of pairing functions
Project description
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.
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file pairing-functions-0.2.1.tar.gz
.
File metadata
- Download URL: pairing-functions-0.2.1.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6afaae6d1c9ef31d207e33963b564d4c9aec772d24c1f377dcd3906c85c96c8e |
|
MD5 | ff46c325193d6b7afda946638319c049 |
|
BLAKE2b-256 | 7d5fa30f140b78fe5cb2d109d01532f22c890e22744e67510caea0a1ccb32df7 |
File details
Details for the file pairing_functions-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: pairing_functions-0.2.1-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc92ccb0694e90ecace9032308cb884c07334a4d4648490edc5e47dad3cd8720 |
|
MD5 | 8423836f0451684b4263ad7cc4a73a16 |
|
BLAKE2b-256 | 311c443d14614a6006b25ac5cde6aaea93a5993a40894f2d817a8f81efed1e1c |