-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbop-sparse-example.js
48 lines (33 loc) · 1.05 KB
/
bop-sparse-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
41
42
43
44
45
46
47
48
/*
* Bop#sparse Bop#parse and Bop#sparse example
*/
var log = console.log
, Bop = require( '../' )
, hello = '------hello'
, line = new Buffer( hello + hello )
, bop = Bop( line )
, llen = line.length
, l = 8
, data = new Buffer( 23 + llen * l )
, i = 0
, matches = null
, cnt = -1
;
log( '- pattern is:', bop.p );
log( '- fill data with %d patterns', l );
/*
* NOTE: it builds example data using Buffer#copy, instead of
* Buffer#concat, to mantain retro compatibility with older
* nodejs versions.
*/
for ( ; i < l; ++i ) line.copy( data, 23 + i * llen );
matches = bop.parse( data );
log( '\n-> use #parse (overlapping sequences).' );
log( '- bop.parse(data) matches:', matches.length );
cnt = bop.count( data )
log( '- bop.count(data):', cnt );
matches = bop.sparse( data );
log( '\n-> use #sparse (no overlapping sequences).' );
log( '- bop.sparse(data) matches:', matches.length );
cnt = bop.count( data, 0, true )
log( '- bop.count(data, true):', cnt );