diff --git a/README.md b/README.md index 5c21e93..7bf2844 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,10 @@ Parent is [@aureooms/js-algorithms](https://github.com/aureooms/js-algorithms). > working. Documentation may be present. Coherence may be. Maybe. ```js -let fordjohnson = sort._fordjohnson( search.binarysearch ) ; +import {isSorted} from '@aureooms/js-sort'; +import {increasing, decreasing} from '@aureooms/js-compare'; +isSorted(increasing, [1, 2, 3], 0, 3); // true +isSorted(decreasing, [1, 2, 3], 0, 3); // false ``` [![License](https://img.shields.io/github/license/aureooms/js-sort.svg)](https://raw.githubusercontent.com/aureooms/js-sort/master/LICENSE) @@ -39,6 +42,7 @@ This package has several children: - [aureooms/js-heapsort](https://github.com/aureooms/js-heapsort): heapsort for JavaScript - [aureooms/js-quicksort](https://github.com/aureooms/js-quicksort): quicksort for JavaScript - [aureooms/js-insertion-sort](https://github.com/aureooms/js-insertion-sort): Insertion sorting algorithms for JavaScript + - [aureooms/js-merge-insertion-sort](https://github.com/aureooms/js-merge-insertion-sort): Ford-Johnson algorithm for JavaScript - [aureooms/js-mergesort](https://github.com/aureooms/js-mergesort): mergesort for JavaScript - [aureooms/js-odd-even-mergesort](https://github.com/aureooms/js-odd-even-mergesort): Batcher's odd-even mergesort for JavaScript - [aureooms/js-radix-sort](https://github.com/aureooms/js-radix-sort): Radix sorting algorithms for JavaScript diff --git a/doc/manual/example.md b/doc/manual/example.md index acb9056..e770044 100644 --- a/doc/manual/example.md +++ b/doc/manual/example.md @@ -1,29 +1,23 @@ # Examples ```js -import array from "@aureooms/js-array" ; -import search from "@aureooms/js-search" ; -import compare from "@aureooms/js-compare" ; - -let fordjohnson = function ( compare , a , i , j ) { - - sort._fordjohnson( search.binarysearch )( compare , array.swap , a , i , j ) ; - -} ; +import * as sort from "@aureooms/js-sort" ; +import {increasing, decreasing} from "@aureooms/js-compare" ; let a = [ 1 , 6 , 5 , 3 , 2 , 4 ] ; +let {selectionsort, isSorted} = sort; -fordjohnson( compare.increasing , a , 0 , a.length ) ; +selectionsort( increasing , a , 0 , a.length ) ; a ; // [ 1 , 2 , 3 , 4 , 5 , 6 ] +isSorted(increasing, a, 0, a.length); // true -fordjohnson( compare.decreasing , a , 0 , a.length ) ; +selectionsort( decreasing , a , 0 , a.length ) ; a ; // [ 6 , 5 , 4 , 3 , 2 , 1 ] +isSorted(decreasing, a, 0, a.length); // true // but also -/** selectionsort */ -let selectionsort = sort.selectionsort ; /** bubblesort */ -let bubblesort = sort.bubblesort ; +let {bubblesort} = sort ; ``` diff --git a/package.json b/package.json index 469f0bf..6c5fb20 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,6 @@ "@aureooms/js-in-situ-sort-spec": "8.0.0", "@aureooms/js-itertools": "4.1.0", "@aureooms/js-random": "2.0.0", - "@aureooms/js-search": "0.0.4", "@babel/cli": "7.11.6", "@babel/core": "7.11.6", "@babel/preset-env": "7.11.5", diff --git a/src/sort/fordjohnson.js b/src/sort/fordjohnson.js deleted file mode 100644 index b57ed47..0000000 --- a/src/sort/fordjohnson.js +++ /dev/null @@ -1,93 +0,0 @@ - -export function _fordjohnson ( binarysearch ) { - - const fordjohnson = function ( compare , swap , a , i , j ) { - - var m , k , t , y , p , q , r , x , l , w , s , pairswap ; - - if ( j - i < 2 ) return ; - - k = m = ( j - i ) / 2 | 0 ; - - // compare pairs of elements and put largest elements at the front of the - // array - - while ( k-- ) { - - if ( compare( a[i+k] , a[i+m+k] ) < 0 ) { - - swap( a , i + k , i + m + k ) ; - - } - - } - - // sort the largest elements at the front recursively - - pairswap = function ( a , i , j ) { - swap( a , i , j ) ; - swap( a , i + m , j + m ) ; - } ; - - fordjohnson( compare , pairswap , a , i , i + m ) ; - - // merge the rest of the array into the front, one item at a time - - p = y = t = 1 ; - - q = 0 ; - - while ( i + m + t <= j ) { - - r = t ; - - while ( r --> q ) { - - w = a[i+m+t-1] ; - - x = binarysearch( compare , a , i , i + m + q , w ) ; - l = x[0] + x[1] ; - - s = i + m + t ; - - while ( --s > l ) { - - swap( a , s , s - 1 ) ; - - } - - } - - q = t ; - - p *= 2 ; - y = p - 2 * t ; - t += y ; - - } - - r = j - i - m ; - - while ( r --> q ) { - - w = a[j-1] ; - - x = binarysearch( compare , a , i , i + m + q , w ) ; - l = x[0] + x[1] ; - - s = j ; - - while ( --s > l ) { - - swap( a , s , s - 1 ) ; - - } - - - } - - } ; - - return fordjohnson ; - -} diff --git a/src/sort/index.js b/src/sort/index.js index 3ab9420..7967af1 100644 --- a/src/sort/index.js +++ b/src/sort/index.js @@ -1,3 +1,2 @@ export * from './bubblesort' ; -export * from './fordjohnson' ; export * from './selectionsort' ; diff --git a/test/src/inplacesort.js b/test/src/inplacesort.js index c5a5f83..8611737 100644 --- a/test/src/inplacesort.js +++ b/test/src/inplacesort.js @@ -1,14 +1,9 @@ import ava from 'ava' ; -import { swap } from "@aureooms/js-array" ; -import { binarysearch } from "@aureooms/js-search" ; import * as spec from "@aureooms/js-in-situ-sort-spec" ; import * as sort from "../../src" ; spec.test( ava , [ [ "selectionsort", sort.selectionsort ], - [ "bubblesort", sort.bubblesort ], - [ "fordjohnson" , function ( compare , a , i , j ) { - sort._fordjohnson( binarysearch )( compare , swap , a , i , j ) ; - } ] + [ "bubblesort", sort.bubblesort ] ] ) ; diff --git a/test/src/whole.js b/test/src/whole.js index 03b9985..e385271 100644 --- a/test/src/whole.js +++ b/test/src/whole.js @@ -1,7 +1,6 @@ import test from 'ava' ; import { iota , swap } from "@aureooms/js-array" ; -import search from "@aureooms/js-search" ; import { shuffle } from "@aureooms/js-random" ; import * as compare from "@aureooms/js-compare" ; import * as itertools from "@aureooms/js-itertools" ; @@ -51,13 +50,7 @@ itertools.product( [ [ [ "selectionsort", sort.selectionsort ], - [ "bubblesort", sort.bubblesort ], - [ "fordjohnson" , function ( compare , a , i , j ) { - - sort._fordjohnson( search.binarysearch )( compare , swap , a , i , j ) ; - - } ] - + [ "bubblesort", sort.bubblesort ] ], [ diff --git a/yarn.lock b/yarn.lock index 614a92d..c7cf39b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -54,11 +54,6 @@ resolved "https://registry.yarnpkg.com/@aureooms/js-random/-/js-random-2.0.0.tgz#f62c6954ed79bd9a520197125ee3cfbe14b00d72" integrity sha1-9ixpVO15vZpSAZcSXuPPvhSwDXI= -"@aureooms/js-search@0.0.4": - version "0.0.4" - resolved "https://registry.yarnpkg.com/@aureooms/js-search/-/js-search-0.0.4.tgz#e7082a7de169c80710924f5292b631a2c1bb9a41" - integrity sha1-5wgqfeFpyAcQkk9SkrYxosG7mkE= - "@aureooms/js-sort@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/@aureooms/js-sort/-/js-sort-7.0.0.tgz#db3c8b93acd93ee0500462b2cec29239c3deb34d"