@buggyorg/graphtools
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -311,3 +311,3 @@ 'use strict'; | ||
if (!isCompoundable(g, subset)) { | ||
throw new Error('This subset cannot be compoundified given this particular subset.' + JSON.stringify(origSubset)); | ||
throw new Error('This subset cannot be compoundified given this particular subset.\n' + JSON.stringify(origSubset)); | ||
} | ||
@@ -314,0 +314,0 @@ var graph = _api.graph.clone(g); |
@@ -46,4 +46,4 @@ 'use strict'; | ||
*/ | ||
function predecessor(graph, node, port) { | ||
return utils.isNPG(graph) ? walkNPG.predecessor(graph, node, port) : walkNG.predecessor(graph, node, port); | ||
function predecessor(graph, node, port, options) { | ||
return utils.isNPG(graph) ? walkNPG.predecessor(graph, node, port, options) : walkNG.predecessor(graph, node, port, options); | ||
} | ||
@@ -60,4 +60,4 @@ | ||
*/ | ||
function successor(graph, node, port) { | ||
return utils.isNPG(graph) ? walkNPG.successor(graph, node, port) : walkNG.successor(graph, node, port); | ||
function successor(graph, node, port, options) { | ||
return utils.isNPG(graph) ? walkNPG.successor(graph, node, port, options) : walkNG.successor(graph, node, port, options); | ||
} | ||
@@ -89,3 +89,3 @@ | ||
return generalWalk(graph, node, path, successor, options); | ||
return generalWalk(graph, node, path, _lodash2.default.partial(successor, _lodash2.default, _lodash2.default, _lodash2.default, options), options); | ||
} | ||
@@ -117,3 +117,3 @@ | ||
return _lodash2.default.map(generalWalk(graph, node, path, predecessor, options), _lodash2.default.reverse); | ||
return _lodash2.default.map(generalWalk(graph, node, path, _lodash2.default.partial(predecessor, _lodash2.default, _lodash2.default, _lodash2.default, options), options), _lodash2.default.reverse); | ||
} | ||
@@ -120,0 +120,0 @@ |
@@ -83,10 +83,11 @@ 'use strict'; | ||
function successor(graph, node, port) { | ||
function successor(graph, node, port, options) { | ||
var edge = { from: node, outPort: port }; | ||
return neighbor(graph, node, port, _lodash2.default.partial(getSuccessorWithCheck, graph, _lodash2.default, node, port), 'v', '_DUPLICATE_', _utils.nthOutput, '_JOIN_', _utils.nthOutput, edge); | ||
var multiCase = options && options.keepDuplicates ? null : '_DUPLICATE_'; | ||
return neighbor(graph, node, port, _lodash2.default.partial(getSuccessorWithCheck, graph, _lodash2.default, node, port), 'v', multiCase, _utils.nthOutput, '_JOIN_', _utils.nthOutput, edge); | ||
} | ||
function predecessor(graph, node, port) { | ||
function predecessor(graph, node, port, options) { | ||
var edge = { to: node, inPort: port }; | ||
return neighbor(graph, node, port, _lodash2.default.partial(getPredecessorWithCheck, graph, _lodash2.default, node, port), 'w', '_JOIN_', _utils.nthInput, '_DUPLICATE_', _utils.nthInput, edge); | ||
} |
{ | ||
"name": "@buggyorg/graphtools", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Tools for processing buggy graphs.", | ||
@@ -25,3 +25,3 @@ "main": "lib/api.js", | ||
"devDependencies": { | ||
"@buggyorg/dupjoin": "^0.1.14", | ||
"@buggyorg/dupjoin": "^0.1.17", | ||
"@buggyorg/npg-port-remodeler": "^0.1.12", | ||
@@ -28,0 +28,0 @@ "babel-cli": "^6.4.5", |
@@ -115,3 +115,3 @@ import graphlib from 'graphlib' | ||
if (!isCompoundable(g, subset)) { | ||
throw new Error('This subset cannot be compoundified given this particular subset.' + JSON.stringify(origSubset)) | ||
throw new Error('This subset cannot be compoundified given this particular subset.\n' + JSON.stringify(origSubset)) | ||
} | ||
@@ -118,0 +118,0 @@ var graph = graphAPI.clone(g) |
@@ -18,6 +18,6 @@ | ||
*/ | ||
export function predecessor (graph, node, port) { | ||
export function predecessor (graph, node, port, options) { | ||
return (utils.isNPG(graph)) | ||
? walkNPG.predecessor(graph, node, port) | ||
: walkNG.predecessor(graph, node, port) | ||
? walkNPG.predecessor(graph, node, port, options) | ||
: walkNG.predecessor(graph, node, port, options) | ||
} | ||
@@ -34,6 +34,6 @@ | ||
*/ | ||
export function successor (graph, node, port) { | ||
export function successor (graph, node, port, options) { | ||
return (utils.isNPG(graph)) | ||
? walkNPG.successor(graph, node, port) | ||
: walkNG.successor(graph, node, port) | ||
? walkNPG.successor(graph, node, port, options) | ||
: walkNG.successor(graph, node, port, options) | ||
} | ||
@@ -63,3 +63,3 @@ | ||
export function walk (graph, node, path, options = {keepPorts: false}) { | ||
return generalWalk(graph, node, path, successor, options) | ||
return generalWalk(graph, node, path, _.partial(successor, _, _, _, options), options) | ||
} | ||
@@ -89,3 +89,3 @@ | ||
export function walkBack (graph, node, path, options = {keepPorts: false}) { | ||
return _.map(generalWalk(graph, node, path, predecessor, options), _.reverse) | ||
return _.map(generalWalk(graph, node, path, _.partial(predecessor, _, _, _, options), options), _.reverse) | ||
} | ||
@@ -92,0 +92,0 @@ |
@@ -68,10 +68,11 @@ | ||
export function successor (graph, node, port) { | ||
export function successor (graph, node, port, options) { | ||
var edge = {from: node, outPort: port} | ||
return neighbor(graph, node, port, _.partial(getSuccessorWithCheck, graph, _, node, port), 'v', '_DUPLICATE_', nthOutput, '_JOIN_', nthOutput, edge) | ||
var multiCase = (options && options.keepDuplicates) ? null : '_DUPLICATE_' | ||
return neighbor(graph, node, port, _.partial(getSuccessorWithCheck, graph, _, node, port), 'v', multiCase, nthOutput, '_JOIN_', nthOutput, edge) | ||
} | ||
export function predecessor (graph, node, port) { | ||
export function predecessor (graph, node, port, options) { | ||
var edge = {to: node, inPort: port} | ||
return neighbor(graph, node, port, _.partial(getPredecessorWithCheck, graph, _, node, port), 'w', '_JOIN_', nthInput, '_DUPLICATE_', nthInput, edge) | ||
} |
@@ -194,2 +194,19 @@ /* global describe, it */ | ||
it('can keep duplicates in the walk results', () => { | ||
var mapG = grlib.json.read(JSON.parse(fs.readFileSync('./test/fixtures/map_recursive.json'))) | ||
var walkTerm = (graph, node, port, mux) => { | ||
if (node === 'mapInc:term') { | ||
return [] | ||
} else if (node === 'mapInc' && port === 'fn') { | ||
return 'fn' | ||
} else { | ||
return _.keys(graph.node(node).outputPorts) | ||
} | ||
} | ||
var paths = walk.walk(mapG, {node: 'mapInc', port: 'fn'}, walkTerm, {keepDuplicates: true}) | ||
expect(paths).to.have.length(2) | ||
expect(paths[0]).to.have.length(3) | ||
expect(_.includes(paths[0], 'mapInc_DUPLICATE_0_1')).to.be.true | ||
}) | ||
/* it.only('can walk through recursive map correctly', () => { | ||
@@ -223,2 +240,2 @@ var mapG = grlib.json.read(JSON.parse(fs.readFileSync('./test/fixtures/map_recursive.1.json'))) | ||
testSetting('network port graphs') | ||
testSetting('network graphs', (graph) => remodelPorts(normalize(graph))) | ||
testSetting('network graphs', (graph) => remodelPorts(normalize(graph, {createIdNodes: false, addConsumeNodes: false}))) |
Sorry, the diff of this file is too big to display
1489037
12763