Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pairing-functions-0.2.1.tar.gz (3.3 kB view hashes)

Uploaded Source

Built Distribution

pairing_functions-0.2.1-py3-none-any.whl (5.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page