|
1 | 1 | /** |
2 | 2 | * Keeps track of a set of elements partitioned into a |
3 | 3 | * number of disjoint (nonoverlapping) subsets. |
| 4 | + * Allows to check whether the path between two nodes exists. |
4 | 5 | * |
5 | 6 | * @example |
6 | 7 | * |
|
26 | 27 | * Initialization.<br><br> |
27 | 28 | * Complexity: O(N). |
28 | 29 | * |
| 30 | + * @public |
29 | 31 | * @constructor |
30 | 32 | * @param {Numner} size Count of the nodes. |
31 | 33 | */ |
32 | | - function QuickFind(size) { |
| 34 | + exports.QuickFind = function (size) { |
33 | 35 | this._ids = []; |
34 | 36 | for (var i = 0; i < size; i += 1) { |
35 | 37 | this._ids[i] = i; |
36 | 38 | } |
37 | | - } |
| 39 | + }; |
38 | 40 |
|
39 | 41 | /** |
40 | 42 | * Connects two nodes - p and q.<br><br> |
41 | 43 | * Complexity: O(N). |
42 | 44 | * |
| 45 | + * @public |
| 46 | + * @method |
43 | 47 | * @param {Number} p The first node. |
44 | 48 | * @param {Number} q The second node. |
45 | 49 | */ |
46 | | - QuickFind.prototype.union = function (p, q) { |
| 50 | + exports.QuickFind.prototype.union = function (p, q) { |
47 | 51 | var size = this._ids.length; |
48 | 52 | var pval = this._ids[p]; |
49 | 53 | var qval = this._ids[q]; |
|
58 | 62 | * Checks whether two nodes are connected.<br><br> |
59 | 63 | * Complexity: O(1). |
60 | 64 | * |
61 | | - * @param {number} p The first node. |
62 | | - * @param {number} q The second node. |
63 | | - * |
| 65 | + * @public |
| 66 | + * @method |
| 67 | + * @param {Number} p The first node. |
| 68 | + * @param {Number} q The second node. |
| 69 | + * @return {Boolean} |
64 | 70 | */ |
65 | | - QuickFind.prototype.connected = function (p, q) { |
| 71 | + exports.QuickFind.prototype.connected = function (p, q) { |
66 | 72 | return this._ids[p] === this._ids[q]; |
67 | 73 | }; |
68 | 74 |
|
69 | | - exports.QuickFind = QuickFind; |
70 | | - |
71 | 75 | })(typeof window === 'undefined' ? module.exports : window); |
0 commit comments