tools.completion: making completions a lot faster using make.

db4
John Benediktsson 2010-08-13 19:28:44 -07:00
parent ae17190909
commit a8e9b57685
2 changed files with 23 additions and 7 deletions

View File

@ -1,5 +1,5 @@
USING: help.markup help.syntax strings generic vectors assocs
math ;
math make ;
IN: tools.completion
ARTICLE: "tools.completion" "Fuzzy completion"
@ -50,6 +50,14 @@ HELP: completion
}
} ;
HELP: completion,
{ $values { "short" string } { "candidate" "a pair " { $snippet "{ obj full }" } } }
{ $description
"Adds the result of " { $link completion }
" to the end of the sequence being constructed by " { $link make }
" if the score is positive."
} ;
HELP: completions
{ $values { "short" string } { "candidates" "a sequence of pairs of the shape " { $snippet "{ obj full }" } } { "seq" "a sequence of pairs of the shape " { $snippet "{ score obj }" } } }
{ $description "Calls " { $link completion } " to produce a sequence of " { $snippet "{ score obj }" } " pairs, then calls " { $link rank-completions } " to sort them and discard the low 33%." } ;

View File

@ -1,9 +1,11 @@
! Copyright (C) 2005, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors kernel arrays sequences math namespaces strings io
fry vectors words assocs combinators sorting unicode.case
unicode.categories math.order vocabs vocabs.hierarchy unicode.data
locals ;
USING: accessors arrays assocs combinators fry io kernel locals
make math math.order namespaces sequences sorting strings
unicode.case unicode.categories unicode.data vectors vocabs
vocabs.hierarchy words ;
IN: tools.completion
:: (fuzzy) ( accum i full ch -- accum i full ? )
@ -64,9 +66,14 @@ IN: tools.completion
: completion ( short candidate -- result )
[ second >lower swap complete ] keep 2array ;
: completion, ( short candidate -- )
completion dup first 0 > [ , ] [ drop ] if ;
: completions ( short candidates -- seq )
[ ] [ [ >lower ] dip [ completion ] with map rank-completions ]
bi-curry if-empty ;
[ ] [
[ >lower ] dip [ [ completion, ] with each ] { } make
rank-completions
] bi-curry if-empty ;
: name-completions ( str seq -- seq' )
[ dup name>> ] { } map>assoc completions ;
@ -79,3 +86,4 @@ IN: tools.completion
: chars-matching ( str -- seq )
name-map keys dup zip completions ;