@stdlib/dstructs-compact-adjacency-matrix 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2021 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MAIN //
22
+
23
+ /**
24
+ * Returns the value (either `0` or `1`) of a specified bit.
25
+ *
26
+ * @private
27
+ * @param {integer32} value - integer value
28
+ * @param {NonNegativeInteger} i - bit number
29
+ * @returns {NonNegativeInteger} bit value
30
+ *
31
+ * @example
32
+ * var b = bitValue( 4, 2 );
33
+ * // returns 1
34
+ *
35
+ * b = bitValue( 4, 0 );
36
+ * // returns 0
37
+ */
38
+ function bitValue( value, i ) {
39
+ return ( value >> i ) & 1;
40
+ }
41
+
42
+
43
+ // EXPORTS //
44
+
45
+ module.exports = bitValue;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2021 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MAIN //
22
+
23
+ /**
24
+ * Clears a bit.
25
+ *
26
+ * @private
27
+ * @param {integer32} value - integer value
28
+ * @param {NonNegativeInteger} i - bit to clear
29
+ * @returns {integer32} updated integer value
30
+ *
31
+ * @example
32
+ * var v = clearBit( 5, 2 );
33
+ * // returns 1
34
+ */
35
+ function clearBit( value, i ) {
36
+ value &= ~( 1 << i );
37
+ return value;
38
+ }
39
+
40
+
41
+ // EXPORTS //
42
+
43
+ module.exports = clearBit;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2021 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var isCollection = require( '@stdlib/assert-is-collection' );
24
+ var format = require( '@stdlib/string-format' );
25
+
26
+
27
+ // MAIN //
28
+
29
+ /**
30
+ * Returns an array of iterated values.
31
+ *
32
+ * @private
33
+ * @param {Object} it - iterator
34
+ * @returns {(Array|TypeError)} array or an error
35
+ */
36
+ function fromIterator( it ) {
37
+ var out;
38
+ var v;
39
+ var z;
40
+
41
+ out = [];
42
+ while ( true ) {
43
+ v = it.next();
44
+ z = v.value;
45
+ if ( z ) {
46
+ if ( !isCollection( z ) ) {
47
+ return new TypeError( format( 'invalid argument. An iterator must return an array-like object containing vertices. Value: `%s`.', z ) );
48
+ }
49
+ out.push( z );
50
+ }
51
+ if ( v.done ) {
52
+ break;
53
+ }
54
+ }
55
+ return out;
56
+ }
57
+
58
+
59
+ // EXPORTS //
60
+
61
+ module.exports = fromIterator;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2021 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var isCollection = require( '@stdlib/assert-is-collection' );
24
+ var format = require( '@stdlib/string-format' );
25
+
26
+
27
+ // MAIN //
28
+
29
+ /**
30
+ * Returns an array of iterated values.
31
+ *
32
+ * @private
33
+ * @param {Object} it - iterator
34
+ * @param {Function} clbk - callback to invoke for each iterated value
35
+ * @param {*} thisArg - invocation context
36
+ * @returns {(Array|TypeError)} array or an error
37
+ */
38
+ function fromIteratorMap( it, clbk, thisArg ) {
39
+ var out;
40
+ var v;
41
+ var z;
42
+ var i;
43
+
44
+ out = [];
45
+ i = -1;
46
+ while ( true ) {
47
+ i += 1;
48
+ v = it.next();
49
+ z = v.value;
50
+ if ( z ) {
51
+ z = clbk.call( thisArg, z, i );
52
+ if ( !isCollection( z ) ) {
53
+ return new TypeError( format( 'invalid argument. Callback must return an array-like object containing vertices. Value: `%s`.', z ) );
54
+ }
55
+ out.push( z );
56
+ }
57
+ if ( v.done ) {
58
+ break;
59
+ }
60
+ }
61
+ return out;
62
+ }
63
+
64
+
65
+ // EXPORTS //
66
+
67
+ module.exports = fromIteratorMap;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2021 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var isCollection = require( '@stdlib/assert-is-collection' );
24
+ var format = require( '@stdlib/string-format' );
25
+
26
+
27
+ // MAIN //
28
+
29
+ /**
30
+ * Returns an array of iterated values.
31
+ *
32
+ * @private
33
+ * @param {Object} it - iterator
34
+ * @returns {(Array|TypeError)} array or an error
35
+ */
36
+ function fromIterator( it ) {
37
+ var out;
38
+ var v;
39
+ var z;
40
+
41
+ out = [];
42
+ while ( true ) {
43
+ v = it.next();
44
+ z = v.value;
45
+ if ( z ) {
46
+ if ( !isCollection( z ) ) {
47
+ return new TypeError( format( 'invalid argument. An iterator must return an array-like object containing vertices. Value: `%s`.', z ) );
48
+ }
49
+ out.push( z[ 0 ], z[ 1 ] );
50
+ }
51
+ if ( v.done ) {
52
+ break;
53
+ }
54
+ }
55
+ return out;
56
+ }
57
+
58
+
59
+ // EXPORTS //
60
+
61
+ module.exports = fromIterator;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2021 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var isCollection = require( '@stdlib/assert-is-collection' );
24
+ var format = require( '@stdlib/string-format' );
25
+
26
+
27
+ // MAIN //
28
+
29
+ /**
30
+ * Returns an array of iterated values.
31
+ *
32
+ * @private
33
+ * @param {Object} it - iterator
34
+ * @param {Function} clbk - callback to invoke for each iterated value
35
+ * @param {*} thisArg - invocation context
36
+ * @returns {(Array|TypeError)} array or an error
37
+ */
38
+ function fromIteratorMap( it, clbk, thisArg ) {
39
+ var out;
40
+ var v;
41
+ var z;
42
+ var i;
43
+
44
+ out = [];
45
+ i = -1;
46
+ while ( true ) {
47
+ i += 1;
48
+ v = it.next();
49
+ z = v.value;
50
+ if ( z ) {
51
+ z = clbk.call( thisArg, z, i );
52
+ if ( !isCollection( z ) ) {
53
+ return new TypeError( format( 'invalid argument. Callback must return an array-like object containing vertices. Value: `%s`.', z ) );
54
+ }
55
+ out.push( z[ 0 ], z[ 1 ] );
56
+ }
57
+ if ( v.done ) {
58
+ break;
59
+ }
60
+ }
61
+ return out;
62
+ }
63
+
64
+
65
+ // EXPORTS //
66
+
67
+ module.exports = fromIteratorMap;
package/lib/index.js ADDED
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2021 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ /**
22
+ * Compact adjacency matrix.
23
+ *
24
+ * @module @stdlib/dstructs-compact-adjacency-matrix
25
+ *
26
+ * @example
27
+ * var CompactAdjacencyMatrix = require( '@stdlib/dstructs-compact-adjacency-matrix' );
28
+ *
29
+ * var adj = new CompactAdjacencyMatrix( 4 );
30
+ * // returns <CompactAdjacencyMatrix>
31
+ *
32
+ * // ...
33
+ *
34
+ * adj.addEdge( 0, 1 );
35
+ * adj.addEdge( 0, 2 );
36
+ * adj.addEdge( 1, 2 );
37
+ * adj.addEdge( 2, 3 );
38
+ *
39
+ * // ...
40
+ */
41
+
42
+ // MODULES //
43
+
44
+ var main = require( './main.js' );
45
+
46
+
47
+ // EXPORTS //
48
+
49
+ module.exports = main;
package/lib/is_set.js ADDED
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2021 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var Boolean = require( '@stdlib/boolean-ctor' );
24
+
25
+
26
+ // MAIN //
27
+
28
+ /**
29
+ * Checks whether a bit is set.
30
+ *
31
+ * @private
32
+ * @param {integer32} value - integer value
33
+ * @param {NonNegativeInteger} i - bit to check
34
+ * @returns {boolean} boolean indicating whether a bit is set
35
+ *
36
+ * @example
37
+ * var bool = isSet( 4, 2 );
38
+ * // returns true
39
+ *
40
+ * bool = isSet( 4, 0 );
41
+ * // returns false
42
+ */
43
+ function isSet( value, i ) {
44
+ return Boolean( ( value >> i ) & 1 );
45
+ }
46
+
47
+
48
+ // EXPORTS //
49
+
50
+ module.exports = isSet;