JSPM

elegant-pair

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q20997F
  • License MIT

An elegant pairing function which uniquely encodes two natural numbers into a single natural number

Package Exports

  • elegant-pair

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (elegant-pair) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.