1.0.1 • Published 7 years ago

elegant-pair v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

elegant-pair

Introduction

Pairing functions are typically used in set theory and theoretical computer science, but can also be used as a simple reversible hashing algorithm on the set of integers.

This can be useful when working with a RDBMS, and it is necessary to construct an unique integer from two or more integers.

The elegant-pair module implements the pairing function created by Matthew Szudzik from Wolfram Research, Inc.

API

Module Functions

pair(x, y)

Generate the elegant pair of the non-negative integers x and y

unpair(z)

Inverts an elegant pair into its component integers x and y

Example

const elegantPair = require('elegant-pair');

let z = elegantPair.pair(92, 23);
// 8579

let xy = elegantPair.unpair(z);
// [ 92, 23 ]

Questions and Issues

For all questions and issues, please open an Issue in GitHub.

License

Licensed liberally under MIT; see LICENSE for complete license text.

1.0.1

7 years ago

1.0.0

7 years ago