File tree Expand file tree Collapse file tree 1 file changed +14
-13
lines changed Expand file tree Collapse file tree 1 file changed +14
-13
lines changed Original file line number Diff line number Diff line change
1
+ /* eslint-disable no-undef */
1
2
'use strict' ;
2
3
3
- const ids = function * ( ) {
4
- const free = [ '0' ] ;
5
- const prepared = { has : false , value : '' } ;
4
+ const BIG_ONE = BigInt ( 1 ) ;
5
+ const BIG_ZERO = BigInt ( 0 ) ;
6
6
7
- while ( true ) {
8
- if ( prepared . has ) {
9
- prepared . has = false ;
10
- yield prepared . value ;
7
+ const ids = function * ( ) {
8
+ for ( let i = BIG_ONE ; ; i ++ ) {
9
+ const base = BIG_ONE << ( i << BIG_ONE ) ;
10
+ for ( let j = BIG_ZERO ; j < BIG_ONE << i ; j ++ ) {
11
+ let value = base ;
12
+ for ( let k = BIG_ZERO ; k <= Math . log2 ( Number ( j ) ) ; k ++ ) {
13
+ if ( j / ( BIG_ONE << k ) & BIG_ONE ) {
14
+ value |= BIG_ONE << ( k << BIG_ONE ) + BIG_ONE ;
15
+ }
16
+ }
17
+ yield value . toString ( 2 ) ;
11
18
}
12
- const nextFree = free . shift ( ) ;
13
- free . push ( '01' + nextFree ) ;
14
- free . push ( '00' + nextFree ) ;
15
- prepared . value = '11' + nextFree ;
16
- prepared . has = true ;
17
- yield '10' + nextFree ;
18
19
}
19
20
} ;
20
21
You can’t perform that action at this time.
0 commit comments