Merge branch 'master' of git://factorcode.org/git/factor
commit
6bb069f173
|
@ -0,0 +1,28 @@
|
|||
! Copyright (C) 2009 Maximilian Lupke.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: assocs help.markup help.syntax sequences ;
|
||||
IN: sequences.abbrev
|
||||
|
||||
HELP: abbrev
|
||||
{ $values
|
||||
{ "seqs" sequence }
|
||||
{ "assoc" assoc }
|
||||
}
|
||||
{ $description "Calculates an assoc of { prefix sequence } pairs with prefix being an prefix of each element of sequence for each element in " { $snippet "seqs" } "." } ;
|
||||
|
||||
HELP: unique-abbrev
|
||||
{ $values
|
||||
{ "seqs" sequence }
|
||||
{ "assoc" assoc }
|
||||
}
|
||||
{ $description "Calculates an assoc of { prefix { sequence } } pairs with prefix being an unambiguous prefix of sequence in seqs." } ;
|
||||
|
||||
ARTICLE: "sequences.abbrev" "Examples of abbrev usage"
|
||||
"It is probably easiest to just run examples to understand abbrev."
|
||||
{ $code
|
||||
"{ \"hello\" \"help\" } abbrev"
|
||||
"{ \"hello\" \"help\" } unique-abbrev"
|
||||
}
|
||||
;
|
||||
|
||||
ABOUT: "sequences.abbrev"
|
|
@ -0,0 +1,26 @@
|
|||
USING: assocs sequences.abbrev tools.test ;
|
||||
IN: sequences.abbrev.tests
|
||||
|
||||
[ { "hello" "help" } ] [
|
||||
"he" { "apple" "hello" "help" } abbrev at
|
||||
] unit-test
|
||||
|
||||
[ f ] [
|
||||
"he" { "apple" "hello" "help" } unique-abbrev at
|
||||
] unit-test
|
||||
|
||||
[ { "apple" } ] [
|
||||
"a" { "apple" "hello" "help" } abbrev at
|
||||
] unit-test
|
||||
|
||||
[ { "apple" } ] [
|
||||
"a" { "apple" "hello" "help" } unique-abbrev at
|
||||
] unit-test
|
||||
|
||||
[ f ] [
|
||||
"a" { "hello" "help" } abbrev at
|
||||
] unit-test
|
||||
|
||||
[ f ] [
|
||||
"a" { "hello" "help" } unique-abbrev at
|
||||
] unit-test
|
|
@ -0,0 +1,23 @@
|
|||
! Copyright (C) 2009 Maximilian Lupke.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: arrays assocs fry kernel math.ranges sequences ;
|
||||
IN: sequences.abbrev
|
||||
|
||||
<PRIVATE
|
||||
|
||||
: prefixes ( seq -- prefixes )
|
||||
dup length [1,b] [ head ] with map ;
|
||||
|
||||
: (abbrev) ( seq -- assoc )
|
||||
[ prefixes ] keep 1array '[ _ ] H{ } map>assoc ;
|
||||
|
||||
: assoc-merge ( assoc1 assoc2 -- assoc3 )
|
||||
tuck '[ over _ at dup [ append ] [ drop ] if ] assoc-map assoc-union ;
|
||||
|
||||
PRIVATE>
|
||||
|
||||
: abbrev ( seqs -- assoc )
|
||||
[ (abbrev) ] map H{ } [ assoc-merge ] reduce ;
|
||||
|
||||
: unique-abbrev ( seqs -- assoc )
|
||||
abbrev [ nip length 1 = ] assoc-filter ;
|
|
@ -0,0 +1 @@
|
|||
Maximilian Lupke
|
Loading…
Reference in New Issue