# permutation-rank

> Ranks and unranks permutations

Latest version **1.0.0** (published 2014-04-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install permutation-rank
pnpm add permutation-rank
yarn add permutation-rank
bun add permutation-rank
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2014-04-30 |
| First published | 2013-03-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Mikola Lysenko |
| Maintainers | mikolalysenko |
| Keywords | permutation, rank, unrank, order, compare, sort, group |

## Links

- npm: https://www.npmjs.com/package/permutation-rank
- Repository: https://github.com/mikolalysenko/permutation-rank
- Issues: https://github.com/mikolalysenko/permutation-rank/issues
- npm.io page: https://npm.io/package/permutation-rank

## Dependencies (2)

- [typedarray-pool](https://npm.io/package/typedarray-pool.md) ^1.0.0
- [invert-permutation](https://npm.io/package/invert-permutation.md) ^1.0.0

## Recent versions

- 1.0.0 (latest) — 2014-04-30
- 0.1.1 — 2013-11-26
- 0.1.0 — 2013-11-05
- 0.0.0 — 2013-03-04

## README

permutation-rank
================
Ranks and unranks permutations.  Based on the following paper:

W. Myrvold, F. Ruskey. (2000) "[Ranking and Unranking Permutations in Linear Time](http://webhome.cs.uvic.ca/~ruskey/Publications/RankPerm/RankPerm.html)". Information Processing Letters.  

Usage
=====
First install using npm:

    npm install permutation-rank

Then you can use it like this:

```javascript
var prank = require("permutation-rank")
var perm = [0,3,1,2]
var r = prank.rank(perm)
console.log("r = ", r)
var u = prank.unrank(perm.length, r)
console.log("u = ", u)

//Prints:
//        r =  15
//        u =  [ 0, 3, 1, 2 ]
```

`prank.rank(permutation)`
-----------------------------------------------
Computes an integer representing the colexicographic rank of the permutation

* `permutation` is an array encoding some permutation

**Returns** An integer representing the ranked encoding of the permutation


`prank.unrank(length, rank[, result])`
--------------------------------------------------
Computes a permutation from a rank order with the given length

* `length` is the length of the permuation
* `rank` is the index of the permutation
* `result` is an optional argument which stores the result of the inversion

**Returns** The permutation at the given rank

Credits
=======
(c) 2013 Mikola Lysenko. MIT License

---
_Source: https://npm.io/package/permutation-rank · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
