-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- The benchmark for selector matching shows a 1.59x improvement over v3.2. - Represent the match types as an integer enum. Represent queries with minimal trees. Direct lookups are used when doing a match of a selector on an element, rather than checking all expressions in order. - Add more selector tests. - Update docs for newly enabled edge selectors with subjects, e.g. `$node -> node`. - Fixes `modules` tests. - Add JSDoc comments. Ref #2145, #2165
- Loading branch information
Showing
15 changed files
with
837 additions
and
640 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var Suite = require('./suite'); | ||
|
||
var eles; | ||
|
||
var suite = new Suite('eles.filter(selector)', { | ||
setup: function( cytoscape ){ | ||
var cy = cytoscape({ elements: require('./graphs/gal') }); | ||
|
||
eles = cy.nodes(); | ||
|
||
return cy; | ||
} | ||
}); | ||
|
||
suite | ||
.add( function( cy ) { | ||
// n.b. | ||
// - use a selector that matches all nodes so we really compare the selector matching rather than letting the matches exit early | ||
// - only create one selector : compare matching perf, not creation perf | ||
eles.filter('node:unselected:grabbable[gal80Rexp > 0][SUID > 0][Stress >= 5][AverageShortestPathLength > 0]'); | ||
}) | ||
; | ||
|
||
module.exports = suite; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// set this to run just a single suite via `gulp benchmark-single` | ||
// (useful when working on a specific function) | ||
var suite = require('../karger-stein'); | ||
var suite = require('../selector-filter'); | ||
|
||
suite.run({ async: true }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import * as is from '../is'; | ||
|
||
export const valCmp = (fieldVal, operator, value) => { | ||
let matches; | ||
let isFieldStr = is.string( fieldVal ); | ||
let isFieldNum = is.number( fieldVal ); | ||
let isValStr = is.string(value); | ||
let fieldStr, valStr; | ||
let caseInsensitive = false; | ||
let notExpr = false; | ||
let isIneqCmp = false; | ||
|
||
if( operator.indexOf( '!' ) >= 0 ){ | ||
operator = operator.replace( '!', '' ); | ||
notExpr = true; | ||
} | ||
|
||
if( operator.indexOf( '@' ) >= 0 ){ | ||
operator = operator.replace( '@', '' ); | ||
caseInsensitive = true; | ||
} | ||
|
||
if( isFieldStr || isValStr || caseInsensitive ){ | ||
fieldStr = !isFieldStr && !isFieldNum ? '' : '' + fieldVal; | ||
valStr = '' + value; | ||
} | ||
|
||
// if we're doing a case insensitive comparison, then we're using a STRING comparison | ||
// even if we're comparing numbers | ||
if( caseInsensitive ){ | ||
fieldVal = fieldStr = fieldStr.toLowerCase(); | ||
value = valStr = valStr.toLowerCase(); | ||
} | ||
|
||
switch( operator ){ | ||
case '*=': | ||
matches = fieldStr.indexOf( valStr ) >= 0; | ||
break; | ||
case '$=': | ||
matches = fieldStr.indexOf( valStr, fieldStr.length - valStr.length ) >= 0; | ||
break; | ||
case '^=': | ||
matches = fieldStr.indexOf( valStr ) === 0; | ||
break; | ||
case '=': | ||
matches = fieldVal === value; | ||
break; | ||
case '>': | ||
isIneqCmp = true; | ||
matches = fieldVal > value; | ||
break; | ||
case '>=': | ||
isIneqCmp = true; | ||
matches = fieldVal >= value; | ||
break; | ||
case '<': | ||
isIneqCmp = true; | ||
matches = fieldVal < value; | ||
break; | ||
case '<=': | ||
isIneqCmp = true; | ||
matches = fieldVal <= value; | ||
break; | ||
default: | ||
matches = false; | ||
break; | ||
} | ||
|
||
// apply the not op, but null vals for inequalities should always stay non-matching | ||
if( notExpr && ( fieldVal != null || !isIneqCmp ) ){ | ||
matches = !matches; | ||
} | ||
|
||
return matches; | ||
}; | ||
|
||
export const boolCmp = (fieldVal, operator) => { | ||
switch( operator ){ | ||
case '?': | ||
return fieldVal ? true : false; | ||
case '!': | ||
return fieldVal ? false : true; | ||
case '^': | ||
return fieldVal === undefined; | ||
} | ||
}; | ||
|
||
export const existCmp = (fieldVal) => fieldVal !== undefined; | ||
|
||
export const data = (ele, field) => ele.data(field); | ||
|
||
export const meta = (ele, field) => ele[field](); |
Oops, something went wrong.