Sha256: dbac67ad2abe3b1609a1c109fb0a946b06c2d6447ebc5a31d969a5aaf7300eda
Contents?: true
Size: 1.27 KB
Versions: 1
Compression:
Stored size: 1.27 KB
Contents
var heap = crossfilter.heap = heap_by(crossfilter_identity); heap.by = heap_by; function heap_by(f) { // Builds a binary heap within the specified array a[lo:hi]. The heap has the // property such that the parent a[lo+i] is always less than or equal to its // two children: a[lo+2*i+1] and a[lo+2*i+2]. function heap(a, lo, hi) { var n = hi - lo, i = (n >>> 1) + 1; while (--i > 0) sift(a, i, n, lo); return a; } // Sorts the specified array a[lo:hi] in descending order, assuming it is // already a heap. function sort(a, lo, hi) { var n = hi - lo, t; while (--n > 0) t = a[lo], a[lo] = a[lo + n], a[lo + n] = t, sift(a, 1, n, lo); return a; } // Sifts the element a[lo+i-1] down the heap, where the heap is the contiguous // slice of array a[lo:lo+n]. This method can also be used to update the heap // incrementally, without incurring the full cost of reconstructing the heap. function sift(a, i, n, lo) { var d = a[--lo + i], x = f(d), child; while ((child = i << 1) <= n) { if (child < n && f(a[lo + child]) > f(a[lo + child + 1])) child++; if (x <= f(a[lo + child])) break; a[lo + i] = a[lo + child]; i = child; } a[lo + i] = d; } heap.sort = sort; return heap; }
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mdarray-sol-0.1.0-java | node_modules/dc/node_modules/crossfilter2/src/heap.js |