Comparing version 0.0.27 to 0.0.28
@@ -115,2 +115,28 @@ /* | ||
sproto.sparse = function ( data ) { | ||
var me = this | ||
, bcomp = me.bcompare | ||
, brange = me.brange | ||
, result = me.result | ||
, tbytes = me.tbytes | ||
, ibytes = me.ibytes | ||
, bits = me.bits | ||
, ibits = me.ibits | ||
, cmask = masks[ ibits - bits ] | ||
, dlen = data.length | ||
, l = dlen - ibytes | ||
, o = 0 | ||
; | ||
// copy a value at a time from random source to results. | ||
for ( ; me.wpos < tbytes; o += ibytes ) { | ||
if ( o > l ) return me.emit( 'feed', tbytes - me.wpos ); | ||
data[ o ] &= cmask; | ||
if ( ~ bcomp( data, o ) ) { | ||
data.copy( result, me.wpos, o, o + ibytes ); | ||
me.wpos += ibytes; | ||
} | ||
} | ||
return me.emit( 'fart', me.result ); | ||
}; | ||
sproto.parse = function ( data ) { | ||
@@ -139,5 +165,10 @@ var me = this | ||
* When results are available, it emits 'fart' event, with the result Buffer. | ||
* | ||
* NOTE: when the range is within 2^(8), 2^(16), 2^(24), 2^(32), | ||
* the probability to discard an element, parsed form the random | ||
* source, decreases; then, it's better to copy an entire slice | ||
* of values, instead of a value at a time (#sparse method). | ||
*/ | ||
for ( ; me.wpos < tbytes; o += ibytes ) { | ||
if ( o > l ) return me.emit( 'feed', tbytes - me.wpos - 1 ); | ||
if ( o > l ) return me.emit( 'feed', tbytes - me.wpos ); | ||
data[ o ] &= cmask; | ||
@@ -160,3 +191,3 @@ if ( ~ bcomp( data, o ) ) { | ||
me.emit( 'fart', me.result ) : | ||
me.emit( 'feed', tbytes - me.wpos - 1 ) | ||
me.emit( 'feed', tbytes - me.wpos ) | ||
; | ||
@@ -163,0 +194,0 @@ }; |
{ | ||
"name": "brando" | ||
, "version": "0.0.27" | ||
, "version": "0.0.28" | ||
, "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
40677
786