File tree Expand file tree Collapse file tree 5 files changed +42
-41
lines changed Expand file tree Collapse file tree 5 files changed +42
-41
lines changed Original file line number Diff line number Diff line change 151
151
return contains ( point , this . root ) ;
152
152
} ;
153
153
154
+ function intersects ( a , b ) {
155
+ return ( a [ 0 ] <= b [ 0 ] && a [ 1 ] >= b [ 0 ] ) || ( a [ 0 ] <= b [ 1 ] && a [ 1 ] >= b [ 1 ] ) ||
156
+ ( b [ 0 ] <= a [ 0 ] && b [ 1 ] >= a [ 0 ] ) || ( b [ 0 ] <= a [ 1 ] && b [ 1 ] >= a [ 1 ] ) ;
157
+ }
158
+
154
159
function intersectsHelper ( interval , node ) {
155
160
if ( ! node ) {
156
161
return false ;
169
174
return result ;
170
175
}
171
176
172
- function intersects ( a , b ) {
173
- return ( a [ 0 ] <= b [ 0 ] && a [ 1 ] >= b [ 0 ] ) || ( a [ 0 ] <= b [ 1 ] && a [ 1 ] >= b [ 1 ] ) ||
174
- ( b [ 0 ] <= a [ 0 ] && b [ 1 ] >= a [ 0 ] ) || ( b [ 0 ] <= a [ 1 ] && b [ 1 ] >= a [ 1 ] ) ;
175
- }
176
-
177
177
/**
178
178
* Checks or interval belongs to at least one intarval from the tree.<br><br>
179
179
* Complexity: O(log N).
Original file line number Diff line number Diff line change 1
1
( function ( exports ) {
2
2
'use strict' ;
3
3
4
+ /**
5
+ * Draws (prints) the given coordinates
6
+ * @param {number } x The first coordinate of the point
7
+ * @param {number } y The second coordinate of the point
8
+ */
9
+ function drawPoint ( x , y ) {
10
+ console . log ( x , y ) ;
11
+ }
12
+
4
13
/**
5
14
* Bresenham's line drawing algorithm.
6
15
* It has complexity O(n)
33
42
}
34
43
}
35
44
36
- /**
37
- * Draws (prints) the given coordinates
38
- * @param {number } x The first coordinate of the point
39
- * @param {number } y The second coordinate of the point
40
- */
41
- function drawPoint ( x , y ) {
42
- console . log ( x , y ) ;
43
- }
44
-
45
45
exports . drawLine = drawLine ;
46
46
47
47
} ( typeof exports === 'undefined' ? window : exports ) ) ;
Original file line number Diff line number Diff line change 71
71
exports . Graph . prototype . prim = ( function ( ) {
72
72
var queue ;
73
73
74
- /**
75
- * Initialize the algorithm.
76
- *
77
- * @private
78
- */
79
- function init ( ) {
80
- queue = new Heap ( compareEdges ) ;
81
- }
82
-
83
74
/**
84
75
* Used for comparitions in the heap
85
76
*
94
85
return b . distance - a . distance ;
95
86
}
96
87
88
+ /**
89
+ * Initialize the algorithm.
90
+ *
91
+ * @private
92
+ */
93
+ function init ( ) {
94
+ queue = new Heap ( compareEdges ) ;
95
+ }
96
+
97
97
return function ( ) {
98
98
init . call ( this ) ;
99
99
var inTheTree = { } ;
Original file line number Diff line number Diff line change 1
1
( function ( exports ) {
2
2
'use strict' ;
3
3
4
+ function id ( val ) { return val ; }
5
+ function get ( key ) { return function ( val ) { return val [ key ] ; } ; }
6
+
4
7
/**
5
8
* Searchs for specific element in a given array using
6
9
* the binary search algorithm.<br><br>
37
40
}
38
41
return - middle - 1 ;
39
42
}
40
- function id ( val ) { return val ; }
41
- function get ( key ) { return function ( val ) { return val [ key ] ; } ; }
42
43
43
44
exports . binarySearch = binarySearch ;
44
45
Original file line number Diff line number Diff line change 13
13
return a - b ;
14
14
}
15
15
16
+ /**
17
+ * Swap the places of two elements
18
+ *
19
+ * @private
20
+ * @param {array } array The array which contains the elements
21
+ * @param {number } i The index of the first element
22
+ * @param {number } j The index of the second element
23
+ * @returns {array } array The array with swaped elements
24
+ */
25
+ function swap ( array , i , j ) {
26
+ var temp = array [ i ] ;
27
+ array [ i ] = array [ j ] ;
28
+ array [ j ] = temp ;
29
+ return array ;
30
+ }
31
+
16
32
/**
17
33
* Partitions given subarray using Lomuto's partitioning algorithm.
18
34
*
35
51
return minEnd ;
36
52
}
37
53
38
- /**
39
- * Swap the places of two elements
40
- *
41
- * @private
42
- * @param {array } array The array which contains the elements
43
- * @param {number } i The index of the first element
44
- * @param {number } j The index of the second element
45
- * @returns {array } array The array with swaped elements
46
- */
47
- function swap ( array , i , j ) {
48
- var temp = array [ i ] ;
49
- array [ i ] = array [ j ] ;
50
- array [ j ] = temp ;
51
- return array ;
52
- }
53
-
54
54
/**
55
55
* Sorts given array.
56
56
*
You can’t perform that action at this time.
0 commit comments