meteor/binary-heap/max-heap.js
function (data) {
    var self = this;

    self._heap = _.map(data, function (o) {
      return { id: o.id, value: o.value };
    });

    _.each(data, function (o, i) {
      self._heapIdx.set(o.id, i);
    });

    if (! data.length)
      return;

    // start from the first non-leaf - the parent of the last leaf
    for (var i = parentIdx(data.length - 1); i >= 0; i--)
      self._downHeap(i);
  }
function (data) {
    var self = this;

    self._heap = _.map(data, function (o) {
      return { id: o.id, value: o.value };
    });

    _.each(data, function (o, i) {
      self._heapIdx.set(o.id, i);
    });

    if (! data.length)
      return;

    // start from the first non-leaf - the parent of the last leaf
    for (var i = parentIdx(data.length - 1); i >= 0; i--)
      self._downHeap(i);
  }
function ( data ) { var self = this ; self . _heap = _ . map ( data , function ( o ) { return { id : o . id , value : o . value } ; } ) ; _ . each ( data , function ( o , i ) { self . _heapIdx . set ( o . id , i ) ; } ) ; if ( ! data . length ) return ; // start from the first non-leaf - the parent of the last leaf for ( var i = parentIdx ( data . length - 1 ) ; i >= 0 ; i -- ) self . _downHeap ( i ) ; }
Builds a new heap in-place in linear time based on passed data
Builds a new heap in - place in linear time based on passed data