Skip to content

Commit 15d0ae1

Browse files
add docs
1 parent 6dec65b commit 15d0ae1

33 files changed

+268
-22
lines changed

src/_apply.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { _transpose } from './_transpose' ;
22

3+
/**
4+
* Applies a given sequence (in the given order) of transpositions (given as
5+
* index tuples) to a given permutation. The permutation is modified in place.
6+
*
7+
* @param transpositions The given transpositions to apply.
8+
* @param sigma The permutation to apply the transpositions to.
9+
*/
310
export function _apply ( transpositions , sigma ) {
411

5-
for ( const [ s , t ] of transpositions ) {
6-
7-
_transpose( s , t , sigma ) ;
8-
9-
}
12+
for ( const [ s , t ] of transpositions ) _transpose( s , t , sigma ) ;
1013

1114
}
1215

src/_bitreversal.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11

2+
/**
3+
* Fills an input array with the bitreversal permutation for input
4+
* <code>n</code> items. The array is filled starting at index <code>0</code>
5+
* and ending at index <code>n-1</code>. Note that <code>n</code> MUST be a
6+
* power of <code>2</code>.
7+
*
8+
* @param {Array} array The array to fill.
9+
* @param {Number} n The size of the permutation, must be a power of 2.
10+
*/
211
export function _bitreversal ( array , n ) {
312

413
let i = 1 ;

src/_compose.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11

2+
/**
3+
* Compose two input permutations. The resulting permutation is output as an
4+
* iterator of indices instead of an array of indices.
5+
*
6+
* @param {Array} sigma The first input permutation.
7+
* @param {Array} tau The second input permutation.
8+
* @returns {Iterator} An iterator over the items of the resulting permutation.
9+
*/
210
export function* _compose ( sigma , tau ) {
311

412
for ( const t of tau ) yield sigma[t] ;

src/_copy.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11

2+
/**
3+
* Copy an input permutation to an output array.
4+
*
5+
* @param {Array} sigma The input permutation.
6+
* @param {Number} n The size of the input permutation to copy.
7+
* @param {Array} tau The output array.
8+
*/
29
export function _copy ( sigma , n , tau ) {
310

4-
for ( let i = 0 ; i < n ; ++i ) {
5-
6-
tau[i] = sigma[i] ;
7-
8-
}
11+
for ( let i = 0 ; i < n ; ++i ) tau[i] = sigma[i] ;
912

1013
}
1114

src/_cycles.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11

2+
/**
3+
* Computes a {@link https://en.wikipedia.org/wiki/Permutation#Cycle_notation
4+
* cycle decomposition} of an input permutation. This algorithm is
5+
* deterministic; the algorithm will procedes in a sequential manner, first
6+
* yielding the cycle containing the first (in input order) index of the
7+
* permutation, then yielding the cycle containing the first (in input order)
8+
* index of the permutation that is not in the first cycle, etc. The output is
9+
* in the form of an iterator over cycles <code>[a, [b, c, ...]]</code> where
10+
* <code>a</code> is the first element of the cycle and the list <code>[b, c,
11+
* ...]</code> contains the second, third, etc. elements of the cycle. The
12+
* algorithm uses an helper array to remember which elements have already been
13+
* encountered.
14+
* @param {Array} sigma The input permutation.
15+
* @param {Array} used The helper array.
16+
* @returns {Iterator} The cycles <code>[a, [b, c, ...]]</code> for sigma.
17+
*/
218
export function* _cycles ( sigma , used ) {
319

420
for ( const s of sigma ) {

src/_identity.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11

2+
/**
3+
* Fills an input array with the identity permutation on input <code>n</code>
4+
* elements.
5+
*
6+
* @param sigma The input array.
7+
* @param n The size to use for the permutation.
8+
*/
29
export function _identity ( sigma , n ) {
310

4-
for ( let i = 0 ; i < n ; ++i ) {
5-
6-
sigma[i] = i ;
7-
8-
}
11+
for ( let i = 0 ; i < n ; ++i ) sigma[i] = i ;
912

1013
}
1114

src/_invert.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
1+
/**
2+
* Fills an input array with the inverse <code>rho</code> of the input
3+
* permutation <code>sigma</code>, that is, the permutation such that
4+
* <code>compose(rho, sigma)</code> returns
5+
* <code>identity(sigma.length)</code>.
6+
*
7+
* @param {Array} sigma The input permutation.
8+
* @param {Number} n The size of the input permutation.
9+
* @param {Array} tau The array where to put the inverse of the input permutation.
10+
*/
211
export function _invert ( sigma , n , tau ) {
312

4-
for ( let i = 0 ; i < n ; ++i ) {
5-
6-
tau[sigma[i]] = i ;
7-
8-
}
13+
for ( let i = 0 ; i < n ; ++i ) tau[sigma[i]] = i ;
914

1015
}
1116

src/_invertcycles.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { _transpose } from './_transpose' ;
22

3+
/**
4+
* No idea what this does. Probably inverts the cycles of a given permutation.
5+
*
6+
* @param {Iterable} cycles The cycles to invert.
7+
* @param {Array} tau The given permutation.
8+
*/
39
export function _invertcycles ( cycles , tau ) {
410

511
for ( const [ s , cycle ] of cycles ) {

src/_itranspositions.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11

2+
/**
3+
* Really no idead what this does.
4+
*
5+
* @param {Array} sigma Input permutation.
6+
* @param {Array} used Helper array.
7+
* @return {Iterator} ?
8+
*/
29
export function* _itranspositions ( sigma , used ) {
310

411
for ( const s of sigma ) {

src/_next.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import { _transpose } from './_transpose' ;
22
import { _reverse } from './_reverse' ;
33

4+
/**
5+
* Updates the input permutation to the next one. Returns true unless the input
6+
* permutation is the last for its elements. In that case, the input permutation
7+
* remains untouched.
8+
*
9+
* @param {Array} sigma The input permutation.
10+
* @param {Number} n The size of the input permutation.
11+
* @returns {Boolean} Whether the input permutation is
12+
* <underline>NOT</underline> the last for its elements.
13+
*/
414
export function _next ( sigma , n ) {
515

616
let i = n - 1 ;

0 commit comments

Comments
 (0)