cytoscape
Advanced tools
Comparing version 2.7.9 to 2.7.10
{ | ||
"name": "cytoscape", | ||
"version": "2.7.9", | ||
"version": "2.7.10", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Graph theory (a.k.a. network) library for analysis and visualisation", |
# Cytoscape.js | ||
[![Build Status](https://travis-ci.org/cytoscape/cytoscape.js.svg?branch=master)](https://travis-ci.org/cytoscape/cytoscape.js) [![Build Status](https://travis-ci.org/cytoscape/cytoscape.js.svg?branch=unstable)](https://travis-ci.org/cytoscape/cytoscape.js) | ||
*(master branch, unstable branch)* | ||
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/cytoscape/cytoscape.js/master/LICENSE) | ||
[![npm](https://img.shields.io/npm/v/cytoscape.svg?maxAge=2592000)](https://www.npmjs.com/package/cytoscape) | ||
[![npm installs](https://img.shields.io/npm/dt/cytoscape.svg?maxAge=2592000&label=npm installs)](https://www.npmjs.com/package/cytoscape) | ||
[![master branch tests](https://img.shields.io/travis/cytoscape/cytoscape.js/master.svg?maxAge=2592000&label=master%20branch)](https://travis-ci.org/cytoscape/cytoscape.js) | ||
[![unstable branch tests](https://img.shields.io/travis/cytoscape/cytoscape.js/unstable.svg?maxAge=2592000&label=unstable%20branch)](https://travis-ci.org/cytoscape/cytoscape.js) | ||
[![StackOverflow](https://img.shields.io/stackexchange/stackoverflow/t/cytoscape.js.svg?maxAge=2592000)](http://stackoverflow.com/questions/tagged/cytoscape.js) | ||
[![StackOverflow](https://img.shields.io/badge/ask%20question-on%20stackoverflow-brightgreen.svg?maxAge=2592000)](http://stackoverflow.com/questions/ask?tags=cytoscape.js) | ||
[![Gitter](https://img.shields.io/gitter/room/cytoscape/cytoscape.js.svg?maxAge=2592000)](https://gitter.im/cytoscape/cytoscape.js) | ||
@@ -35,3 +41,9 @@ | ||
## Roadmap | ||
Future versions of Cytoscape.js are planned in the [milestones of the Github issue tracker](https://github.com/cytoscape/cytoscape.js/milestones). You can use the milestones to see what's currently planned for future releases. | ||
## Contributing to Cytoscape.js | ||
@@ -38,0 +50,0 @@ |
@@ -722,2 +722,14 @@ 'use strict'; | ||
elesfn.recalculateRenderedStyle = function( useCache ){ | ||
var cy = this.cy(); | ||
var renderer = cy.renderer(); | ||
var styleEnabled = cy.styleEnabled(); | ||
if( renderer && styleEnabled ){ | ||
renderer.recalculateRenderedStyle( this, useCache ); | ||
} | ||
return this; | ||
}; | ||
elesfn.boundingBox = function( options ){ | ||
@@ -755,7 +767,6 @@ // the main usecase is ele.boundingBox() for a single element with no/def options | ||
var cy = eles.cy(); | ||
var renderer = eles.cy().renderer(); | ||
var styleEnabled = cy.styleEnabled(); | ||
if( styleEnabled ){ | ||
renderer.recalculateRenderedStyle( eles, opts.useCache ); | ||
this.recalculateRenderedStyle( opts.useCache ); | ||
} | ||
@@ -767,3 +778,3 @@ | ||
if( styleEnabled && ele.isEdge() && ele.pstyle('curve-style').strValue === 'bezier' ){ | ||
renderer.recalculateRenderedStyle( ele.parallelEdges(), opts.useCache ); // n.b. ele.parallelEdges() single is cached | ||
ele.parallelEdges().recalculateRenderedStyle( opts.useCache ); // n.b. ele.parallelEdges() single is cached | ||
} | ||
@@ -770,0 +781,0 @@ |
@@ -189,2 +189,3 @@ 'use strict'; | ||
|| ele.pstyle( 'display' ).value !== 'element' | ||
|| ele.pstyle('width').pfValue === 0 | ||
){ | ||
@@ -195,2 +196,4 @@ return false; | ||
if( ele._private.group === 'nodes' ){ | ||
if( ele.pstyle('height').pfValue === 0 ){ return false; } | ||
if( !hasCompoundNodes ){ return true; } | ||
@@ -197,0 +200,0 @@ |
@@ -27,2 +27,6 @@ 'use strict'; | ||
// exit if destroy() called on core or renderer in between frames #1499 | ||
// TODO first check this.isDestroyed() in >=3.1 #1440 | ||
if( !renderer ){ return; } | ||
renderer.notify( params ); | ||
@@ -29,0 +33,0 @@ }, |
@@ -116,2 +116,5 @@ 'use strict'; | ||
// the renderer can't be used for calcs when destroyed, e.g. ele.boundingBox() | ||
if( this.destroyed ){ return; } | ||
// use cache by default for perf | ||
@@ -129,16 +132,7 @@ if( useCache === undefined ){ useCache = true; } | ||
if( _p.group === 'nodes' ){ | ||
var pos = _p.position; | ||
nodes.push( ele ); | ||
rstyle.nodeX = pos.x; | ||
rstyle.nodeY = pos.y; | ||
rstyle.nodeW = ele.pstyle( 'width' ).pfValue; | ||
rstyle.nodeH = ele.pstyle( 'height' ).pfValue; | ||
} else { // edges | ||
edges.push( ele ); | ||
} | ||
} // if edges | ||
rstyle.clean = true; | ||
@@ -148,4 +142,18 @@ // rstyle.dirtyEvents = null; | ||
// update node data from projections | ||
for( var i = 0; i < nodes.length; i++ ){ | ||
var ele = nodes[i]; | ||
var _p = ele._private; | ||
var rstyle = _p.rstyle; | ||
var pos = _p.position; | ||
this.recalculateNodeLabelProjection( ele ); | ||
rstyle.nodeX = pos.x; | ||
rstyle.nodeY = pos.y; | ||
rstyle.nodeW = ele.pstyle( 'width' ).pfValue; | ||
rstyle.nodeH = ele.pstyle( 'height' ).pfValue; | ||
} | ||
this.recalculateEdgeProjections( edges ); | ||
this.recalculateLabelProjections( nodes, edges ); | ||
@@ -159,2 +167,4 @@ // update edge data from projections | ||
this.recalculateEdgeLabelProjections( ele ); | ||
// update rstyle positions | ||
@@ -1145,12 +1155,2 @@ rstyle.srcX = rs.arrowStartX; | ||
BRp.recalculateLabelProjections = function( nodes, edges ){ | ||
for( var i = 0; i < nodes.length; i++ ){ | ||
this.recalculateNodeLabelProjection( nodes[ i ] ); | ||
} | ||
for( var i = 0; i < edges.length; i++ ){ | ||
this.recalculateEdgeLabelProjections( edges[ i ] ); | ||
} | ||
}; | ||
BRp.recalculateEdgeProjections = function( edges ){ | ||
@@ -1157,0 +1157,0 @@ this.findEdgeControlPoints( edges ); |
@@ -87,2 +87,5 @@ 'use strict'; | ||
// the renderer can't be notified after it's destroyed | ||
if( this.destroyed ){ return; } | ||
if( is.array( params.type ) ){ | ||
@@ -89,0 +92,0 @@ types = params.type; |
@@ -25,2 +25,5 @@ 'use strict'; | ||
BRp.beforeRender = function( fn, priority ){ | ||
// the renderer can't add tick callbacks when destroyed | ||
if( this.destroyed ){ return; } | ||
priority = priority || 0; | ||
@@ -27,0 +30,0 @@ |
@@ -14,6 +14,3 @@ 'use strict'; | ||
// Edge line width | ||
if( edge.pstyle( 'width' ).pfValue <= 0 ){ | ||
return; | ||
} | ||
if( !edge.visible() ){ return; } | ||
@@ -20,0 +17,0 @@ var bb; |
@@ -21,2 +21,4 @@ 'use strict'; | ||
if( bb.w === 0 || bb.h === 0 ){ return; } | ||
if( !extent || math.boundingBoxesIntersect( bb, extent ) ){ | ||
@@ -75,2 +77,4 @@ var cache = r.data.eleTxrCache.getElement( ele, bb, pxRatio ); | ||
if( bb.w === 0 || bb.h === 0 ){ continue; } | ||
context.drawImage( layer.canvas, bb.x1, bb.y1, bb.w, bb.h ); | ||
@@ -77,0 +81,0 @@ } |
@@ -18,2 +18,6 @@ 'use strict'; | ||
if( !node.visible() ){ return; } | ||
var parentOpacity = node.effectiveOpacity(); | ||
var usePaths = this.usePaths(); | ||
@@ -23,5 +27,2 @@ var path; | ||
var parentOpacity = node.effectiveOpacity(); | ||
if( parentOpacity === 0 ){ return; } | ||
nodeWidth = node.width() + node.pstyle( 'padding-left' ).pfValue + node.pstyle( 'padding-right' ).pfValue; | ||
@@ -28,0 +29,0 @@ nodeHeight = node.height() + node.pstyle( 'padding-top' ).pfValue + node.pstyle( 'padding-bottom' ).pfValue; |
@@ -92,2 +92,4 @@ 'use strict'; | ||
if( bb.w === 0 || bb.h === 0 ){ return null; } | ||
if( lvl == null ){ | ||
@@ -94,0 +96,0 @@ lvl = Math.ceil( math.log2( zoom * pxRatio ) ); |
@@ -313,2 +313,5 @@ 'use strict'; | ||
var bb = ele.boundingBox(); | ||
if( bb.w === 0 || bb.h === 0 ){ return; } | ||
var eleCache = self.eleTxrCache; | ||
@@ -315,0 +318,0 @@ var reason = useHighQualityEleTxrReqs ? eleCache.reasons.highQuality : undefined; |
588
src/heap.js
@@ -17,380 +17,364 @@ /*! | ||
'use strict'; | ||
/* jshint ignore:start */ | ||
// Generated by CoffeeScript 1.8.0 | ||
(function(){ | ||
var Heap, defaultCmp, floor, heapify, heappop, heappush, heappushpop, heapreplace, insort, min, nlargest, nsmallest, updateItem, _siftdown, _siftup; | ||
floor = Math.floor, min = Math.min; | ||
var Heap, defaultCmp, floor, heapify, heappop, heappush, heappushpop, heapreplace, insort, min, nlargest, nsmallest, updateItem, _siftdown, _siftup; | ||
floor = Math.floor, min = Math.min; | ||
/* | ||
Default comparison function to be used | ||
*/ | ||
defaultCmp = function( x, y ){ | ||
if( x < y ){ | ||
return -1; | ||
} | ||
if( x > y ){ | ||
return 1; | ||
} | ||
return 0; | ||
}; | ||
/* | ||
Default comparison function to be used | ||
*/ | ||
defaultCmp = function( x, y ){ | ||
if( x < y ){ | ||
return -1; | ||
} | ||
if( x > y ){ | ||
return 1; | ||
} | ||
return 0; | ||
}; | ||
/* | ||
Insert item x in list a, and keep it sorted assuming a is sorted. | ||
If x is already in a, insert it to the right of the rightmost x. | ||
/* | ||
Insert item x in list a, and keep it sorted assuming a is sorted. | ||
Optional args lo (default 0) and hi (default a.length) bound the slice | ||
of a to be searched. | ||
*/ | ||
If x is already in a, insert it to the right of the rightmost x. | ||
insort = function( a, x, lo, hi, cmp ){ | ||
var mid; | ||
if( lo == null ){ | ||
lo = 0; | ||
Optional args lo (default 0) and hi (default a.length) bound the slice | ||
of a to be searched. | ||
*/ | ||
insort = function( a, x, lo, hi, cmp ){ | ||
var mid; | ||
if( lo == null ){ | ||
lo = 0; | ||
} | ||
if( cmp == null ){ | ||
cmp = defaultCmp; | ||
} | ||
if( lo < 0 ){ | ||
throw new Error( 'lo must be non-negative' ); | ||
} | ||
if( hi == null ){ | ||
hi = a.length; | ||
} | ||
while( lo < hi ){ | ||
mid = floor( (lo + hi) / 2 ); | ||
if( cmp( x, a[ mid ] ) < 0 ){ | ||
hi = mid; | ||
} else { | ||
lo = mid + 1; | ||
} | ||
if( cmp == null ){ | ||
cmp = defaultCmp; | ||
} | ||
if( lo < 0 ){ | ||
throw new Error( 'lo must be non-negative' ); | ||
} | ||
if( hi == null ){ | ||
hi = a.length; | ||
} | ||
while( lo < hi ){ | ||
mid = floor( (lo + hi) / 2 ); | ||
if( cmp( x, a[ mid ] ) < 0 ){ | ||
hi = mid; | ||
} else { | ||
lo = mid + 1; | ||
} | ||
} | ||
return ([].splice.apply( a, [ lo, lo - lo ].concat( x ) ), x); | ||
}; | ||
} | ||
return ([].splice.apply( a, [ lo, lo - lo ].concat( x ) ), x); | ||
}; | ||
/* | ||
Push item onto heap, maintaining the heap invariant. | ||
*/ | ||
/* | ||
Push item onto heap, maintaining the heap invariant. | ||
*/ | ||
heappush = function( array, item, cmp ){ | ||
if( cmp == null ){ | ||
cmp = defaultCmp; | ||
} | ||
array.push( item ); | ||
return _siftdown( array, 0, array.length - 1, cmp ); | ||
}; | ||
heappush = function( array, item, cmp ){ | ||
if( cmp == null ){ | ||
cmp = defaultCmp; | ||
} | ||
array.push( item ); | ||
return _siftdown( array, 0, array.length - 1, cmp ); | ||
}; | ||
/* | ||
Pop the smallest item off the heap, maintaining the heap invariant. | ||
*/ | ||
/* | ||
Pop the smallest item off the heap, maintaining the heap invariant. | ||
*/ | ||
heappop = function( array, cmp ){ | ||
var lastelt, returnitem; | ||
if( cmp == null ){ | ||
cmp = defaultCmp; | ||
} | ||
lastelt = array.pop(); | ||
if( array.length ){ | ||
returnitem = array[0]; | ||
array[0] = lastelt; | ||
_siftup( array, 0, cmp ); | ||
} else { | ||
returnitem = lastelt; | ||
} | ||
return returnitem; | ||
}; | ||
heappop = function( array, cmp ){ | ||
var lastelt, returnitem; | ||
if( cmp == null ){ | ||
cmp = defaultCmp; | ||
} | ||
lastelt = array.pop(); | ||
if( array.length ){ | ||
returnitem = array[0]; | ||
array[0] = lastelt; | ||
_siftup( array, 0, cmp ); | ||
} else { | ||
returnitem = lastelt; | ||
} | ||
return returnitem; | ||
}; | ||
/* | ||
Pop and return the current smallest value, and add the new item. | ||
/* | ||
Pop and return the current smallest value, and add the new item. | ||
This is more efficient than heappop() followed by heappush(), and can be | ||
more appropriate when using a fixed size heap. Note that the value | ||
returned may be larger than item! That constrains reasonable use of | ||
this routine unless written as part of a conditional replacement: | ||
if item > array[0] | ||
item = heapreplace(array, item) | ||
*/ | ||
This is more efficient than heappop() followed by heappush(), and can be | ||
more appropriate when using a fixed size heap. Note that the value | ||
returned may be larger than item! That constrains reasonable use of | ||
this routine unless written as part of a conditional replacement: | ||
if item > array[0] | ||
item = heapreplace(array, item) | ||
*/ | ||
heapreplace = function( array, item, cmp ){ | ||
var returnitem; | ||
if( cmp == null ){ | ||
cmp = defaultCmp; | ||
} | ||
returnitem = array[0]; | ||
array[0] = item; | ||
heapreplace = function( array, item, cmp ){ | ||
var returnitem; | ||
if( cmp == null ){ | ||
cmp = defaultCmp; | ||
} | ||
returnitem = array[0]; | ||
array[0] = item; | ||
_siftup( array, 0, cmp ); | ||
return returnitem; | ||
}; | ||
/* | ||
Fast version of a heappush followed by a heappop. | ||
*/ | ||
heappushpop = function( array, item, cmp ){ | ||
var _ref; | ||
if( cmp == null ){ | ||
cmp = defaultCmp; | ||
} | ||
if( array.length && cmp( array[0], item ) < 0 ){ | ||
_ref = [ array[0], item ], item = _ref[0], array[0] = _ref[1]; | ||
_siftup( array, 0, cmp ); | ||
return returnitem; | ||
}; | ||
} | ||
return item; | ||
}; | ||
/* | ||
Fast version of a heappush followed by a heappop. | ||
*/ | ||
/* | ||
Transform list into a heap, in-place, in O(array.length) time. | ||
*/ | ||
heappushpop = function( array, item, cmp ){ | ||
var _ref; | ||
if( cmp == null ){ | ||
cmp = defaultCmp; | ||
} | ||
if( array.length && cmp( array[0], item ) < 0 ){ | ||
_ref = [ array[0], item ], item = _ref[0], array[0] = _ref[1]; | ||
_siftup( array, 0, cmp ); | ||
} | ||
return item; | ||
}; | ||
heapify = function( array, cmp ){ | ||
var i, _i, _j, _len, _ref, _ref1, _results, _results1; | ||
if( cmp == null ){ | ||
cmp = defaultCmp; | ||
} | ||
_ref1 = (function(){ | ||
_results1 = []; | ||
for( var _j = 0, _ref = floor( array.length / 2 ); 0 <= _ref ? _j < _ref : _j > _ref; 0 <= _ref ? _j++ : _j-- ){ _results1.push( _j ); } | ||
return _results1; | ||
}).apply( this ).reverse(); | ||
_results = []; | ||
for( _i = 0, _len = _ref1.length; _i < _len; _i++ ){ | ||
i = _ref1[ _i ]; | ||
_results.push( _siftup( array, i, cmp ) ); | ||
} | ||
return _results; | ||
}; | ||
/* | ||
Transform list into a heap, in-place, in O(array.length) time. | ||
*/ | ||
/* | ||
Update the position of the given item in the heap. | ||
This function should be called every time the item is being modified. | ||
*/ | ||
heapify = function( array, cmp ){ | ||
var i, _i, _j, _len, _ref, _ref1, _results, _results1; | ||
if( cmp == null ){ | ||
cmp = defaultCmp; | ||
} | ||
_ref1 = (function(){ | ||
_results1 = []; | ||
for( var _j = 0, _ref = floor( array.length / 2 ); 0 <= _ref ? _j < _ref : _j > _ref; 0 <= _ref ? _j++ : _j-- ){ _results1.push( _j ); } | ||
return _results1; | ||
}).apply( this ).reverse(); | ||
_results = []; | ||
for( _i = 0, _len = _ref1.length; _i < _len; _i++ ){ | ||
i = _ref1[ _i ]; | ||
_results.push( _siftup( array, i, cmp ) ); | ||
} | ||
return _results; | ||
}; | ||
updateItem = function( array, item, cmp ){ | ||
var pos; | ||
if( cmp == null ){ | ||
cmp = defaultCmp; | ||
} | ||
pos = array.indexOf( item ); | ||
if( pos === -1 ){ | ||
return; | ||
} | ||
_siftdown( array, 0, pos, cmp ); | ||
return _siftup( array, pos, cmp ); | ||
}; | ||
/* | ||
Update the position of the given item in the heap. | ||
This function should be called every time the item is being modified. | ||
*/ | ||
/* | ||
Find the n largest elements in a dataset. | ||
*/ | ||
updateItem = function( array, item, cmp ){ | ||
var pos; | ||
if( cmp == null ){ | ||
cmp = defaultCmp; | ||
} | ||
pos = array.indexOf( item ); | ||
if( pos === -1 ){ | ||
return; | ||
} | ||
_siftdown( array, 0, pos, cmp ); | ||
return _siftup( array, pos, cmp ); | ||
}; | ||
nlargest = function( array, n, cmp ){ | ||
var elem, result, _i, _len, _ref; | ||
if( cmp == null ){ | ||
cmp = defaultCmp; | ||
} | ||
result = array.slice( 0, n ); | ||
if( !result.length ){ | ||
return result; | ||
} | ||
heapify( result, cmp ); | ||
_ref = array.slice( n ); | ||
for( _i = 0, _len = _ref.length; _i < _len; _i++ ){ | ||
elem = _ref[ _i ]; | ||
heappushpop( result, elem, cmp ); | ||
} | ||
return result.sort( cmp ).reverse(); | ||
}; | ||
/* | ||
Find the n largest elements in a dataset. | ||
*/ | ||
/* | ||
Find the n smallest elements in a dataset. | ||
*/ | ||
nlargest = function( array, n, cmp ){ | ||
var elem, result, _i, _len, _ref; | ||
if( cmp == null ){ | ||
cmp = defaultCmp; | ||
} | ||
result = array.slice( 0, n ); | ||
nsmallest = function( array, n, cmp ){ | ||
var elem, i, los, result, _i, _j, _len, _ref, _ref1, _results; | ||
if( cmp == null ){ | ||
cmp = defaultCmp; | ||
} | ||
if( n * 10 <= array.length ){ | ||
result = array.slice( 0, n ).sort( cmp ); | ||
if( !result.length ){ | ||
return result; | ||
} | ||
heapify( result, cmp ); | ||
los = result[ result.length - 1]; | ||
_ref = array.slice( n ); | ||
for( _i = 0, _len = _ref.length; _i < _len; _i++ ){ | ||
elem = _ref[ _i ]; | ||
heappushpop( result, elem, cmp ); | ||
} | ||
return result.sort( cmp ).reverse(); | ||
}; | ||
/* | ||
Find the n smallest elements in a dataset. | ||
*/ | ||
nsmallest = function( array, n, cmp ){ | ||
var elem, i, los, result, _i, _j, _len, _ref, _ref1, _results; | ||
if( cmp == null ){ | ||
cmp = defaultCmp; | ||
} | ||
if( n * 10 <= array.length ){ | ||
result = array.slice( 0, n ).sort( cmp ); | ||
if( !result.length ){ | ||
return result; | ||
if( cmp( elem, los ) < 0 ){ | ||
insort( result, elem, 0, null, cmp ); | ||
result.pop(); | ||
los = result[ result.length - 1]; | ||
} | ||
los = result[ result.length - 1]; | ||
_ref = array.slice( n ); | ||
for( _i = 0, _len = _ref.length; _i < _len; _i++ ){ | ||
elem = _ref[ _i ]; | ||
if( cmp( elem, los ) < 0 ){ | ||
insort( result, elem, 0, null, cmp ); | ||
result.pop(); | ||
los = result[ result.length - 1]; | ||
} | ||
} | ||
return result; | ||
} | ||
heapify( array, cmp ); | ||
_results = []; | ||
for( i = _j = 0, _ref1 = min( n, array.length ); 0 <= _ref1 ? _j < _ref1 : _j > _ref1; i = 0 <= _ref1 ? ++_j : --_j ){ | ||
_results.push( heappop( array, cmp ) ); | ||
} | ||
return _results; | ||
}; | ||
return result; | ||
} | ||
heapify( array, cmp ); | ||
_results = []; | ||
for( i = _j = 0, _ref1 = min( n, array.length ); 0 <= _ref1 ? _j < _ref1 : _j > _ref1; i = 0 <= _ref1 ? ++_j : --_j ){ | ||
_results.push( heappop( array, cmp ) ); | ||
} | ||
return _results; | ||
}; | ||
_siftdown = function( array, startpos, pos, cmp ){ | ||
var newitem, parent, parentpos; | ||
if( cmp == null ){ | ||
cmp = defaultCmp; | ||
_siftdown = function( array, startpos, pos, cmp ){ | ||
var newitem, parent, parentpos; | ||
if( cmp == null ){ | ||
cmp = defaultCmp; | ||
} | ||
newitem = array[ pos ]; | ||
while( pos > startpos ){ | ||
parentpos = (pos - 1) >> 1; | ||
parent = array[ parentpos ]; | ||
if( cmp( newitem, parent ) < 0 ){ | ||
array[ pos ] = parent; | ||
pos = parentpos; | ||
continue; | ||
} | ||
newitem = array[ pos ]; | ||
while( pos > startpos ){ | ||
parentpos = (pos - 1) >> 1; | ||
parent = array[ parentpos ]; | ||
if( cmp( newitem, parent ) < 0 ){ | ||
array[ pos ] = parent; | ||
pos = parentpos; | ||
continue; | ||
} | ||
break; | ||
} | ||
return array[ pos ] = newitem; | ||
}; | ||
break; | ||
} | ||
return array[ pos ] = newitem; | ||
}; | ||
_siftup = function( array, pos, cmp ){ | ||
var childpos, endpos, newitem, rightpos, startpos; | ||
if( cmp == null ){ | ||
cmp = defaultCmp; | ||
_siftup = function( array, pos, cmp ){ | ||
var childpos, endpos, newitem, rightpos, startpos; | ||
if( cmp == null ){ | ||
cmp = defaultCmp; | ||
} | ||
endpos = array.length; | ||
startpos = pos; | ||
newitem = array[ pos ]; | ||
childpos = 2 * pos + 1; | ||
while( childpos < endpos ){ | ||
rightpos = childpos + 1; | ||
if( rightpos < endpos && !(cmp( array[ childpos ], array[ rightpos ] ) < 0) ){ | ||
childpos = rightpos; | ||
} | ||
endpos = array.length; | ||
startpos = pos; | ||
newitem = array[ pos ]; | ||
array[ pos ] = array[ childpos ]; | ||
pos = childpos; | ||
childpos = 2 * pos + 1; | ||
while( childpos < endpos ){ | ||
rightpos = childpos + 1; | ||
if( rightpos < endpos && !(cmp( array[ childpos ], array[ rightpos ] ) < 0) ){ | ||
childpos = rightpos; | ||
} | ||
array[ pos ] = array[ childpos ]; | ||
pos = childpos; | ||
childpos = 2 * pos + 1; | ||
} | ||
array[ pos ] = newitem; | ||
return _siftdown( array, startpos, pos, cmp ); | ||
}; | ||
} | ||
array[ pos ] = newitem; | ||
return _siftdown( array, startpos, pos, cmp ); | ||
}; | ||
Heap = (function(){ | ||
Heap.push = heappush; | ||
Heap = (function(){ | ||
Heap.push = heappush; | ||
Heap.pop = heappop; | ||
Heap.pop = heappop; | ||
Heap.replace = heapreplace; | ||
Heap.replace = heapreplace; | ||
Heap.pushpop = heappushpop; | ||
Heap.pushpop = heappushpop; | ||
Heap.heapify = heapify; | ||
Heap.heapify = heapify; | ||
Heap.updateItem = updateItem; | ||
Heap.updateItem = updateItem; | ||
Heap.nlargest = nlargest; | ||
Heap.nlargest = nlargest; | ||
Heap.nsmallest = nsmallest; | ||
Heap.nsmallest = nsmallest; | ||
function Heap( cmp ){ | ||
this.cmp = cmp != null ? cmp : defaultCmp; | ||
this.nodes = []; | ||
} | ||
function Heap( cmp ){ | ||
this.cmp = cmp != null ? cmp : defaultCmp; | ||
this.nodes = []; | ||
} | ||
Heap.prototype.push = function( x ){ | ||
return heappush( this.nodes, x, this.cmp ); | ||
}; | ||
Heap.prototype.push = function( x ){ | ||
return heappush( this.nodes, x, this.cmp ); | ||
}; | ||
Heap.prototype.pop = function(){ | ||
return heappop( this.nodes, this.cmp ); | ||
}; | ||
Heap.prototype.pop = function(){ | ||
return heappop( this.nodes, this.cmp ); | ||
}; | ||
Heap.prototype.peek = function(){ | ||
return this.nodes[0]; | ||
}; | ||
Heap.prototype.peek = function(){ | ||
return this.nodes[0]; | ||
}; | ||
Heap.prototype.contains = function( x ){ | ||
return this.nodes.indexOf( x ) !== -1; | ||
}; | ||
Heap.prototype.contains = function( x ){ | ||
return this.nodes.indexOf( x ) !== -1; | ||
}; | ||
Heap.prototype.replace = function( x ){ | ||
return heapreplace( this.nodes, x, this.cmp ); | ||
}; | ||
Heap.prototype.replace = function( x ){ | ||
return heapreplace( this.nodes, x, this.cmp ); | ||
}; | ||
Heap.prototype.pushpop = function( x ){ | ||
return heappushpop( this.nodes, x, this.cmp ); | ||
}; | ||
Heap.prototype.pushpop = function( x ){ | ||
return heappushpop( this.nodes, x, this.cmp ); | ||
}; | ||
Heap.prototype.heapify = function(){ | ||
return heapify( this.nodes, this.cmp ); | ||
}; | ||
Heap.prototype.heapify = function(){ | ||
return heapify( this.nodes, this.cmp ); | ||
}; | ||
Heap.prototype.updateItem = function( x ){ | ||
return updateItem( this.nodes, x, this.cmp ); | ||
}; | ||
Heap.prototype.updateItem = function( x ){ | ||
return updateItem( this.nodes, x, this.cmp ); | ||
}; | ||
Heap.prototype.clear = function(){ | ||
return this.nodes = []; | ||
}; | ||
Heap.prototype.clear = function(){ | ||
return this.nodes = []; | ||
}; | ||
Heap.prototype.empty = function(){ | ||
return this.nodes.length === 0; | ||
}; | ||
Heap.prototype.empty = function(){ | ||
return this.nodes.length === 0; | ||
}; | ||
Heap.prototype.size = function(){ | ||
return this.nodes.length; | ||
}; | ||
Heap.prototype.size = function(){ | ||
return this.nodes.length; | ||
}; | ||
Heap.prototype.clone = function(){ | ||
var heap; | ||
heap = new Heap(); | ||
heap.nodes = this.nodes.slice( 0 ); | ||
return heap; | ||
}; | ||
Heap.prototype.clone = function(){ | ||
var heap; | ||
heap = new Heap(); | ||
heap.nodes = this.nodes.slice( 0 ); | ||
return heap; | ||
}; | ||
Heap.prototype.toArray = function(){ | ||
return this.nodes.slice( 0 ); | ||
}; | ||
Heap.prototype.toArray = function(){ | ||
return this.nodes.slice( 0 ); | ||
}; | ||
Heap.prototype.insert = Heap.prototype.push; | ||
Heap.prototype.insert = Heap.prototype.push; | ||
Heap.prototype.top = Heap.prototype.peek; | ||
Heap.prototype.top = Heap.prototype.peek; | ||
Heap.prototype.front = Heap.prototype.peek; | ||
Heap.prototype.front = Heap.prototype.peek; | ||
Heap.prototype.has = Heap.prototype.contains; | ||
Heap.prototype.has = Heap.prototype.contains; | ||
Heap.prototype.copy = Heap.prototype.clone; | ||
Heap.prototype.copy = Heap.prototype.clone; | ||
return Heap; | ||
return Heap; | ||
})(); | ||
})(); | ||
(function( root, factory ){ | ||
if( typeof define === 'function' && define.amd ){ // eslint-disable-line no-undef | ||
return define( [], factory ); // eslint-disable-line no-undef | ||
} else if( typeof exports === 'object' ){ | ||
return module.exports = factory(); | ||
} else { | ||
return root.Heap = factory(); | ||
} | ||
})( this, function(){ | ||
return Heap; | ||
} ); | ||
}).call( this ); | ||
/* jshint ignore:end */ | ||
module.exports = Heap; |
@@ -1,1 +0,1 @@ | ||
"2.7.9" | ||
"2.7.10" |
732269
21238
107