tools.completion: simplify runs which is just monotonic-split.
parent
0d2859124e
commit
6e2726f232
|
@ -1,13 +1,11 @@
|
|||
|
||||
USING: assocs kernel tools.completion tools.completion.private
|
||||
tools.test ;
|
||||
USING: arrays assocs kernel sequences tools.test ;
|
||||
|
||||
IN: tools.completion
|
||||
|
||||
{ f } [ "abc" "def" fuzzy ] unit-test
|
||||
{ V{ 4 5 6 } } [ "set-nth" "nth" fuzzy ] unit-test
|
||||
|
||||
{ V{ V{ 0 } V{ 4 5 6 } } } [ V{ 0 4 5 6 } runs ] unit-test
|
||||
{ { { 0 } { 4 5 6 } } } [ V{ 0 4 5 6 } runs [ >array ] map ] unit-test
|
||||
|
||||
{ { "nth" "?nth" "set-nth" } } [
|
||||
"nth" { "set-nth" "nth" "?nth" } dup zip completions keys
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors arrays assocs colors.constants combinators
|
||||
combinators.short-circuit fry io.directories io.files
|
||||
io.files.info io.files.types io.pathnames kernel locals make
|
||||
math math.order sequences sequences.private sorting splitting
|
||||
unicode.categories unicode.data vectors vocabs vocabs.hierarchy
|
||||
;
|
||||
io.files.info io.pathnames kernel locals make math math.order
|
||||
sequences sequences.private sorting splitting
|
||||
splitting.monotonic unicode.categories unicode.data vectors
|
||||
vocabs vocabs.hierarchy ;
|
||||
IN: tools.completion
|
||||
|
||||
<PRIVATE
|
||||
|
@ -28,21 +28,8 @@ PRIVATE>
|
|||
dup [ length <vector> 0 ] curry 2dip
|
||||
[ (fuzzy) ] with all? 2drop ;
|
||||
|
||||
<PRIVATE
|
||||
|
||||
: (runs) ( runs n seq -- runs n )
|
||||
[
|
||||
[
|
||||
2dup number=
|
||||
[ drop ] [ nip V{ } clone pick push ] if
|
||||
1 +
|
||||
] keep pick last push
|
||||
] each ; inline
|
||||
|
||||
PRIVATE>
|
||||
|
||||
: runs ( seq -- newseq )
|
||||
[ V{ } clone 1vector ] dip [ first ] keep (runs) drop ;
|
||||
[ 1 - = ] monotonic-split-slice ;
|
||||
|
||||
<PRIVATE
|
||||
|
||||
|
@ -69,15 +56,12 @@ PRIVATE>
|
|||
] if ;
|
||||
|
||||
: rank-completions ( results -- newresults )
|
||||
sort-keys <reversed>
|
||||
[ 0 [ first max ] reduce 3 /f ] keep
|
||||
[ first-unsafe < ] with filter
|
||||
values ;
|
||||
sort-keys <reversed> values ;
|
||||
|
||||
: complete ( full short -- score )
|
||||
[ dupd fuzzy score ] 2keep
|
||||
[ <reversed> ] bi@
|
||||
dupd fuzzy score max ;
|
||||
2dup [ <reversed> ] bi@ [ dupd fuzzy score ] 2bi@ max ;
|
||||
|
||||
: completion ( short candidate -- result )
|
||||
[ second swap complete ] keep 2array ; inline
|
||||
|
|
Loading…
Reference in New Issue