UNPKG

8.81 kBJavaScriptView Raw
1require=(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 * lodash 3.0.0 (Custom Build) <https://lodash.com/>
4 * Build: `lodash modern modularize exports="npm" -o ./`
5 * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
6 * Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE>
7 * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
8 * Available under MIT license <https://lodash.com/license>
9 */
10var baseToString = require('lodash._basetostring');
11
12/** Used to generate unique IDs. */
13var idCounter = 0;
14
15/**
16 * Generates a unique ID. If `prefix` is provided the ID is appended to it.
17 *
18 * @static
19 * @memberOf _
20 * @category Utility
21 * @param {string} [prefix] The value to prefix the ID with.
22 * @returns {string} Returns the unique ID.
23 * @example
24 *
25 * _.uniqueId('contact_');
26 * // => 'contact_104'
27 *
28 * _.uniqueId();
29 * // => '105'
30 */
31function uniqueId(prefix) {
32 var id = ++idCounter;
33 return baseToString(prefix) + id;
34}
35
36module.exports = uniqueId;
37
38},{"lodash._basetostring":2}],2:[function(require,module,exports){
39/**
40 * lodash 3.0.1 (Custom Build) <https://lodash.com/>
41 * Build: `lodash modern modularize exports="npm" -o ./`
42 * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
43 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
44 * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
45 * Available under MIT license <https://lodash.com/license>
46 */
47
48/**
49 * Converts `value` to a string if it's not one. An empty string is returned
50 * for `null` or `undefined` values.
51 *
52 * @private
53 * @param {*} value The value to process.
54 * @returns {string} Returns the string.
55 */
56function baseToString(value) {
57 return value == null ? '' : (value + '');
58}
59
60module.exports = baseToString;
61
62},{}],3:[function(require,module,exports){
63
64// IN browserify context, fall back to a no op
65module.exports = function (cb) { cb() }
66
67
68},{}],4:[function(require,module,exports){
69'use strict';
70
71var _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
73function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
74
75var getIncidentEdgeIds = require('./getIncidentEdgeIds');
76var getOrphanEdgeIds = require('./getOrphanEdgeIds');
77var uniqueId = require('lodash.uniqueid');
78
79/**
80 * Hypergraph
81 * @class
82 *
83 * http://en.wikipedia.org/wiki/Hypergraph
84 *
85 * @class
86 * @param {Object} graph
87 */
88
89var 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 * @param {Array} nodeIds
102 * @returns {String} id
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 * @param {Any} data
118 * @returns {String} id
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 * @param {String} id
134 * @returns
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 * @param {String} id
150 * @returns {Any} data
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
172module.exports = Graph;
173
174},{"./getIncidentEdgeIds":7,"./getOrphanEdgeIds":8,"lodash.uniqueid":1}],5:[function(require,module,exports){
175"use strict";
176
177/**
178 * Compute adjacent nodes
179 *
180 * @param {Array} edges
181 * @param {String} nodeId
182 * @returns {Array} adjacentNodeIds
183 */
184
185var 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 // Nothing to do if edge does not contain nodeId.
200 if (edge.indexOf(nodeId) === -1) {
201 continue;
202 }
203
204 // Take all nodeIds except given nodeId, avoid repetitions.
205 var nodeIds = edge.filter(givenNodeId).filter(foundNodeIds);
206
207 adjacentNodeIds = adjacentNodeIds.concat(nodeIds);
208 }
209
210 return adjacentNodeIds;
211};
212
213module.exports = getAdjacentNodeIds;
214
215},{}],6:[function(require,module,exports){
216"use strict";
217
218/**
219 * The degree of a vertex is the number of incident edges, with loops counted twice.
220 *
221 * http://en.wikipedia.org/wiki/Degree_(graph_theory)
222 *
223 * @param {Array} edges
224 * @param {String} nodeId
225 * @returns {Number} degree
226 */
227
228var 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
246module.exports = getDegree;
247
248},{}],7:[function(require,module,exports){
249"use strict";
250
251/**
252 * Edges incident to given node
253 *
254 * @param {Array} edges
255 * @param {String} nodeId
256 * @returns {Array} incidentEdgeIds
257 */
258
259var 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
278module.exports = getIncidentEdgeIds;
279
280},{}],8:[function(require,module,exports){
281'use strict';
282
283/**
284 * Compute edges which does not refer to existing nodeIds
285 *
286 * @param {Array} edges
287 * @param {Array} nodes
288 * @param {Object} graph
289 * @returns {Array} orphanEdgeIds
290 */
291
292var 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
310module.exports = getOrphanEdgeIds;
311
312},{}],9:[function(require,module,exports){
313"use strict";
314
315/**
316 The rank is the maximum cardinality of any of the edges in the hypergraph
317 *
318 * @params {Array} edges
319 * @returns {Number} rank
320 */
321
322var 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
333module.exports = getRank;
334
335},{}],10:[function(require,module,exports){
336'use strict';
337
338require('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
351module.exports = require('./src');
352
353},{"./src":10}]},{},[]);