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.
Generate the elegant pair of the non-negative integers x and y
Inverts an elegant pair into its component integers x and y
const elegantPair = require('elegant-pair');
let z = elegantPair.pair(92, 23);
// 8579
let xy = elegantPair.unpair(z);
// [ 92, 23 ]
For all questions and issues, please open an Issue in GitHub.
Licensed liberally under MIT; see LICENSE for complete license text.