math.transforms.bwt: faster versions of Burrows-Wheeler Transform.
parent
16213f8779
commit
6f3f4e8fb8
|
@ -1,6 +1,6 @@
|
|||
! Copyright (C) 2012 John Benediktsson
|
||||
! See http://factorcode.org/license.txt for BSD license
|
||||
USING: strings tools.test ;
|
||||
USING: tools.test ;
|
||||
IN: math.transforms.bwt
|
||||
|
||||
{ "asdf" } [ "asdf" bwt ibwt >string ] unit-test
|
||||
{ "asdf" } [ "asdf" bwt ibwt ] unit-test
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
! Copyright (C) 2012 John Benediktsson
|
||||
! See http://factorcode.org/license.txt for BSD license
|
||||
USING: arrays fry kernel math sequences sequences.extras
|
||||
sorting ;
|
||||
USING: assocs fry kernel sequences sequences.rotated sorting ;
|
||||
IN: math.transforms.bwt
|
||||
|
||||
! Inefficient versions of Burrows-Wheeler Transform
|
||||
! Semi-efficient versions of Burrows-Wheeler Transform
|
||||
|
||||
: bwt ( seq -- newseq )
|
||||
0 suffix all-rotations natural-sort [ last ] map ;
|
||||
: bwt ( seq -- i newseq )
|
||||
dup all-rotations natural-sort
|
||||
[ [ sequence= ] with find drop ]
|
||||
[ [ last ] rot map-as ] 2bi ;
|
||||
|
||||
: ibwt ( newseq -- seq )
|
||||
[ length [ { } <array> ] keep ] keep
|
||||
'[ _ [ prefix ] 2map natural-sort ] times
|
||||
[ last 0 = ] find nip but-last ;
|
||||
: ibwt ( i newseq -- seq )
|
||||
[ length ]
|
||||
[ <enum> sort-values '[ _ nth first2 ] ]
|
||||
[ replicate-as ] tri nip ;
|
||||
|
|
Loading…
Reference in New Issue