Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
iterative-permutation
Advanced tools
Fast, iterative implementation of Heap's Algorithm for JavaScript
This is a non-recursive implementation of Heap's Algorithm that can be used to generate permutations for very large sets of values. Typically recursive solutions generate all sets of values and then return them all at the end. For very large sets it becomes problematic to store all of the permutations in memory. Instead this implementation returns permutations one at a time so they can be processed and discarded if needed.
npm install iterative-permutation
var Permutation = require('iterative-permutation');
var generator = new Permutation([1, 2, 3]);
while (generator.hasNext()) {
console.log(generator.next());
}
console.log('finished');
Prints:
[ 1, 2, 3 ]
[ 2, 1, 3 ]
[ 3, 1, 2 ]
[ 1, 3, 2 ]
[ 2, 3, 1 ]
[ 3, 2, 1 ]
finished
This implementation keeps track of the algorithm stack in a variable called
stack
and then updates it with the current index each time a new permutation
is calculated. It only uses for loops and simple function calls and has no
external dependencies, just regular ol' JavaScript. Why no ES6 generators? Some
people have found that generators are a
little slow
and typically when you need a large number of permutations it's in a hot code
path. This implementation tries to be as fast as reasonably possible.
Brian Card: @bmcard
MIT License - Copyright 2015 Brian Card
FAQs
Fast, iterative implementation of Heap's Algorithm
We found that iterative-permutation demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.