Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

arrayslicer

gabmontes3k1.2.3

Node.JS module that implements an optimized binary search over a given array of objects

array, search, binary, slice

readme

Array Slicer

Node.JS module that implements an optimized binary search over a given array of objects.

Quick example

var IndexedArray = require("arrayslicer");

var ia = new IndexedArray([{num: 1}, {num: 2}, {num: 5}], "num");

ia.fetch(2); // ia.cursor is set to 1
ia.get(1); // -> {num: 1}
ia.getRange(2, 5); // -> [{num: 2}, {num: 5}]

Install

npm install arrayslicer

API

IndexedArray(array, index)

Creates a new IndexedArray object based on array and indexed by the property index.

IndexedArray.sort()

Sort the IndexedArray by its index property. This is needed to ensure the values are retrieved properly.

IndexedArray.fetch(value)

Sets the internal pointer of the IndexedArray, called cursor, to the element with index equal value.

If there are no matching elements, the properties nexthigh and nextlow are set to the nearest indexes to value.

IndexedArray.get(value)

Gets the element with index equal value.

If there are no matching elements, the function will return null.

IndexedArray.get(begin, end)

Returns an array containing all the elements within begin and end, including both values if exact matches are found within the data.

IndexedArray.setCompare(fn)

Use a custom compare function.

IndexedArray.setSort(fn)

Use a custom sort function.

Licence

WTFPL

changelog

v1.2.3 - oct 08 2014
  • Fixed bug when searching for numeric indexes.
v1.2.2 - aug 14 2014
  • Fixed bug on internal cache population.
v1.2.1 - jul 31 2014
  • Fixed bug when getting a range around the last element.
v1.2.0 - jul 30 2014
  • Major changes in the behavior of getRange. Breaks compatibility with previous versions.
v1.1.0 - jun 17 2014
  • getRange will always return Array objects.
v1.0.1 - sep 30 2013
  • Initial version.