Skip to content

Commit de1d405

Browse files
committed
Move internal functions to separate files
1 parent 65f383f commit de1d405

File tree

6 files changed

+218
-41
lines changed

6 files changed

+218
-41
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
var CompactAdjacencyMatrix = require( './../lib' );
22+
23+
// Create a new adjacency matrix:
24+
var adj = new CompactAdjacencyMatrix( 4 );
25+
26+
// Add edges:
27+
adj.addEdge( 0, 1 );
28+
adj.addEdge( 0, 2 );
29+
adj.addEdge( 1, 2 );
30+
adj.addEdge( 2, 3 );
Original file line numberDiff line numberDiff line change
@@ -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;
Original file line numberDiff line numberDiff line change
@@ -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/utils/compact-adjacency-matrix
25+
*
26+
* @example
27+
* var CompactAdjacencyMatrix = require( '@stdlib/utils/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 CompactAdjacencyMatrix = require( './main.js' );
45+
46+
47+
// EXPORTS //
48+
49+
module.exports = CompactAdjacencyMatrix;
Original file line numberDiff line numberDiff line change
@@ -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+
* Checks whether a bit is set.
25+
*
26+
* @private
27+
* @param {integer32} value - integer value
28+
* @param {NonNegativeInteger} i - bit to check
29+
* @returns {boolean} boolean indicating whether a bit is set
30+
*
31+
* @example
32+
* var bool = isSet( 4, 2 );
33+
* // returns true
34+
*
35+
* bool = isSet( 4, 0 );
36+
* // returns false
37+
*/
38+
function isSet( value, i ) {
39+
return Boolean( ( value >> i ) & 1 );
40+
}
41+
42+
43+
// EXPORTS //
44+
45+
module.exports = isSet;

lib/node_modules/@stdlib/utils/compact-adjacency-matrix/lib/main.js

+8-41
Original file line numberDiff line numberDiff line change
@@ -27,54 +27,16 @@ var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-propert
2727
var Int32Array = require( '@stdlib/array/int32' );
2828
var ceil = require( '@stdlib/math/base/special/ceil' );
2929
var floor = require( '@stdlib/math/base/special/floor' );
30+
var setBit = require( './set_bit.js' );
31+
var clearBit = require( './clear_bit.js' );
32+
var isSet = require( './is_set.js' );
3033

3134

3235
// VARIABLES //
3336

3437
var NBITS = 32;
3538

3639

37-
// FUNCTIONS //
38-
39-
/**
40-
* Sets a bit.
41-
*
42-
* @private
43-
* @param {integer32} value - integer value
44-
* @param {NonNegativeInteger} i - bit to set
45-
* @returns {integer32} updated integer value
46-
*/
47-
function setBit( value, i ) {
48-
value |= 1 << i;
49-
return value;
50-
}
51-
52-
/**
53-
* Clears a bit.
54-
*
55-
* @private
56-
* @param {integer32} value - integer value
57-
* @param {NonNegativeInteger} i - bit to clear
58-
* @returns {integer32} updated integer value
59-
*/
60-
function clearBit( value, i ) {
61-
value &= ~( 1 << i );
62-
return value;
63-
}
64-
65-
/**
66-
* Checks whether a bit is set.
67-
*
68-
* @private
69-
* @param {integer32} value - integer value
70-
* @param {NonNegativeInteger} i - bit to check
71-
* @returns {boolean} boolean indicating whether a bit is set
72-
*/
73-
function isSet( value, i ) {
74-
return Boolean( ( value >> i ) & 1 );
75-
}
76-
77-
7840
// MAIN //
7941

8042
/**
@@ -88,6 +50,11 @@ function isSet( value, i ) {
8850
* @example
8951
* var adj = new CompactAdjacencyMatrix( 4 );
9052
* // returns <CompactAdjacencyMatrix>
53+
*
54+
* adj.addEdge( 0, 1 );
55+
* adj.addEdge( 0, 2 );
56+
* adj.addEdge( 1, 2 );
57+
* adj.addEdge( 2, 3 );
9158
*/
9259
function CompactAdjacencyMatrix( N ) {
9360
if ( !( this instanceof CompactAdjacencyMatrix ) ) {
Original file line numberDiff line numberDiff line change
@@ -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+
* Sets a bit.
25+
*
26+
* @private
27+
* @param {integer32} value - integer value
28+
* @param {NonNegativeInteger} i - bit to set
29+
* @returns {integer32} updated integer value
30+
*
31+
* @example
32+
* var v = setBit( 0, 2 );
33+
* // returns 4
34+
*/
35+
function setBit( value, i ) {
36+
value |= 1 << i;
37+
return value;
38+
}
39+
40+
41+
// EXPORTS //
42+
43+
module.exports = setBit;

0 commit comments

Comments
 (0)