@aureooms/js-odd-even-mergesort

2.0.0 • Public • Published

@aureooms/js-odd-even-mergesort

Batcher's odd-even mergesort algorithm for JavaScript. See docs. Parent is @aureooms/js-sort.

import { whole } from '@aureooms/js-odd-even-mergesort' ;
import { list } from '@aureooms/js-itertools' ;
import { increasing } from '@aureooms/js-compare' ;
import { swap } from '@aureooms/js-array' ;
let modules = list( whole( 4 ) ) ;
modules ; // [ [ 0 , 1 ] , [ 2 , 3 ] , [ 0 , 2 ] , [ 1 , 3 ] , [ 1 , 2 ] ]

let a = [ 3 , 1 , 2 , 4 ] ;
for ( let [ i , j ] of modules ) if ( increasing( a[i] , a[j] ) > 0 ) swap( a , i , j ) ;

// 3 ----1------1----------- 1
//       |      |
// 1 ----3------|-3----2---- 2
//              | |    |
// 2 ------2----2-|----3---- 3
//         |      |
// 4 ------4------4--------- 4

a ; // [ 1 , 2 , 3 , 4 ]

NPM license NPM version Build Status Coverage Status Dependencies Status devDependencies Status Code Climate NPM downloads per month GitHub issues Documentation

Package Sidebar

Install

npm i @aureooms/js-odd-even-mergesort

Weekly Downloads

7

Version

2.0.0

License

AGPL-3.0

Last publish

Collaborators

  • aureooms