Comparing version 0.0.37 to 0.0.38
@@ -42,11 +42,11 @@ var log = console.log | ||
// test( 8, 1024 * 1024 + 1 ); | ||
test( 1, 1024 * 1024 ); | ||
test( 4, 1024 * 1024 + 1 ); | ||
test( 4, 1024 * 1024 ); | ||
// 8 bits numbers, 1 byte | ||
test( 1, 256 ); | ||
test( 1, 128 ); | ||
test( 1, 129 ); | ||
//test( 1, 256 ); | ||
//test( 1, 128 ); | ||
//test( 1, 129 ); | ||
log(); |
@@ -63,3 +63,3 @@ /* | ||
for ( ; i < o; i += ibytes ) result[ wuint ]( i, i ); | ||
me.shuffle( 1 ); | ||
// me.shuffle( 1 ); | ||
return me; | ||
@@ -69,7 +69,6 @@ }; | ||
/* | ||
* Full range permutations (FP) uses random data only for shuffling | ||
* the result Buffer, with Fisher-Yates algorithm. | ||
* the parse method for full range permutations (FPs), uses the random data | ||
* only for shuffling the result Buffer, using the Fisher-Yates algorithm. | ||
* To shuffle r elements (0,r-1): | ||
* | ||
* To shuffle r elements (indexes from r - 1 downto 0): | ||
* | ||
* var i = r − 1 | ||
@@ -80,3 +79,10 @@ * , a = [ .. ] | ||
* | ||
* random method should return a number >=0 && <=i. | ||
* NOTE: random(0,i) should return a number between >=0 && <=i. | ||
* | ||
* CAVE CANEM: I restrict the range of parsed values, on every iteration, to the | ||
* current writing index (me.wpos), using a bitwise mask; in this manner we have | ||
* a probability to find a good value of at least 1/2 on every iteration, it ensure | ||
* that the algorithm converges quickly; otherwise it could run indefinitively, | ||
* consuming a lot of random data, also to produce only a short-size full range | ||
* permutation. The bad aspect: it will probably produce more biased results. | ||
* | ||
@@ -99,3 +105,6 @@ */ | ||
, r = -1 | ||
, wbits = .1 | ||
, wmask = -1 | ||
, wbits = -1 | ||
, wibits = -1 | ||
, wibytes = -1 | ||
; | ||
@@ -106,3 +115,9 @@ | ||
data[ o ] &= cmask; | ||
if ( ( r = ( ( data[ ruint ]( o ) ) * ibytes ) ) > me.wpos ) continue; | ||
// calculate mask to apply to parsed values | ||
wbits = max( ceil( dlog( me.wpos ) / log2 ), 1 ); | ||
wibytes = max( ceil( wbits / 8 ), 1 ); | ||
wibits = wibytes << 3 >>> 0; | ||
wmask = masks[ wibits - wbits ]; | ||
// after reading the value, apply wpos mask | ||
if ( ( r = ( data[ ruint ]( o ) & wmask ) * ibytes ) > me.wpos ) continue; | ||
swap( result, me.wpos, r, ibytes ); | ||
@@ -109,0 +124,0 @@ me.wpos -= ibytes; |
@@ -38,5 +38,4 @@ /* | ||
/* | ||
* Get how many bits and bytes are necessary to | ||
* represent values in the specified range, min | ||
* is 1 byte. | ||
* Get how many bits and bytes are necessary to* represent values in the | ||
* specified range, minimum value is 1 byte. | ||
*/ | ||
@@ -43,0 +42,0 @@ me.range = r >>> 0 ? abs( r ) : 1; |
{ | ||
"name": "brando" | ||
, "version": "0.0.37" | ||
, "version": "0.0.38" | ||
, "description": "Brando." | ||
@@ -5,0 +5,0 @@ , "homepage": "https://github.com/rootslab/brando" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49601
988