From 6f6eede2b3e7e61d175beb22270b37ae40d7a3b7 Mon Sep 17 00:00:00 2001 From: electricessence Date: Tue, 4 Oct 2016 17:15:23 -0700 Subject: [PATCH 1/3] Cleanup. Spelling and minor inspection warnings. --- src/timsort.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/timsort.js b/src/timsort.js index 384d283..9753f04 100644 --- a/src/timsort.js +++ b/src/timsort.js @@ -4,7 +4,7 @@ const DEFAULT_MIN_MERGE = 32; /** - * Minimum ordered subsequece required to do galloping. + * Minimum ordered sub-sequence required to do galloping. */ const DEFAULT_MIN_GALLOPING = 7; @@ -18,7 +18,7 @@ const DEFAULT_TMP_STORAGE_LENGTH = 256; * Pre-computed powers of 10 for efficient lexicographic comparison of * small integers. */ -const POWERS_OF_TEN = [1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9] +const POWERS_OF_TEN = [1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9]; /** * Estimate the logarithm base 10 of a small integer. @@ -134,7 +134,7 @@ function minRunLength(n) { * descending sequence (run) starting at array[lo] in the range [lo, hi). If * the run is descending it is made ascending. * - * @param {array} array - The array to reverse. + * @param {Array} array - The array to reverse. * @param {number} lo - First element in the range (inclusive). * @param {number} hi - Last element in the range. * @param {function} compare - Item comparison function. @@ -167,7 +167,7 @@ function makeAscendingRun(array, lo, hi, compare) { /** * Reverse an array in the range [lo, hi). * - * @param {array} array - The array to reverse. + * @param {Array} array - The array to reverse. * @param {number} lo - First element in the range (inclusive). * @param {number} hi - Last element in the range. */ @@ -185,7 +185,7 @@ function reverseRun(array, lo, hi) { * Perform the binary sort of the array in the range [lo, hi) where start is * the first element possibly out of order. * - * @param {array} array - The array to sort. + * @param {Array} array - The array to sort. * @param {number} lo - First element in the range (inclusive). * @param {number} hi - Last element in the range. * @param {number} start - First element possibly out of order. @@ -251,7 +251,7 @@ function binaryInsertionSort(array, lo, hi, start, compare) { * (for stability). * * @param {number} value - Value to insert. - * @param {array} array - The array in which to insert value. + * @param {Array} array - The array in which to insert value. * @param {number} start - First element in the range. * @param {number} length - Length of the range. * @param {number} hint - The index at which to begin the search. @@ -330,7 +330,7 @@ function gallopLeft(value, array, start, length, hint, compare) { * (for stability). * * @param {number} value - Value to insert. - * @param {array} array - The array in which to insert value. + * @param {Array} array - The array in which to insert value. * @param {number} start - First element in the range. * @param {number} length - Length of the range. * @param {number} hint - The index at which to begin the search. @@ -567,7 +567,7 @@ class TimSort { let compare = this.compare; let array = this.array; let tmp = this.tmp; - let i = 0; + let i; for (i = 0; i < length1; i++) { tmp[i] = array[start1 + i]; @@ -728,7 +728,7 @@ class TimSort { let compare = this.compare; let array = this.array; let tmp = this.tmp; - let i = 0; + let i; for (i = 0; i < length2; i++) { tmp[i] = array[start2 + i]; @@ -737,8 +737,8 @@ class TimSort { let cursor1 = start1 + length1 - 1; let cursor2 = length2 - 1; let dest = start2 + length2 - 1; - let customCursor = 0; - let customDest = 0; + let customCursor; + let customDest; array[dest--] = array[cursor1--]; @@ -900,7 +900,7 @@ class TimSort { /** * Sort an array in the range [lo, hi) using TimSort. * - * @param {array} array - The array to sort. + * @param {Array} array - The array to sort. * @param {function=} compare - Item comparison function. Default is * alphabetical * @param {number} lo - First element in the range (inclusive). @@ -921,7 +921,8 @@ export function sort(array, compare, lo, hi) { } else if (typeof compare !== 'function') { hi = lo; - lo = compare; + //noinspection JSValidateTypes + lo = compare; compare = alphabeticalCompare; } From 0be8c80fb23ad7868eb9af35b0d837764120033f Mon Sep 17 00:00:00 2001 From: electricessence Date: Tue, 4 Oct 2016 17:23:50 -0700 Subject: [PATCH 2/3] Added default typings. --- index.d.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..e044e44 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,23 @@ +/*! + * @author electricessence / https://github.com/electricessence/ + */ + +declare module timsort +{ + declare export function sort( + array:any, + lo?:number, + hi?:number):void; + declare export function sort( + array:any, + compare:(a:any, b:any)=>number, + lo?:number, + hi?:number):void; + declare export function sort( + array:any, + compare:any, + lo?:number, + hi?:number):void; +} + +export = timsort; \ No newline at end of file From 243b956f7642847c426b2a3935452e29bb3dc6ab Mon Sep 17 00:00:00 2001 From: electricessence Date: Tue, 4 Oct 2016 17:25:22 -0700 Subject: [PATCH 3/3] Added default typings. --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 4b89427..0f70a65 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "timsort", - "version": "0.3.0", + "version": "0.3.1", "author": { "name": "Marco Ziccardi", "url": "http://mziccard.me/" @@ -8,6 +8,7 @@ "description": "TimSort: Fast Sorting for Node.js", "homepage": "https://github.com/mziccard/node-timsort", "main": "index.js", + "typings":"index.d.ts", "directories": { "test": "./test", "benchmark": "./benchmark"