.
This commit is contained in:
35
qwen/nodejs/node_modules/toposort-class/.eslintrc
generated
vendored
Normal file
35
qwen/nodejs/node_modules/toposort-class/.eslintrc
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"parser": "babel-eslint",
|
||||
"env": {
|
||||
"node": true,
|
||||
"mocha": true,
|
||||
"browser": true
|
||||
},
|
||||
"rules": {
|
||||
"strict": 0, //taken care of automatically by babel
|
||||
"no-mixed-spaces-and-tabs": 2,
|
||||
"eqeqeq": 2,
|
||||
"no-eq-null": 2,
|
||||
"consistent-this": 2,
|
||||
"guard-for-in": 2,
|
||||
"no-caller": 2,
|
||||
"no-underscore-dangle": 2,
|
||||
"curly": 2,
|
||||
"no-multi-spaces": 2,
|
||||
"key-spacing": 0,
|
||||
"no-return-assign": 2,
|
||||
"consistent-return": 2,
|
||||
"no-shadow": 2,
|
||||
"comma-dangle": 2,
|
||||
"no-use-before-define": 2,
|
||||
"no-empty": 2,
|
||||
"new-parens": 2,
|
||||
"no-cond-assign": 2,
|
||||
"no-fallthrough": 2,
|
||||
"new-cap": 2,
|
||||
"no-loop-func": 2,
|
||||
"no-unreachable": 2,
|
||||
"no-process-exit": 2,
|
||||
"quotes": [2, "double", "avoid-escape"]
|
||||
}
|
||||
}
|
||||
1
qwen/nodejs/node_modules/toposort-class/.gitattributes
generated
vendored
Normal file
1
qwen/nodejs/node_modules/toposort-class/.gitattributes
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
* eol=lf
|
||||
44
qwen/nodejs/node_modules/toposort-class/.npmignore
generated
vendored
Normal file
44
qwen/nodejs/node_modules/toposort-class/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
# Development stuff
|
||||
test/
|
||||
Gruntfile.js
|
||||
|
||||
# Configuration files
|
||||
.jscsrc
|
||||
.jshintrc
|
||||
.travis.yml
|
||||
bower.json
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directory
|
||||
# Deployed apps should consider commenting this line out:
|
||||
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
|
||||
node_modules
|
||||
|
||||
# JetBrains exclusion
|
||||
.idea
|
||||
|
||||
# Source files
|
||||
src
|
||||
|
||||
# example files
|
||||
examples
|
||||
21
qwen/nodejs/node_modules/toposort-class/LICENSE
generated
vendored
Normal file
21
qwen/nodejs/node_modules/toposort-class/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Gustavo Henke and Aaron Trent
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
93
qwen/nodejs/node_modules/toposort-class/README.md
generated
vendored
Normal file
93
qwen/nodejs/node_modules/toposort-class/README.md
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
# Toposort
|
||||
[](https://travis-ci.org/gustavohenke/toposort)
|
||||
[](https://gemnasium.com/gustavohenke/toposort)
|
||||
|
||||
__Sorting directed acyclic graphs, for Node.js, io.js and the browser__
|
||||
_This was originally done by Marcel Klehr. [Why not checkout his original repo?](https://github.com/marcelklehr/toposort)_
|
||||
|
||||
## Installation
|
||||
There are a few ways for installing Toposort. Here are them:
|
||||
|
||||
* Via NPM: `npm install toposort-class`
|
||||
* Via Bower: `bower install toposort`
|
||||
* Via Git: `git clone git://github.com/gustavohenke/toposort.git`
|
||||
* [Direct download](https://raw.githubusercontent.com/gustavohenke/toposort/master/build/toposort.js) ([Minified](https://raw.githubusercontent.com/gustavohenke/toposort/master/build/toposort.min.js)) for use in the browser
|
||||
|
||||
## Example
|
||||
Let's say you have the following dependency graph:
|
||||
|
||||
* Plugin depends on Backbone and jQuery UI Button;
|
||||
* Backbone depends on jQuery and Underscore;
|
||||
* jQuery UI Button depends on jQuery UI Core and jQuery UI Widget;
|
||||
* jQuery UI Widget and jQuery UI Core depend on jQuery;
|
||||
* jQuery and Underscore don't depend on anyone.
|
||||
|
||||
Now, how would you sort this in a way that each asset will be correctly placed? You'll probably need the following sorting:
|
||||
|
||||
* `jQuery`, `jQuery UI Core`, `jQuery UI Widget`, `jQuery UI Button`, `Underscore`, `Backbone`, `Plugin`
|
||||
|
||||
You can achieve it with the following code, using `toposort-class`:
|
||||
```javascript
|
||||
var Toposort = require('toposort-class'),
|
||||
t = new Toposort();
|
||||
|
||||
t.add("jquery-ui-core", "jquery")
|
||||
.add("jquery-ui-widget", "jquery")
|
||||
.add("jquery-ui-button", ["jquery-ui-core", "jquery-ui-widget"])
|
||||
.add("plugin", ["backbone", "jquery-ui-button"])
|
||||
.add("backbone", ["underscore", "jquery"]);
|
||||
|
||||
console.log(t.sort().reverse());
|
||||
|
||||
/* Will output:
|
||||
* ['jquery', 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-button', 'underscore', 'backbone', 'plugin']
|
||||
*
|
||||
* And you're done.
|
||||
*/
|
||||
```
|
||||
|
||||
## Usage
|
||||
CommonJS (Node.js and io.js):
|
||||
```javascript
|
||||
var Toposort = require('toposort-class'),
|
||||
t = new Toposort();
|
||||
```
|
||||
|
||||
Browser with AMD:
|
||||
```javascript
|
||||
define("myModule", ["Toposort"], function(Toposort) {
|
||||
var t = new Toposort();
|
||||
});
|
||||
```
|
||||
|
||||
Browser without AMD:
|
||||
```javascript
|
||||
var t = new window.Toposort();
|
||||
```
|
||||
|
||||
or whatever global object there is instead of `window`.
|
||||
|
||||
## API
|
||||
|
||||
#### `.add(item, deps)`
|
||||
* _{String}_ `item` - The name of the dependent item that is being added
|
||||
* _{Array|String}_ `deps` - A dependency or list of dependencies of `item`
|
||||
|
||||
__Returns:__ _{Toposort}_ The Toposort instance, for chaining.
|
||||
|
||||
#### `.sort()`
|
||||
__Returns:__ _{Array}_ The list of dependencies topologically sorted.
|
||||
|
||||
This method will check for cyclic dependencies, like "A is dependent of A".
|
||||
|
||||
#### `.clear()`
|
||||
__Returns:__ _{Toposort}_ The Toposort instance, for chaining.
|
||||
|
||||
Clears all edges, effectively resetting the instance.
|
||||
|
||||
#### `.Toposort`
|
||||
|
||||
Reference to the Toposort constructor.
|
||||
|
||||
## Legal
|
||||
MIT License
|
||||
128
qwen/nodejs/node_modules/toposort-class/benchmark/0.3.1/toposort.js
generated
vendored
Normal file
128
qwen/nodejs/node_modules/toposort-class/benchmark/0.3.1/toposort.js
generated
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
!function() {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Topological sort class.
|
||||
* Original by Marcel Klehr, contributed by Gustavo Henke.
|
||||
*
|
||||
* @class
|
||||
* @since 0.1.0
|
||||
* @see https://github.com/marcelklehr/toposort
|
||||
* @author Marcel Klehr <mklehr@gmx.net>
|
||||
*
|
||||
* @see https://github.com/gustavohenke/toposort
|
||||
* @author Gustavo Henke <gustavo@injoin.com.br>
|
||||
*/
|
||||
function Toposort() {
|
||||
var self = this;
|
||||
var edges = [];
|
||||
|
||||
/**
|
||||
* Adds dependency edges.
|
||||
*
|
||||
* @since 0.1.0
|
||||
* @param {String} item An dependent name. Must be an string and not empty
|
||||
* @param {String[]|String} [deps] An dependency or array of dependencies
|
||||
* @returns {Toposort} The Toposort instance
|
||||
*/
|
||||
self.add = function( item, deps ) {
|
||||
if( typeof item !== "string" || !item ) {
|
||||
throw new TypeError( "Dependent name must be given as a not empty string" );
|
||||
}
|
||||
|
||||
deps = Array.isArray( deps ) ? deps.slice() : [deps];
|
||||
if( deps.length ) {
|
||||
deps.forEach( function( dep ) {
|
||||
if( typeof dep !== "string" || !dep ) {
|
||||
throw new TypeError(
|
||||
"Dependency name must be given as a not empty string"
|
||||
);
|
||||
}
|
||||
|
||||
edges.push( [item, dep] );
|
||||
} );
|
||||
} else {
|
||||
edges.push( [item] );
|
||||
}
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
/**
|
||||
* Runs the toposorting and return an ordered array of strings
|
||||
*
|
||||
* @since 0.1.0
|
||||
* @returns {String[]} The list of items topologically sorted.
|
||||
*/
|
||||
self.sort = function() {
|
||||
var nodes = [];
|
||||
var sorted = [];
|
||||
|
||||
edges.forEach( function( edge ) {
|
||||
edge.forEach( function( n ) {
|
||||
if( nodes.indexOf( n ) === -1 ) {
|
||||
nodes.push( n );
|
||||
}
|
||||
} );
|
||||
} );
|
||||
|
||||
function visit( node, predecessors, i ) {
|
||||
var index, predsCopy;
|
||||
predecessors = predecessors || [];
|
||||
|
||||
if( predecessors.indexOf( node ) > -1 ) {
|
||||
throw new Error(
|
||||
"Cyclic dependency found. '" + node + "' is dependent of itself.\n" +
|
||||
"Dependency Chain: " + predecessors.join( " -> " ) + " => " + node
|
||||
);
|
||||
}
|
||||
|
||||
index = nodes.indexOf( node );
|
||||
if( index === -1 ) {
|
||||
return i;
|
||||
}
|
||||
|
||||
nodes.splice( index, 1 );
|
||||
if( predecessors.length === 0 ) {
|
||||
i--;
|
||||
}
|
||||
|
||||
predsCopy = predecessors.slice();
|
||||
predsCopy.push( node );
|
||||
|
||||
edges.filter( function( e ) {
|
||||
return e[0] === node;
|
||||
} ).forEach( function( e ) {
|
||||
i = visit( e[1], predsCopy, i );
|
||||
} );
|
||||
|
||||
sorted.unshift( node );
|
||||
return i;
|
||||
}
|
||||
|
||||
for( var i = 0; i < nodes.length; i++ ) {
|
||||
i = visit( nodes[i], null, i );
|
||||
}
|
||||
|
||||
return sorted;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
if( typeof module === "object" && module && typeof module.exports === "object" ) {
|
||||
// Expose toposort to CommonJS loaders (aka Node)
|
||||
module.exports = exports.Toposort = Toposort;
|
||||
} else {
|
||||
// Expose toposort to AMD loaders (aka Require.js)
|
||||
if( typeof define === "function" && define.amd ) {
|
||||
define( function() {
|
||||
return Toposort;
|
||||
} );
|
||||
}
|
||||
|
||||
// Expose toposort as a browser global
|
||||
if( typeof window === "object" ) {
|
||||
window.Toposort = Toposort;
|
||||
}
|
||||
}
|
||||
}();
|
||||
11
qwen/nodejs/node_modules/toposort-class/benchmark/README.md
generated
vendored
Normal file
11
qwen/nodejs/node_modules/toposort-class/benchmark/README.md
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
Benchmarks
|
||||
==========
|
||||
|
||||
Since I'm obsessed with performance, here is a tiny benchmark comparing the performance of the 0.3.1 version and the current version written in ES6
|
||||
|
||||
| Description | Library | Op/s | % |
|
||||
|------------------------------|-----------------|-----------:|-----:|
|
||||
| simple dependency chains | 0.3.1 version | 66,722.22 | 8% |
|
||||
| | current version | 837,416.60 | 100% |
|
||||
| slightly more complex chains | 0.3.1 version | 24,530.85 | 6% |
|
||||
| | current version | 386,620.50 | 100% |
|
||||
56
qwen/nodejs/node_modules/toposort-class/benchmark/general.js
generated
vendored
Normal file
56
qwen/nodejs/node_modules/toposort-class/benchmark/general.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
var Toposort = require( "../index.js" );
|
||||
var OldToposort = require( "./0.3.1/toposort.js" );
|
||||
|
||||
suite( "simple dependency chains", function() {
|
||||
set( "delay", 0 );
|
||||
set( "mintime", 1750 );
|
||||
|
||||
bench( "0.3.1 version", function() {
|
||||
var t = new OldToposort();
|
||||
|
||||
t.add( "3", "2" )
|
||||
.add( "2", "1" )
|
||||
.add( "6", "5" )
|
||||
.add( "5", ["2", "4"] ).sort();
|
||||
} );
|
||||
|
||||
bench( "current version", function() {
|
||||
var t = new Toposort();
|
||||
|
||||
t.add( "3", "2" )
|
||||
.add( "2", "1" )
|
||||
.add( "6", "5" )
|
||||
.add( "5", ["2", "4"] ).sort();
|
||||
} );
|
||||
} );
|
||||
|
||||
suite( "slightly more complex chains", function() {
|
||||
set( "delay", 0 );
|
||||
set( "mintime", 1750 );
|
||||
|
||||
bench( "0.3.1 version", function() {
|
||||
var t = new OldToposort();
|
||||
|
||||
t.add( "3", "1" )
|
||||
.add( "2", "3" )
|
||||
.add( "4", ["2", "3"] )
|
||||
.add( "5", ["3", "4"] )
|
||||
.add( "6", ["3", "4", "5"] )
|
||||
.add( "7", "1" )
|
||||
.add( "8", ["1", "2", "3", "4", "5"] )
|
||||
.add( "9", ["8", "6", "7"] ).sort();
|
||||
} );
|
||||
|
||||
bench( "current version", function() {
|
||||
var t = new Toposort();
|
||||
|
||||
t.add( "3", "1" )
|
||||
.add( "2", "3" )
|
||||
.add( "4", ["2", "3"] )
|
||||
.add( "5", ["3", "4"] )
|
||||
.add( "6", ["3", "4", "5"] )
|
||||
.add( "7", "1" )
|
||||
.add( "8", ["1", "2", "3", "4", "5"] )
|
||||
.add( "9", ["8", "6", "7"] ).sort();
|
||||
} );
|
||||
} );
|
||||
4
qwen/nodejs/node_modules/toposort-class/benchmark/results.csv
generated
vendored
Normal file
4
qwen/nodejs/node_modules/toposort-class/benchmark/results.csv
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
2015-07-31 22:37:51,"simple dependency chains","0.3.1 version",2295.217390,153142
|
||||
2015-07-31 22:37:51,"simple dependency chains","current version",3299.024625,2762658
|
||||
2015-07-31 22:37:51,"slightly more complex chains","0.3.1 version",3313.337523,81279
|
||||
2015-07-31 22:37:51,"slightly more complex chains","current version",1797.512029,694955
|
||||
|
281
qwen/nodejs/node_modules/toposort-class/build/toposort.js
generated
vendored
Normal file
281
qwen/nodejs/node_modules/toposort-class/build/toposort.js
generated
vendored
Normal file
@@ -0,0 +1,281 @@
|
||||
/****
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2015 Gustavo Henke and Aaron Trent
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
****/
|
||||
(function( global, factory ) {
|
||||
if( typeof define === "function" && define.amd ) {
|
||||
define( "Toposort", ["exports", "module"], factory );
|
||||
} else if( typeof exports !== "undefined" && typeof module !== "undefined" ) {
|
||||
factory( exports, module );
|
||||
} else {
|
||||
var mod = {
|
||||
exports: {}
|
||||
};
|
||||
factory( mod.exports, mod );
|
||||
global.Toposort = mod.exports;
|
||||
}
|
||||
})( this, function( exports, module ) {
|
||||
"use strict";
|
||||
|
||||
function _classCallCheck( instance, Constructor ) {
|
||||
if( !(instance instanceof Constructor) ) {
|
||||
throw new TypeError( "Cannot call a class as a function" );
|
||||
}
|
||||
}
|
||||
|
||||
var Toposort = (function() {
|
||||
function Toposort() {
|
||||
_classCallCheck( this, Toposort );
|
||||
|
||||
this.edges = [];
|
||||
this.Toposort = Toposort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds dependency edges.
|
||||
*
|
||||
* @since 0.1.0
|
||||
* @param {String} item An dependent name. Must be an string and not empty
|
||||
* @param {String[]|String} [deps] An dependency or array of dependencies
|
||||
* @returns {Toposort} The Toposort instance
|
||||
*/
|
||||
|
||||
Toposort.prototype.add = function add( item, deps ) {
|
||||
if( typeof item !== "string" || !item ) {
|
||||
throw new TypeError( "Dependent name must be given as a not empty string" );
|
||||
}
|
||||
|
||||
deps = Array.isArray( deps ) ? deps : [deps];
|
||||
|
||||
if( deps.length > 0 ) {
|
||||
for( var _iterator = deps, _isArray = Array.isArray( _iterator ), _i = 0, _iterator = _isArray ?
|
||||
_iterator :
|
||||
_iterator[Symbol.iterator](); ; ) {
|
||||
var _ref;
|
||||
|
||||
if( _isArray ) {
|
||||
if( _i >= _iterator.length ) {
|
||||
break;
|
||||
}
|
||||
_ref = _iterator[_i++];
|
||||
} else {
|
||||
_i = _iterator.next();
|
||||
if( _i.done ) {
|
||||
break;
|
||||
}
|
||||
_ref = _i.value;
|
||||
}
|
||||
|
||||
var dep = _ref;
|
||||
|
||||
if( typeof dep !== "string" || !dep ) {
|
||||
throw new TypeError( "Dependency name must be given as a not empty string" );
|
||||
}
|
||||
|
||||
this.edges.push( [item, dep] );
|
||||
}
|
||||
} else {
|
||||
this.edges.push( [item] );
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Runs the toposorting and return an ordered array of strings
|
||||
*
|
||||
* @since 0.1.0
|
||||
* @returns {String[]} The list of items topologically sorted.
|
||||
*/
|
||||
|
||||
Toposort.prototype.sort = function sort() {
|
||||
var _this = this;
|
||||
|
||||
var nodes = [];
|
||||
|
||||
//accumulate unique nodes into a large list
|
||||
for( var _iterator2 = this.edges, _isArray2 = Array.isArray( _iterator2 ), _i2 = 0, _iterator2 = _isArray2 ?
|
||||
_iterator2 :
|
||||
_iterator2[Symbol.iterator](); ; ) {
|
||||
var _ref2;
|
||||
|
||||
if( _isArray2 ) {
|
||||
if( _i2 >= _iterator2.length ) {
|
||||
break;
|
||||
}
|
||||
_ref2 = _iterator2[_i2++];
|
||||
} else {
|
||||
_i2 = _iterator2.next();
|
||||
if( _i2.done ) {
|
||||
break;
|
||||
}
|
||||
_ref2 = _i2.value;
|
||||
}
|
||||
|
||||
var edge = _ref2;
|
||||
|
||||
for( var _iterator3 = edge, _isArray3 = Array.isArray( _iterator3 ), _i3 = 0, _iterator3 = _isArray3 ?
|
||||
_iterator3 :
|
||||
_iterator3[Symbol.iterator](); ; ) {
|
||||
var _ref3;
|
||||
|
||||
if( _isArray3 ) {
|
||||
if( _i3 >= _iterator3.length ) {
|
||||
break;
|
||||
}
|
||||
_ref3 = _iterator3[_i3++];
|
||||
} else {
|
||||
_i3 = _iterator3.next();
|
||||
if( _i3.done ) {
|
||||
break;
|
||||
}
|
||||
_ref3 = _i3.value;
|
||||
}
|
||||
|
||||
var node = _ref3;
|
||||
|
||||
if( nodes.indexOf( node ) === -1 ) {
|
||||
nodes.push( node );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//initialize the placement of nodes into the sorted array at the end
|
||||
var place = nodes.length;
|
||||
|
||||
//initialize the sorted array with the same length as the unique nodes array
|
||||
var sorted = new Array( nodes.length );
|
||||
|
||||
//define a visitor function that recursively traverses dependencies.
|
||||
var visit = function visit( node, predecessors ) {
|
||||
//check if a node is dependent of itself
|
||||
if( predecessors.length !== 0 && predecessors.indexOf( node ) !== -1 ) {
|
||||
throw new Error( "Cyclic dependency found. " + node + " is dependent of itself.\nDependency chain: "
|
||||
+ predecessors.join( " -> " ) + " => " + node );
|
||||
}
|
||||
|
||||
var index = nodes.indexOf( node );
|
||||
|
||||
//if the node still exists, traverse its dependencies
|
||||
if( index !== -1 ) {
|
||||
var copy = false;
|
||||
|
||||
//mark the node as false to exclude it from future iterations
|
||||
nodes[index] = false;
|
||||
|
||||
//loop through all edges and follow dependencies of the current node
|
||||
for( var _iterator4 = _this.edges, _isArray4 = Array.isArray( _iterator4 ), _i4 = 0, _iterator4 = _isArray4 ?
|
||||
_iterator4 :
|
||||
_iterator4[Symbol.iterator](); ; ) {
|
||||
var _ref4;
|
||||
|
||||
if( _isArray4 ) {
|
||||
if( _i4 >= _iterator4.length ) {
|
||||
break;
|
||||
}
|
||||
_ref4 = _iterator4[_i4++];
|
||||
} else {
|
||||
_i4 = _iterator4.next();
|
||||
if( _i4.done ) {
|
||||
break;
|
||||
}
|
||||
_ref4 = _i4.value;
|
||||
}
|
||||
|
||||
var edge = _ref4;
|
||||
|
||||
if( edge[0] === node ) {
|
||||
//lazily create a copy of predecessors with the current node concatenated onto it
|
||||
copy = copy || predecessors.concat( [node] );
|
||||
|
||||
//recurse to node dependencies
|
||||
visit( edge[1], copy );
|
||||
}
|
||||
}
|
||||
|
||||
//add the node to the next place in the sorted array
|
||||
sorted[--place] = node;
|
||||
}
|
||||
};
|
||||
|
||||
for( var i = 0; i < nodes.length; i++ ) {
|
||||
var node = nodes[i];
|
||||
|
||||
//ignore nodes that have been excluded
|
||||
if( node !== false ) {
|
||||
//mark the node as false to exclude it from future iterations
|
||||
nodes[i] = false;
|
||||
|
||||
//loop through all edges and follow dependencies of the current node
|
||||
for( var _iterator5 = this.edges, _isArray5 = Array.isArray( _iterator5 ), _i5 = 0, _iterator5 = _isArray5 ?
|
||||
_iterator5 :
|
||||
_iterator5[Symbol.iterator](); ; ) {
|
||||
var _ref5;
|
||||
|
||||
if( _isArray5 ) {
|
||||
if( _i5 >= _iterator5.length ) {
|
||||
break;
|
||||
}
|
||||
_ref5 = _iterator5[_i5++];
|
||||
} else {
|
||||
_i5 = _iterator5.next();
|
||||
if( _i5.done ) {
|
||||
break;
|
||||
}
|
||||
_ref5 = _i5.value;
|
||||
}
|
||||
|
||||
var edge = _ref5;
|
||||
|
||||
if( edge[0] === node ) {
|
||||
//recurse to node dependencies
|
||||
visit( edge[1], [node] );
|
||||
}
|
||||
}
|
||||
|
||||
//add the node to the next place in the sorted array
|
||||
sorted[--place] = node;
|
||||
}
|
||||
}
|
||||
|
||||
return sorted;
|
||||
};
|
||||
|
||||
/**
|
||||
* Clears edges
|
||||
*
|
||||
* @since 0.4.0
|
||||
* @returns {Toposort} The Toposort instance
|
||||
*/
|
||||
|
||||
Toposort.prototype.clear = function clear() {
|
||||
this.edges = [];
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
return Toposort;
|
||||
})();
|
||||
|
||||
module.exports = Toposort;
|
||||
} );
|
||||
1
qwen/nodejs/node_modules/toposort-class/build/toposort.min.js
generated
vendored
Normal file
1
qwen/nodejs/node_modules/toposort-class/build/toposort.min.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(a,b){if("function"==typeof define&&define.amd)define("Toposort",["exports","module"],b);else if("undefined"!=typeof exports&&"undefined"!=typeof module)b(exports,module);else{var c={exports:{}};b(c.exports,c),a.Toposort=c.exports}}(this,function(a,b){"use strict";function c(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var d=function(){function a(){c(this,a),this.edges=[],this.Toposort=a}return a.prototype.add=function(a,b){if("string"!=typeof a||!a)throw new TypeError("Dependent name must be given as a not empty string");if(b=Array.isArray(b)?b:[b],b.length>0)for(var c=b,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if("string"!=typeof g||!g)throw new TypeError("Dependency name must be given as a not empty string");this.edges.push([a,g])}else this.edges.push([a]);return this},a.prototype.sort=function(){for(var a=this,b=[],c=this.edges,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}for(var g=f,h=g,i=Array.isArray(h),j=0,h=i?h:h[Symbol.iterator]();;){var k;if(i){if(j>=h.length)break;k=h[j++]}else{if(j=h.next(),j.done)break;k=j.value}var l=k;-1===b.indexOf(l)&&b.push(l)}}for(var m=b.length,n=new Array(b.length),o=function u(c,d){if(0!==d.length&&-1!==d.indexOf(c))throw new Error("Cyclic dependency found. "+c+" is dependent of itself.\nDependency chain: "+d.join(" -> ")+" => "+c);var e=b.indexOf(c);if(-1!==e){var f=!1;b[e]=!1;for(var g=a.edges,h=Array.isArray(g),i=0,g=h?g:g[Symbol.iterator]();;){var j;if(h){if(i>=g.length)break;j=g[i++]}else{if(i=g.next(),i.done)break;j=i.value}var k=j;k[0]===c&&(f=f||d.concat([c]),u(k[1],f))}n[--m]=c}},p=0;p<b.length;p++){var l=b[p];if(l!==!1){b[p]=!1;for(var q=this.edges,r=Array.isArray(q),s=0,q=r?q:q[Symbol.iterator]();;){var t;if(r){if(s>=q.length)break;t=q[s++]}else{if(s=q.next(),s.done)break;t=s.value}var g=t;g[0]===l&&o(g[1],[l])}n[--m]=l}}return n},a.prototype.clear=function(){return this.edges=[],this},a}();b.exports=d});
|
||||
1
qwen/nodejs/node_modules/toposort-class/index.js
generated
vendored
Normal file
1
qwen/nodejs/node_modules/toposort-class/index.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require( './build/toposort.js' );
|
||||
46
qwen/nodejs/node_modules/toposort-class/package.json
generated
vendored
Normal file
46
qwen/nodejs/node_modules/toposort-class/package.json
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "toposort-class",
|
||||
"version": "1.0.1",
|
||||
"description": "Topological sort of directed acyclic graphs (like dependecy lists)",
|
||||
"main": "./index.js",
|
||||
"devDependencies": {
|
||||
"babel-eslint": "^4.0.5",
|
||||
"eslint": "^1.0.0",
|
||||
"grunt": "^0.4.5",
|
||||
"grunt-babel": "^5.0.1",
|
||||
"grunt-banner": "^0.4.0",
|
||||
"grunt-contrib-clean": "^0.6.0",
|
||||
"grunt-contrib-uglify": "^0.9.1",
|
||||
"matcha": "^0.6.0",
|
||||
"mocha": "^2.2.5"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha -b test",
|
||||
"eslint": "eslint src/toposort.js test/spec.js Gruntfile.js",
|
||||
"benchmark": "matcha benchmark/general.js",
|
||||
"benchmark-save": "matcha -R csv benchmark/general.js > benchmark/results.csv"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/gustavohenke/toposort.git"
|
||||
},
|
||||
"keywords": [
|
||||
"topological",
|
||||
"sort",
|
||||
"sorting",
|
||||
"graphs",
|
||||
"graph",
|
||||
"dependency",
|
||||
"list",
|
||||
"dependencies",
|
||||
"acyclic",
|
||||
"browser"
|
||||
],
|
||||
"author": [
|
||||
"Marcel Klehr <mklehr@gmx.net>",
|
||||
"Gustavo Henke <gustavo@injoin.com.br>",
|
||||
"Aaron Trent <novacrazy@gmail.com>"
|
||||
],
|
||||
"license": "MIT",
|
||||
"readmeFilename": "README.md"
|
||||
}
|
||||
Reference in New Issue
Block a user