New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

permutation-rank

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

permutation-rank - npm Package Compare versions

Comparing version 0.0.0 to 0.1.0

LICENSE

46

index.js
"use strict"
var pool = require("typedarray-pool")
var inverse = require("invert-permutation")
function rank(permutation) {
switch(permutation.length) {
var n = permutation.length
switch(n) {
case 0:

@@ -15,6 +17,10 @@ case 1:

}
var p = permutation.slice(0)
, pinv = inverse(p)
, r = 0, s, t, i
for(i=p.length-1; i>0; --i) {
var p = pool.mallocUint32(n)
var pinv = pool.mallocUint32(n)
var r = 0, s, t, i
inverse(permutation, pinv)
for(i=0; i<n; ++i) {
p[i] = permutation[i]
}
for(i=n-1; i>0; --i) {
t = pinv[i]

@@ -28,20 +34,38 @@ s = p[i]

}
pool.freeUint32(pinv)
pool.freeUint32(p)
return r
}
function unrank(n, r) {
function unrank(n, r, p) {
switch(n) {
case 0:
if(p) { return p }
return []
case 1:
return [0]
if(p) {
p[0] = 0
} else {
return [0]
}
case 2:
return r ? [0,1] : [1,0]
if(p) {
if(r) {
p[0] = 0
p[1] = 1
} else {
p[0] = 1
p[1] = 0
}
return p
} else {
return r ? [0,1] : [1,0]
}
default:
break
}
var p = new Array(n)
, s, t, i, nf=1
p = p || new Array(n)
var s, t, i, nf=1
p[0] = 0
for(i=1; i<p.length; ++i) {
for(i=1; i<n; ++i) {
p[i] = i

@@ -48,0 +72,0 @@ nf = (nf*i)|0

{
"name": "permutation-rank",
"version": "0.0.0",
"version": "0.1.0",
"description": "Ranks and unranks permutations",

@@ -10,3 +10,4 @@ "main": "index.js",

"dependencies": {
"invert-permutation": "~0.0.0"
"invert-permutation": "~0.1.0",
"typedarray-pool": "~0.1.1"
},

@@ -29,3 +30,4 @@ "devDependencies": {

"compare",
"sort"
"sort",
"group"
],

@@ -32,0 +34,0 @@ "author": "Mikola Lysenko",

@@ -32,10 +32,19 @@ permutation-rank

* `permutation` is an array encoding some permutation
`require("permutation-rank").unrank(length, rank)`
**Returns** An integer representing the ranked encoding of the permutation
`require("permutation-rank").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
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc