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