1 ! Copyright (C) 2008 Marc Fauconneau.
\r
2 ! See http://factorcode.org/license.txt for BSD license.
\r
3 USING: kernel arrays math accessors sequences math.vectors
\r
4 math.order sorting binary-search sets assocs fry suffix-arrays ;
\r
5 IN: suffix-arrays.words
\r
7 ! to search on word names
\r
9 : new-word-sa ( words -- sa )
\r
10 [ name>> ] map >suffix-array ;
\r
12 : name>word-map ( words -- map )
\r
13 dup [ name>> V{ } clone ] H{ } map>assoc
\r
14 [ '[ dup name>> _ at push ] each ] keep ;
\r
16 : query-word-sa ( map begin sa -- matches ) query '[ _ at ] map concat ;
\r
19 ! clear all-words 100 head dup name>word-map "test" rot new-word-sa query .
\r