interval-sets: some modernization.
parent
2e10ff5e53
commit
7dbb63a01e
|
|
@ -20,7 +20,7 @@ HELP: interval-set
|
|||
|
||||
HELP: <interval-set>
|
||||
{ $values { "specification" "a sequence of numbers and pairs of numbers" } { "interval-set" interval-set } }
|
||||
{ $description "Creates an interval set based on the specification. Pairs of numers are interpreted as intervals which include their endpoints, and individual numbers are interpreted to be in the set, in a singleton range." } ;
|
||||
{ $description "Creates an interval set based on the specification. Pairs of numbers are interpreted as intervals which include their endpoints, and individual numbers are interpreted to be in the set, in a singleton range." } ;
|
||||
|
||||
HELP: in?
|
||||
{ $values { "key" integer } { "set" interval-set } { "?" { { $link t } " or " { $link f } } } }
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ IN: interval-sets.tests
|
|||
[ f ] [ 0 T{ interval-set } in? ] unit-test
|
||||
[ f ] [ 2 T{ interval-set } in? ] unit-test
|
||||
|
||||
: i1 ( n -- ? )
|
||||
: i1 ( -- set )
|
||||
{ { 3 4 } } <interval-set> ;
|
||||
|
||||
[ f ] [ 2 i1 in? ] unit-test
|
||||
|
|
@ -15,9 +15,9 @@ IN: interval-sets.tests
|
|||
[ t ] [ 4 i1 in? ] unit-test
|
||||
[ f ] [ 5 i1 in? ] unit-test
|
||||
|
||||
CONSTANT: unicode-max HEX: 10FFFF
|
||||
CONSTANT: unicode-max 0x10FFFF
|
||||
|
||||
: i2 ( n -- ? )
|
||||
: i2 ( -- set )
|
||||
{ { 3 4 } } <interval-set>
|
||||
unicode-max <interval-not> ;
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ CONSTANT: unicode-max HEX: 10FFFF
|
|||
[ f ] [ 4 i2 in? ] unit-test
|
||||
[ t ] [ 5 i2 in? ] unit-test
|
||||
|
||||
: i3 ( n -- ? )
|
||||
: i3 ( -- set )
|
||||
{ { 2 4 } } <interval-set>
|
||||
{ { 6 8 } } <interval-set>
|
||||
<interval-or> ;
|
||||
|
|
@ -41,7 +41,7 @@ CONSTANT: unicode-max HEX: 10FFFF
|
|||
[ t ] [ 8 i3 in? ] unit-test
|
||||
[ f ] [ 9 i3 in? ] unit-test
|
||||
|
||||
: i4 ( n -- ? )
|
||||
: i4 ( -- set )
|
||||
{ { 2 4 } } <interval-set>
|
||||
{ { 6 8 } } <interval-set>
|
||||
<interval-and> ;
|
||||
|
|
@ -56,7 +56,7 @@ CONSTANT: unicode-max HEX: 10FFFF
|
|||
[ f ] [ 8 i4 in? ] unit-test
|
||||
[ f ] [ 9 i4 in? ] unit-test
|
||||
|
||||
: i5 ( n -- ? )
|
||||
: i5 ( -- set )
|
||||
{ { 2 5 } } <interval-set>
|
||||
{ { 4 8 } } <interval-set>
|
||||
<interval-or> ;
|
||||
|
|
@ -71,7 +71,7 @@ CONSTANT: unicode-max HEX: 10FFFF
|
|||
[ t ] [ 8 i5 in? ] unit-test
|
||||
[ f ] [ 9 i5 in? ] unit-test
|
||||
|
||||
: i6 ( n -- ? )
|
||||
: i6 ( -- set )
|
||||
{ { 2 5 } } <interval-set>
|
||||
{ { 4 8 } } <interval-set>
|
||||
<interval-and> ;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
! Copyright (C) 2009 Daniel Ehrenberg.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: kernel sequences binary-search accessors math.order
|
||||
specialized-arrays.uint make grouping math arrays
|
||||
sorting assocs locals combinators fry hints ;
|
||||
USING: accessors alien.c-types arrays assocs binary-search
|
||||
combinators fry grouping hints kernel locals make math
|
||||
math.order sequences sorting specialized-arrays ;
|
||||
SPECIALIZED-ARRAY: uint
|
||||
IN: interval-sets
|
||||
! Sets of positive integers
|
||||
|
||||
|
|
@ -21,7 +22,7 @@ PRIVATE>
|
|||
|
||||
: in? ( key set -- ? )
|
||||
dupd find-interval
|
||||
[ [ start ] [ end 1- ] bi between? ]
|
||||
[ [ start ] [ end 1 - ] bi between? ]
|
||||
[ drop f ] if* ;
|
||||
|
||||
HINTS: in? { integer interval-set } ;
|
||||
|
|
@ -56,7 +57,7 @@ HINTS: in? { integer interval-set } ;
|
|||
interval-set boa ;
|
||||
|
||||
: >intervals ( seq -- seq' )
|
||||
[ 1+ ] assoc-map concat ;
|
||||
[ 1 + ] assoc-map concat ;
|
||||
|
||||
PRIVATE>
|
||||
|
||||
|
|
@ -97,7 +98,7 @@ PRIVATE>
|
|||
0 over ?nth zero? [ rest ] [ 0 prefix ] if ;
|
||||
|
||||
: interval-max ( interval-set1 interval-set2 -- n )
|
||||
[ array>> [ 0 ] [ peek ] if-empty ] bi@ max ;
|
||||
[ array>> [ 0 ] [ last ] if-empty ] bi@ max ;
|
||||
|
||||
PRIVATE>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue