1 | require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | var baseToString = require('lodash._basetostring');
|
11 |
|
12 |
|
13 | var idCounter = 0;
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | function uniqueId(prefix) {
|
32 | var id = ++idCounter;
|
33 | return baseToString(prefix) + id;
|
34 | }
|
35 |
|
36 | module.exports = uniqueId;
|
37 |
|
38 | },{"lodash._basetostring":2}],2:[function(require,module,exports){
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | function baseToString(value) {
|
57 | return value == null ? '' : (value + '');
|
58 | }
|
59 |
|
60 | module.exports = baseToString;
|
61 |
|
62 | },{}],3:[function(require,module,exports){
|
63 |
|
64 |
|
65 | module.exports = function (cb) { cb() }
|
66 |
|
67 |
|
68 | },{}],4:[function(require,module,exports){
|
69 | 'use strict';
|
70 |
|
71 | var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
72 |
|
73 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
74 |
|
75 | var getIncidentEdgeIds = require('./getIncidentEdgeIds');
|
76 | var getOrphanEdgeIds = require('./getOrphanEdgeIds');
|
77 | var uniqueId = require('lodash.uniqueid');
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 | var Graph = (function () {
|
90 | function Graph() {
|
91 | _classCallCheck(this, Graph);
|
92 |
|
93 | var arg = arguments[0] || {};
|
94 |
|
95 | this.edges = arg.edges || {};
|
96 | this.nodes = arg.nodes || {};
|
97 | }
|
98 |
|
99 | |
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | _createClass(Graph, [{
|
106 | key: 'addEdge',
|
107 | value: function addEdge(nodeIds) {
|
108 | var id = uniqueId();
|
109 |
|
110 | this.edges[id] = nodeIds;
|
111 |
|
112 | return id;
|
113 | }
|
114 |
|
115 | |
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 | }, {
|
122 | key: 'addNode',
|
123 | value: function addNode(data) {
|
124 | var id = uniqueId();
|
125 |
|
126 | this.nodes[id] = data;
|
127 |
|
128 | return id;
|
129 | }
|
130 |
|
131 | |
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 | }, {
|
138 | key: 'delEdge',
|
139 | value: function delEdge(id) {
|
140 | var nodeIds = this.edges[id];
|
141 |
|
142 | delete this.edges[id];
|
143 |
|
144 | return nodeIds;
|
145 | }
|
146 |
|
147 | |
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 | }, {
|
154 | key: 'delNode',
|
155 | value: function delNode(id) {
|
156 | var data = this.nodes[id];
|
157 | delete this.nodes[id];
|
158 |
|
159 | var incidentEdgeIds = getIncidentEdgeIds(this.edges, id);
|
160 |
|
161 | for (var edgeId in incidentEdgeIds) {
|
162 | this.delEdge(edgeId);
|
163 | }
|
164 |
|
165 | return data;
|
166 | }
|
167 | }]);
|
168 |
|
169 | return Graph;
|
170 | })();
|
171 |
|
172 | module.exports = Graph;
|
173 |
|
174 | },{"./getIncidentEdgeIds":7,"./getOrphanEdgeIds":8,"lodash.uniqueid":1}],5:[function(require,module,exports){
|
175 | "use strict";
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 | var getAdjacentNodeIds = function getAdjacentNodeIds(edges, nodeId) {
|
186 | var adjacentNodeIds = [];
|
187 |
|
188 | var givenNodeId = function givenNodeId(id) {
|
189 | return id !== nodeId;
|
190 | };
|
191 |
|
192 | var foundNodeIds = function foundNodeIds(id) {
|
193 | return adjacentNodeIds.indexOf(id) === -1;
|
194 | };
|
195 |
|
196 | for (var edgeId in edges) {
|
197 | var edge = edges[edgeId];
|
198 |
|
199 |
|
200 | if (edge.indexOf(nodeId) === -1) {
|
201 | continue;
|
202 | }
|
203 |
|
204 |
|
205 | var nodeIds = edge.filter(givenNodeId).filter(foundNodeIds);
|
206 |
|
207 | adjacentNodeIds = adjacentNodeIds.concat(nodeIds);
|
208 | }
|
209 |
|
210 | return adjacentNodeIds;
|
211 | };
|
212 |
|
213 | module.exports = getAdjacentNodeIds;
|
214 |
|
215 | },{}],6:[function(require,module,exports){
|
216 | "use strict";
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 | var getDegree = function getDegree(edges, nodeId) {
|
229 | var degree = 0;
|
230 |
|
231 | var countIncidents = function countIncidents(id) {
|
232 | if (id === nodeId) {
|
233 | degree++;
|
234 | }
|
235 | };
|
236 |
|
237 | for (var edgeId in edges) {
|
238 | var edge = edges[edgeId];
|
239 |
|
240 | edge.forEach(countIncidents);
|
241 | }
|
242 |
|
243 | return degree;
|
244 | };
|
245 |
|
246 | module.exports = getDegree;
|
247 |
|
248 | },{}],7:[function(require,module,exports){
|
249 | "use strict";
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 | var getIncidentEdgeIds = function getIncidentEdgeIds(edges, nodeId) {
|
260 | var incidentEdgeIds = [];
|
261 |
|
262 | var pushUniqueIncidents = function pushUniqueIncidents(edgeId, nodeId, id) {
|
263 | var isIncident = id === nodeId;
|
264 | var isUnique = incidentEdgeIds.indexOf(edgeId) < 0;
|
265 |
|
266 | if (isIncident && isUnique) incidentEdgeIds.push(edgeId);
|
267 | };
|
268 |
|
269 | for (var edgeId in edges) {
|
270 | var edge = edges[edgeId];
|
271 |
|
272 | edge.forEach(pushUniqueIncidents.bind(null, edgeId, nodeId));
|
273 | }
|
274 |
|
275 | return incidentEdgeIds;
|
276 | };
|
277 |
|
278 | module.exports = getIncidentEdgeIds;
|
279 |
|
280 | },{}],8:[function(require,module,exports){
|
281 | 'use strict';
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 | var getOrphanEdgeIds = function getOrphanEdgeIds(edges, nodes) {
|
293 | var orphanEdgeIds = [];
|
294 |
|
295 | var nodeIdsNotFound = function nodeIdsNotFound(nodeId) {
|
296 | return typeof nodes[nodeId] === 'undefined';
|
297 | };
|
298 |
|
299 | for (var edgeId in edges) {
|
300 | var edge = edges[edgeId];
|
301 |
|
302 | if (edge.filter(nodeIdsNotFound).length > 0) {
|
303 | orphanEdgeIds.push(edgeId);
|
304 | }
|
305 | }
|
306 |
|
307 | return orphanEdgeIds;
|
308 | };
|
309 |
|
310 | module.exports = getOrphanEdgeIds;
|
311 |
|
312 | },{}],9:[function(require,module,exports){
|
313 | "use strict";
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 | var getRank = function getRank(edges) {
|
323 | var rank = 0;
|
324 |
|
325 | for (var edgeId in edges) {
|
326 | var edge = edges[edgeId];
|
327 | rank = Math.max(rank, edge.length);
|
328 | }
|
329 |
|
330 | return rank;
|
331 | };
|
332 |
|
333 | module.exports = getRank;
|
334 |
|
335 | },{}],10:[function(require,module,exports){
|
336 | 'use strict';
|
337 |
|
338 | require('strict-mode')(function () {
|
339 | exports.Graph = require('./Graph');
|
340 |
|
341 | exports.getAdjacentNodeIds = require('./getAdjacentNodeIds');
|
342 | exports.getDegree = require('./getDegree');
|
343 | exports.getIncidentEdgeIds = require('./getIncidentEdgeIds');
|
344 | exports.getOrphanEdgeIds = require('./getOrphanEdgeIds');
|
345 | exports.getRank = require('./getRank');
|
346 | });
|
347 |
|
348 | },{"./Graph":4,"./getAdjacentNodeIds":5,"./getDegree":6,"./getIncidentEdgeIds":7,"./getOrphanEdgeIds":8,"./getRank":9,"strict-mode":3}],"iper":[function(require,module,exports){
|
349 | 'use strict';
|
350 |
|
351 | module.exports = require('./src');
|
352 |
|
353 | },{"./src":10}]},{},[]);
|