-
Notifications
You must be signed in to change notification settings - Fork 2
/
multi-simple-example.js
40 lines (34 loc) · 988 Bytes
/
multi-simple-example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
* generate combinations of a multiset, with repetitions <= 256
*/
let log = console.log
, Geco = require( '../' )
, k = 3
, v = 4
// alloc test buffer setting repetitions to 2 (1 byte) for all elements
, brep = Buffer.alloc( v, 2 )
, iter = Geco.mget( k, v, brep )
, buff = null
, cnt = 0
, num = -1
, alen = brep.length
, list = null
, i = 0
, arep = []
;
for ( ; i < brep.length; ++i ) arep.push( brep[ i ] )
log( `\n- repetitions buffer is:`, brep );
log( `- 1 byte per element, ${arep.length} different types` );
log( `\n- generating all multiset combinations of:` );
log( ` - ${k} elements chosen from ${v} different types` );
log( ` - repetitions for every type are set (at max) to:`, arep, '\n' );
for ( buff of iter ) {
i = 0;
list = Array( alen ).fill( 0 )
for ( ; i < alen ; ++i ) {
num = buff[ i ];
if ( num ) list[ i ] = num;
}
log( ` ${++cnt}:`, buff, list );
}
log();