extra-bit.web 2.0.3 → 2.1.2
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.
- package/README.md +7 -7
- package/index.d.ts +6 -37
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@ The [bit] is a basic unit of information in information theory, computing.
|
|
|
2
2
|
This package includes [bit twiddling hacks] by Sean Eron Anderson and many others.<br>
|
|
3
3
|
📦 [Node.js](https://www.npmjs.com/package/extra-bit),
|
|
4
4
|
🌐 [Web](https://www.npmjs.com/package/extra-bit.web),
|
|
5
|
-
📜 [Files](https://unpkg.com/extra-bit
|
|
5
|
+
📜 [Files](https://unpkg.com/extra-bit/),
|
|
6
6
|
📰 [Docs](https://nodef.github.io/extra-bit/).
|
|
7
7
|
📘 [Wiki](https://github.com/nodef/extra-bit/wiki/).
|
|
8
8
|
|
|
@@ -19,22 +19,22 @@ is exposed as `extra_bit` standalone variable and can be loaded from
|
|
|
19
19
|
```javascript
|
|
20
20
|
const bit = require('extra-bit');
|
|
21
21
|
// import * as bit from "extra-bit";
|
|
22
|
-
// import * as bit from "https://unpkg.com/extra-bit
|
|
22
|
+
// import * as bit from "https://unpkg.com/extra-bit/index.mjs"; (deno)
|
|
23
23
|
|
|
24
24
|
bit.count(7);
|
|
25
|
-
// 3 (111 ⇒ 3)
|
|
25
|
+
// → 3 (111 ⇒ 3)
|
|
26
26
|
|
|
27
27
|
bit.parity(8, 2);
|
|
28
|
-
// 2 (10,00 ⇒ 10)
|
|
28
|
+
// → 2 (10,00 ⇒ 10)
|
|
29
29
|
|
|
30
30
|
bit.swap(6, 1, 0);
|
|
31
|
-
// 5 (110 ⇒ 101)
|
|
31
|
+
// → 5 (110 ⇒ 101)
|
|
32
32
|
|
|
33
33
|
bit.reverse(0xFFFF0000);
|
|
34
|
-
// 65535 (0x0000FFFF)
|
|
34
|
+
// → 65535 (0x0000FFFF)
|
|
35
35
|
|
|
36
36
|
bit.signExtend(15, 4);
|
|
37
|
-
// -1
|
|
37
|
+
// → -1
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
<br>
|
package/index.d.ts
CHANGED
|
@@ -1,30 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Get
|
|
2
|
+
* Get bits at specified index.
|
|
3
3
|
* @param x an int32
|
|
4
4
|
* @param i bit index
|
|
5
5
|
* @param w bit width (1)
|
|
6
6
|
*/
|
|
7
7
|
declare function get(x: number, i: number, w?: number): number;
|
|
8
|
-
//# sourceMappingURL=get.d.ts.map
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Get bits as per mask.
|
|
12
10
|
* @param x an int32
|
|
13
11
|
* @param m bit mask
|
|
14
12
|
*/
|
|
15
13
|
declare function getAs(x: number, m: number): number;
|
|
16
|
-
//# sourceMappingURL=getAs.d.ts.map
|
|
17
|
-
|
|
18
14
|
/**
|
|
19
|
-
* Set
|
|
15
|
+
* Set bits at specified index.
|
|
20
16
|
* @param x an int32
|
|
21
17
|
* @param i bit index
|
|
22
18
|
* @param v bit value (1)
|
|
23
19
|
* @param w bit width (1)
|
|
24
20
|
*/
|
|
25
21
|
declare function set(x: number, i: number, v?: number, w?: number): number;
|
|
26
|
-
//# sourceMappingURL=set.d.ts.map
|
|
27
|
-
|
|
28
22
|
/**
|
|
29
23
|
* Set bits as per mask.
|
|
30
24
|
* @param x an int32
|
|
@@ -32,79 +26,59 @@ declare function set(x: number, i: number, v?: number, w?: number): number;
|
|
|
32
26
|
* @param f bit value (1)
|
|
33
27
|
*/
|
|
34
28
|
declare function setAs(x: number, m: number, f?: number): number;
|
|
35
|
-
//# sourceMappingURL=setAs.d.ts.map
|
|
36
|
-
|
|
37
29
|
/**
|
|
38
|
-
* Toggle
|
|
30
|
+
* Toggle bits at specified index.
|
|
39
31
|
* @param x an int32
|
|
40
32
|
* @param i bit index
|
|
41
33
|
* @param w bit width (1)
|
|
42
34
|
*/
|
|
43
35
|
declare function toggle(x: number, i: number, w?: number): number;
|
|
44
|
-
//# sourceMappingURL=toggle.d.ts.map
|
|
45
|
-
|
|
46
36
|
/**
|
|
47
37
|
* Toggle bits as per mask.
|
|
48
38
|
* @param x an int32
|
|
49
39
|
* @param m bit mask
|
|
50
40
|
*/
|
|
51
41
|
declare function toggleAs(x: number, m: number): number;
|
|
52
|
-
//# sourceMappingURL=toggleAs.d.ts.map
|
|
53
|
-
|
|
54
42
|
/**
|
|
55
|
-
* Swap bit sequences.
|
|
43
|
+
* Swap bit sequences at specified indices.
|
|
56
44
|
* @param x an int32
|
|
57
45
|
* @param i first bit index
|
|
58
46
|
* @param j second bit index
|
|
59
47
|
* @param w bit width (1)
|
|
60
48
|
*/
|
|
61
49
|
declare function swap(x: number, i: number, j: number, w?: number): number;
|
|
62
|
-
//# sourceMappingURL=swap.d.ts.map
|
|
63
|
-
|
|
64
50
|
/**
|
|
65
51
|
* Find index of first set bit from LSB.
|
|
66
52
|
* @param x an int32
|
|
67
53
|
*/
|
|
68
54
|
declare function scan(x: number): number;
|
|
69
|
-
//# sourceMappingURL=scan.d.ts.map
|
|
70
|
-
|
|
71
55
|
/**
|
|
72
56
|
* Find index of first set bit from MSB.
|
|
73
57
|
* @param x an int32
|
|
74
58
|
*/
|
|
75
59
|
declare function scanReverse(x: number): number;
|
|
76
|
-
//# sourceMappingURL=scanReverse.d.ts.map
|
|
77
|
-
|
|
78
60
|
/**
|
|
79
61
|
* Count bits set.
|
|
80
62
|
* @param x an int32
|
|
81
63
|
*/
|
|
82
64
|
declare function count(x: number): number;
|
|
83
|
-
//# sourceMappingURL=count.d.ts.map
|
|
84
|
-
|
|
85
65
|
/**
|
|
86
|
-
*
|
|
66
|
+
* Calculate n-bit parity.
|
|
87
67
|
* @param x an int32
|
|
88
68
|
* @param n number of bits (1)
|
|
89
69
|
*/
|
|
90
70
|
declare function parity(x: number, n?: number): number;
|
|
91
|
-
//# sourceMappingURL=parity.d.ts.map
|
|
92
|
-
|
|
93
71
|
/**
|
|
94
|
-
* Rotate bits.
|
|
72
|
+
* Rotate bits by a certain amount.
|
|
95
73
|
* @param x an int32
|
|
96
74
|
* @param n rotate amount (+ve: left, -ve: right)
|
|
97
75
|
*/
|
|
98
76
|
declare function rotate(x: number, n?: number): number;
|
|
99
|
-
//# sourceMappingURL=rotate.d.ts.map
|
|
100
|
-
|
|
101
77
|
/**
|
|
102
78
|
* Reverse all bits.
|
|
103
79
|
* @param x an int32
|
|
104
80
|
*/
|
|
105
81
|
declare function reverse(x: number): number;
|
|
106
|
-
//# sourceMappingURL=reverse.d.ts.map
|
|
107
|
-
|
|
108
82
|
/**
|
|
109
83
|
* Merge bits as per mask.
|
|
110
84
|
* @param x first int32
|
|
@@ -112,8 +86,6 @@ declare function reverse(x: number): number;
|
|
|
112
86
|
* @param m bit mask (0 ⇒ from x)
|
|
113
87
|
*/
|
|
114
88
|
declare function merge(x: number, y: number, m: number): number;
|
|
115
|
-
//# sourceMappingURL=merge.d.ts.map
|
|
116
|
-
|
|
117
89
|
/**
|
|
118
90
|
* Interleave bits of two int16s.
|
|
119
91
|
* @param x first int16
|
|
@@ -121,14 +93,11 @@ declare function merge(x: number, y: number, m: number): number;
|
|
|
121
93
|
* @returns int32
|
|
122
94
|
*/
|
|
123
95
|
declare function interleave(x: number, y: number): number;
|
|
124
|
-
//# sourceMappingURL=interleave.d.ts.map
|
|
125
|
-
|
|
126
96
|
/**
|
|
127
97
|
* Sign extend variable bit-width integer.
|
|
128
98
|
* @param x variable bit-width integer
|
|
129
99
|
* @param w bit width (32)
|
|
130
100
|
*/
|
|
131
101
|
declare function signExtend(x: number, w?: number): number;
|
|
132
|
-
//# sourceMappingURL=signExtend.d.ts.map
|
|
133
102
|
|
|
134
103
|
export { count, get, getAs, interleave, merge, parity, reverse, rotate, scan, scanReverse, set, setAs, signExtend, swap, toggle, toggleAs };
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(n){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).extra_bit=n()}}((function(){return function n(e,r
|
|
1
|
+
!function(n){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).extra_bit=n()}}((function(){return function n(e,t,r){function u(f,i){if(!t[f]){if(!e[f]){var c="function"==typeof require&&require;if(!i&&c)return c(f,!0);if(o)return o(f,!0);var s=new Error("Cannot find module '"+f+"'");throw s.code="MODULE_NOT_FOUND",s}var d=t[f]={exports:{}};e[f][0].call(d.exports,(function(n){return u(e[f][1][n]||n)}),d,d.exports,n,e,t,r)}return t[f].exports}for(var o="function"==typeof require&&require,f=0;f<r.length;f++)u(r[f]);return u}({1:[function(n,e,t){"use strict";function r(n){return(1<<n)-1}Object.defineProperty(t,"__esModule",{value:!0});const u=[32,0,1,26,2,23,27,0,3,16,24,30,28,11,0,13,4,7,17,0,25,22,31,15,29,10,12,6,0,21,14,9,5,20,8,19,18];const o=[0,9,1,10,13,21,2,29,11,14,16,18,22,25,3,30,8,12,20,28,15,17,24,7,19,27,23,6,26,5,4,31];t.count=function(n){return 16843009*((n=(858993459&(n-=n>>>1&1431655765))+(n>>>2&858993459))+(n>>>4)&252645135)>>>24},t.get=function(n,e,t=1){return n>>>e&r(t)},t.getAs=function(n,e){return n&e},t.interleave=function(n,e){return(e=1431655765&((e=858993459&((e=252645135&((e=16711935&(e|e<<8))|e<<4))|e<<2))|e<<1))|(n=1431655765&((n=858993459&((n=252645135&((n=16711935&(n|n<<8))|n<<4))|n<<2))|n<<1))<<1},t.merge=function(n,e,t){return n^(n^e)&t},t.parity=function(n,e=1){if(1===e)return function(n){return n^=n>>>16,n^=n>>>8,n^=n>>>4,27030>>>(n&=15)&1}(n);for(var t=(1<<e)-1,r=0;n;)r^=n&t,n>>>=e;return r},t.reverse=function(n){return(n=(n=(n=(n=n>>>1&1431655765|(1431655765&n)<<1)>>>2&858993459|(858993459&n)<<2)>>>4&252645135|(252645135&n)<<4)>>>8&16711935|(16711935&n)<<8)>>>16|n<<16},t.rotate=function(n,e=0){return e<0?n<<32+e|n>>>-e:n<<e|n>>32-e},t.scan=function(n){return u[(-n&n)%37]},t.scanReverse=function(n){return n|=n>>>1,n|=n>>>2,n|=n>>>4,n|=n>>>8,o[130329821*(n|=n>>>16)>>>27]},t.set=function(n,e,t=1,u=1){return n&~(r(u)<<e)|t<<e},t.setAs=function(n,e,t=1){return n&~e|-t&e},t.signExtend=function(n,e=32){return n<<(e=32-e)>>e},t.swap=function(n,e,t,u=1){var o=(n>>>e^n>>>t)&r(u);return n^(o<<e|o<<t)},t.toggle=function(n,e,t=1){return n^r(t)<<e},t.toggleAs=function(n,e){return n^e}},{}]},{},[1])(1)}));
|
package/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function ones(n){return(1<<n)-1}function get(n,t,e=1){return n>>>t&ones(e)}function getAs(n,t){return n&t}function set(n,t,e=1,r=1){return n&~(ones(r)<<t)|e<<t}function setAs(n,t,e=1){return n&~t|-e&t}function toggle(n,t,e=1){return n^ones(e)<<t}function toggleAs(n,t){return n^t}function swap(n,t,e,r=1){var u=(n>>>t^n>>>e)&ones(r);return n^(u<<t|u<<e)}const MOD37_POS32=[32,0,1,26,2,23,27,0,3,16,24,30,28,11,0,13,4,7,17,0,25,22,31,15,29,10,12,6,0,21,14,9,5,20,8,19,18];
|
|
1
|
+
function ones(n){return(1<<n)-1}function get(n,t,e=1){return n>>>t&ones(e)}function getAs(n,t){return n&t}function set(n,t,e=1,r=1){return n&~(ones(r)<<t)|e<<t}function setAs(n,t,e=1){return n&~t|-e&t}function toggle(n,t,e=1){return n^ones(e)<<t}function toggleAs(n,t){return n^t}function swap(n,t,e,r=1){var u=(n>>>t^n>>>e)&ones(r);return n^(u<<t|u<<e)}const MOD37_POS32=[32,0,1,26,2,23,27,0,3,16,24,30,28,11,0,13,4,7,17,0,25,22,31,15,29,10,12,6,0,21,14,9,5,20,8,19,18];function scan(n){return MOD37_POS32[(-n&n)%37]}const DEBRUIJN_POS32=[0,9,1,10,13,21,2,29,11,14,16,18,22,25,3,30,8,12,20,28,15,17,24,7,19,27,23,6,26,5,4,31];function scanReverse(n){return n|=n>>>1,n|=n>>>2,n|=n>>>4,n|=n>>>8,DEBRUIJN_POS32[130329821*(n|=n>>>16)>>>27]}function count(n){return 16843009*((n=(858993459&(n-=n>>>1&1431655765))+(n>>>2&858993459))+(n>>>4)&252645135)>>>24}function parity1(n){return n^=n>>>16,n^=n>>>8,n^=n>>>4,27030>>>(n&=15)&1}function parity(n,t=1){if(1===t)return parity1(n);for(var e=(1<<t)-1,r=0;n;)r^=n&e,n>>>=t;return r}function rotate(n,t=0){return t<0?n<<32+t|n>>>-t:n<<t|n>>32-t}function reverse(n){return(n=(n=(n=(n=n>>>1&1431655765|(1431655765&n)<<1)>>>2&858993459|(858993459&n)<<2)>>>4&252645135|(252645135&n)<<4)>>>8&16711935|(16711935&n)<<8)>>>16|n<<16}function merge(n,t,e){return n^(n^t)&e}function interleave(n,t){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&(t|t<<8))|t<<4))|t<<2))|t<<1))|(n=1431655765&((n=858993459&((n=252645135&((n=16711935&(n|n<<8))|n<<4))|n<<2))|n<<1))<<1}function signExtend(n,t=32){return n<<(t=32-t)>>t}export{count,get,getAs,interleave,merge,parity,reverse,rotate,scan,scanReverse,set,setAs,signExtend,swap,toggle,toggleAs};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "extra-bit.web",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "The bit is a basic unit of information in information theory, computing.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "index.js",
|
|
@@ -45,11 +45,10 @@
|
|
|
45
45
|
},
|
|
46
46
|
"homepage": "https://github.com/nodef/extra-bit#readme",
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@rollup/plugin-commonjs": "^
|
|
49
|
-
"@rollup/plugin-node-resolve": "^13.
|
|
50
|
-
"
|
|
51
|
-
"extra-build": "^2.0.31",
|
|
48
|
+
"@rollup/plugin-commonjs": "^22.0.1",
|
|
49
|
+
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
50
|
+
"extra-build": "^2.1.31",
|
|
52
51
|
"rollup-plugin-cleanup": "^3.2.1",
|
|
53
|
-
"rollup-plugin-dts": "^4.2.
|
|
52
|
+
"rollup-plugin-dts": "^4.2.2"
|
|
54
53
|
}
|
|
55
54
|
}
|