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
Close
Hashes for pairing_functions-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc92ccb0694e90ecace9032308cb884c07334a4d4648490edc5e47dad3cd8720 |
|
MD5 | 8423836f0451684b4263ad7cc4a73a16 |
|
BLAKE2b-256 | 311c443d14614a6006b25ac5cde6aaea93a5993a40894f2d817a8f81efed1e1c |