Skip to content

Commit c9841ae

Browse files
♻️ refactor: Improve docstrings and simplify some trivial generators.
1 parent 36a2fb4 commit c9841ae

25 files changed

+38
-44
lines changed

src/_bitreversal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* power of <code>2</code>.
66
*
77
* @param {Array} array The array to fill.
8-
* @param {Number} n The size of the permutation, must be a power of 2.
8+
* @param {number} n The size of the permutation, must be a power of 2.
99
*/
1010
export function _bitreversal(array, n) {
1111
let i = 1;

src/_compose.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* @param {Array} sigma The first input permutation.
66
* @param {Array} tau The second input permutation.
7-
* @returns {Iterator} An iterator over the items of the resulting permutation.
7+
* @returns {IterableIterator} An iterator over the items of the resulting permutation.
88
*/
99
export function* _compose(sigma, tau) {
1010
for (const t of tau) yield sigma[t];

src/_copy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copy an input permutation to an output array.
33
*
44
* @param {Array} sigma The input permutation.
5-
* @param {Number} n The size of the input permutation to copy.
5+
* @param {number} n The size of the input permutation to copy.
66
* @param {Array} tau The output array.
77
*/
88
export function _copy(sigma, n, tau) {

src/_cycles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
* @param {Array} sigma The input permutation.
1616
* @param {Array} used The helper array.
17-
* @returns {Iterator} The cycles <code>[a, [b, c, ...]]</code> for sigma.
17+
* @returns {IterableIterator} The cycles <code>[a, [b, c, ...]]</code> for sigma.
1818
*/
1919
export function* _cycles(sigma, used) {
2020
for (const s of sigma) {

src/_identity.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* elements.
44
*
55
* @param {Array} sigma The input array.
6-
* @param {Number} n The size to use for the permutation.
6+
* @param {number} n The size to use for the permutation.
77
*/
88
export function _identity(sigma, n) {
99
for (let i = 0; i < n; ++i) sigma[i] = i;

src/_invert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* API.
77
*
88
* @param {Array} sigma The input permutation.
9-
* @param {Number} n The size of the input permutation.
9+
* @param {number} n The size of the input permutation.
1010
* @param {Array} tau The array where to put the inverse of the input permutation.
1111
*/
1212
export function _invert(sigma, n, tau) {

src/_itranspositions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* @param {Array} sigma Input permutation.
88
* @param {Array} used Helper array.
9-
* @return {Iterator} Iterator over the transpositions.
9+
* @return {IterableIterator} Iterator over the transpositions.
1010
*/
1111
export function* _itranspositions(sigma, used) {
1212
for (const s of sigma) {

src/_next.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {_reverse} from './_reverse.js';
77
* input permutation remains untouched.
88
*
99
* @param {Array} sigma The input permutation (modified in-place).
10-
* @param {Number} n The size of the input permutation.
10+
* @param {number} n The size of the input permutation.
1111
* @returns {Boolean} Whether the input permutation is
1212
* __NOT__ the last for its elements.
1313
*/

src/_permutations.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {_next} from './_next.js';
55
* permutation.
66
*
77
* @param {Array} sigma The starting permutation.
8-
* @param {Number} n The size of the permutation.
9-
* @returns {Iterator} Iterator over all permutations between the starting one
8+
* @param {number} n The size of the permutation.
9+
* @returns {IterableIterator} Iterator over all permutations between the starting one
1010
* and the last permutation on its elements.
1111
*/
1212
export function* _permutations(sigma, n) {

src/_reverse.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {_transpose} from './_transpose.js';
55
* (include) to input index <code>j</code> (excluded).
66
*
77
* @param {Array} sigma The input permutation to reverse (modified in-place).
8-
* @param {Number} i The left bound (included).
9-
* @param {Number} j The right bound (excluded).
8+
* @param {number} i The left bound (included).
9+
* @param {number} j The right bound (excluded).
1010
*/
1111
export function _reverse(sigma, i, j) {
1212
while (i < --j) _transpose(i++, j, sigma);

src/_transpose.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* Transpose elements of input index <code>a</code> and <code>b</code> in the
33
* input permutation.
44
*
5-
* @param {Number} a The first input index.
6-
* @param {Number} b The second input index.
5+
* @param {number} a The first input index.
6+
* @param {number} b The second input index.
77
* @param {Array} sigma The input permutation.
88
*/
99
export function _transpose(a, b, sigma) {

src/_transposition.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* Transposes <code>a</code> with <code>b</code> in <code>sigma</code> provided
44
* <code>sigma[a] === a</code> and <code>sigma[b] === b</code>.
55
*
6-
* @param {Number} a First index.
7-
* @param {Number} b Second index.
6+
* @param {number} a First index.
7+
* @param {number} b Second index.
88
* @param {Array} sigma Input permutation.
99
*/
1010
export function _transposition(a, b, sigma) {

src/_transpositions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* Computes the transposition decomposition of some permutation given its cycle
33
* decomposition.
44
*
5-
* @param {Array} cycles The cycle decomposition of some permutation.
6-
* @returns {Iterator} The transposition decomposition of the permutation
5+
* @param {Iterable} cycles The cycle decomposition of some permutation.
6+
* @returns {IterableIterator} The transposition decomposition of the permutation
77
* defined by the input cycles.
88
*/
99
export function* _transpositions(cycles) {

src/_used.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* example, for computing the cycle decomposition of an input permutation (see
66
* {@link _cycles}, {@link cycles}).
77
*
8-
* @param {Number} n The given size.
8+
* @param {number} n The given size.
99
* @param {Array} array The input array.
1010
*/
1111
export function _used(n, array) {

src/apply.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {_apply} from './_apply.js';
55
* Apply a given sequence (in the given order) of transpositions (given as
66
* index tuples) to the identity permutation over input <code>n</code> elements.
77
*
8-
* @param {Number} n The size of the identity permutation to apply the transpositions
8+
* @param {number} n The size of the identity permutation to apply the transpositions
99
* to.
1010
* @param {Iterable} transpositions The given transpositions to apply.
1111
* @returns {Array} The resulting permutation.

src/bitreversal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {_bitreversal} from './_bitreversal.js';
66
* input <code>n</code> items. Note that <code>n</code> MUST be a power of
77
* <code>2</code>.
88
*
9-
* @param {Number} n The size of the permutation, must be a power of
9+
* @param {number} n The size of the permutation, must be a power of
1010
* <code>2</code>.
1111
* @returns {Array} The bitreversal permutation of size <code>n</code>.
1212
*/

src/cycles.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import {used} from './used.js';
77
* See {@link _cycles} for implementation.
88
*
99
* @param {Array} sigma The input permutation.
10-
* @returns {Iterator} The cycles <code>[a, [b, c, ...]]</code> for sigma.
10+
* @returns {IterableIterator} The cycles <code>[a, [b, c, ...]]</code> for sigma.
1111
*/
12-
export function* cycles(sigma) {
13-
yield* _cycles(sigma, used(sigma.length));
14-
}
12+
export const cycles = (sigma) => _cycles(sigma, used(sigma.length));

src/identity.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {_identity} from './_identity.js';
44
/**
55
* Returns the identity permutation of a given size.
66
*
7-
* @param {Number} n The size of the permutation to return.
7+
* @param {number} n The size of the permutation to return.
88
* @returns {Array} The identity permutation on <code>n</code> elements.
99
*/
1010
export function identity(n) {

src/itranspositions.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import {used} from './used.js';
1010
* const invert = sigma => apply( sigma.length , itranspositions( sigma ) ) ;
1111
*
1212
* @param {Array} sigma Input permutation.
13-
* @return {Iterator} Iterator over the transpositions.
13+
* @return {IterableIterator} Iterator over the transpositions.
1414
*/
15-
export function* itranspositions(sigma) {
16-
yield* _itranspositions(sigma, used(sigma.length));
17-
}
15+
export const itranspositions = (sigma) =>
16+
_itranspositions(sigma, used(sigma.length));

src/permutation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Allocates a new permutation of given input size.
33
*
4-
* @param {Number} n The size of the permutation to allocate.
4+
* @param {number} n The size of the permutation to allocate.
55
* @returns {Array} The allocated permutation.
66
*/
77
export function permutation(n) {

src/permutations.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {copy} from './copy.js';
55
/**
66
* Generate all permutations on <code>n</code> elements.
77
*
8-
* @param {Number} n The size of the permutations to generate.
9-
* @returns {Iterator} Iterator that yields all permutations on <code>n</code>
8+
* @param {number} n The size of the permutations to generate.
9+
* @returns {IterableIterator} Iterator that yields all permutations on <code>n</code>
1010
* elements.
1111
*/
1212
export function* permutations(n) {

src/transpose.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {_transpose} from './_transpose.js';
66
* then returns the result.
77
*
88
* @param {Array} sigma The input permutation.
9-
* @param {Number} a The first index of the transpose.
10-
* @param {Number} b The second index of the transpose.
9+
* @param {number} a The first index of the transpose.
10+
* @param {number} b The second index of the transpose.
1111
* @returns {Array} The result.
1212
*/
1313
export function transpose(sigma, a, b) {

src/transposition.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import {_transposition} from './_transposition.js';
55
* Outputs the permutation on input <code>n</code> numbers that only transposes
66
* two input elements <code>a</code> and <code>b</code>.
77
*
8-
* @param {Number} n The size of the permutation to output.
9-
* @param {Number} a The first index to swap.
10-
* @param {Number} b The second index to swap.
8+
* @param {number} n The size of the permutation to output.
9+
* @param {number} a The first index to swap.
10+
* @param {number} b The second index to swap.
1111
* @returns {undefined}
1212
*/
1313
export function transposition(n, a, b) {

src/transpositions.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import {_transpositions} from './_transpositions.js';
22
import {cycles} from './cycles.js';
3-
import {used} from './used.js';
43

54
/**
65
* Computes the transposition decomposition of the input permutation as an
76
* Iterator.
87
*
98
* @param {Array} sigma The input permutation.
10-
* @returns {Iterator} The transposition decomposition of <code>sigma</code>.
9+
* @returns {IterableIterator} The transposition decomposition of <code>sigma</code>.
1110
*/
12-
export function* transpositions(sigma) {
13-
yield* _transpositions(cycles(sigma, used(sigma.length)));
14-
}
11+
export const transpositions = (sigma) => _transpositions(cycles(sigma));

src/used.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {_used} from './_used.js';
33
/**
44
* Generates an helper array of given size (used in {@link _cycle}, {@link cycle}).
55
*
6-
* @param {Number} n The given size.
6+
* @param {number} n The given size.
77
* @returns {Array} The helper array of prescribed size.
88
*/
99
export function used(n) {

0 commit comments

Comments
 (0)