Paste: suffix-array 2
Author: | prunedtree |
Mode: | factor |
Date: | Wed, 1 Oct 2008 18:15:40 |
Plain Text |
USING: kernel arrays math accessors sequences math.vectors math.order sorting
binary-search sets assocs fry parser ;
IN: suffix-array
: suffixes dup length [ tail-slice ] with map ;
: >suffix-array [ suffixes ] map concat natural-sort ;
: SA{ \ } [ >suffix-array ] parse-literal ; parsing
: prefix<=> [ swap <=> ] [ head? ] 2bi [ drop +eq+ ] when ;
: find-index '[ _ prefix<=> ] search drop ;
: from-to
'[ _ head? not ] [ find-last-from drop 1+ ] [ find-from drop ] 3bi ;
: query
[ swap [ find-index ] 2keep from-to ] keep <slice> [ seq>> ] map prune ;
New Annotation