Skip to content

giacomociti/external-merge-sort

Repository files navigation

External Merge Sort

NPM Version

Implementation of external merge sort based on async generators. The sort function takes an iterable and returns an async generator yielding the input values sorted. It relies on a merge function which can also be useful on its own, in case you want to merge two or more iterables already sorted.

Usage

import { sort } from 'external-merge-sort'

const sorted = sort([3,1,2])

for await (const item of sorted) {
  console.log(item)
}

the simple usage above is not that useful in practice: the iterable input normally comes from a big file stream and you need to provide additional options to specify:

  • maxSize: the size of chunks in which to split the input
  • maxFiles: threshold to trigger an additional pass (usually not needed)
  • comparer: a custom comparison function
  • store: an object capable to write chunks to temporary storage, returning an iterable over stored items

See examples with text, json and rdf files.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •