Paste: word-suffix-array 4
Author: | prunedtree |
Mode: | factor |
Date: | Wed, 1 Oct 2008 14:49:54 |
Plain Text |
USING: kernel arrays math accessors sequences math.vectors math.order sorting
binary-search sets assocs fry ;
IN: suffix-array
: load first2 [ name>> ] dip tail-slice ;
: suffix<=> [ load ] bi@ <=> ;
: suffixes dup name>> length [ 2array ] with map ;
: new-sa [ suffixes ] map concat [ suffix<=> ] sort ;
: prefix<=> [ swap <=> ] [ head? ] 2bi [ drop +eq+ ] [ ] if ;
: find-one-index '[ load _ prefix<=> ] search drop ;
: expand-slice
'[ load _ head? not ] [ find-last-from ] [ find-from ] 3bi [ drop ] 2bi@ rot <slice> ;
: query-sa
swap dupd [ find-one-index ] 2keep expand-slice [ first ] map prune ;
New Annotation