! Copyright (C) 2009 Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types arrays assocs binary-search
-combinators fry grouping kernel locals make math math.order
-sequences sequences.private sorting specialized-arrays ;
+classes combinators kernel make math math.order sequences
+sequences.private sorting specialized-arrays ;
SPECIALIZED-ARRAY: uint
IN: interval-sets
! Sets of positive integers
+! Intervals are a pair of { start end }
TUPLE: interval-set { array uint-array read-only } ;
-<PRIVATE
-
-ERROR: not-an-interval-set obj ;
-
-: check-interval-set ( map -- map )
- dup interval-set? [ not-an-interval-set ] unless ; inline
-
-PRIVATE>
-
-: in? ( key set -- ? )
- check-interval-set array>>
+: interval-in? ( key set -- ? )
+ interval-set check-instance array>>
dupd [ <=> ] with search swap [
even? [ >= ] [ 1 - <= ] if
] [ 2drop f ] if* ;
: spec>pairs ( sequence -- intervals )
[ dup number? [ dup 2array ] when ] map ;
-ALIAS: start first-unsafe
-ALIAS: end second-unsafe
-
: disjoint? ( node1 node2 -- ? )
- [ end ] [ start ] bi* < ;
+ [ second-unsafe ] [ first-unsafe ] bi* < ;
: (delete-redundancies) ( seq -- )
dup length {