]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/interval-maps/interval-maps.factor
basis: use lint.vocabs tool to trim using lists
[factor.git] / basis / interval-maps / interval-maps.factor
index a089fa3972ff63491b21d00af2ece8e39e90b104..b22b347640400cd2cadbf2e55c255dbc81698b14 100644 (file)
@@ -1,19 +1,17 @@
 ! Copyright (C) 2008 Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays assocs binary-search grouping kernel
-locals make math math.order sequences sequences.private sorting ;
+USING: accessors arrays assocs binary-search classes grouping
+kernel make math math.order sequences sequences.private
+sorting ;
 IN: interval-maps
 
+! Intervals are triples of { start end value }
 TUPLE: interval-map { array array read-only } ;
 
 <PRIVATE
 
-ALIAS: start first-unsafe
-ALIAS: end second-unsafe
-ALIAS: value third-unsafe
-
 : find-interval ( key interval-map -- interval-node )
-    array>> [ start <=> ] with search nip ; inline
+    array>> [ first-unsafe <=> ] with search nip ; inline
 
 : interval-contains? ( key interval-node -- ? )
     first2-unsafe between? ; inline
@@ -22,7 +20,7 @@ ALIAS: value third-unsafe
     [ [ dup number? [ dup 2array ] when ] dip ] { } assoc-map-as ;
 
 : disjoint? ( node1 node2 -- ? )
-    [ end ] [ start ] bi* < ;
+    [ second-unsafe ] [ first-unsafe ] bi* < ;
 
 : ensure-disjoint ( intervals -- intervals )
     dup [ disjoint? ] monotonic?
@@ -31,25 +29,20 @@ ALIAS: value third-unsafe
 : >intervals ( specification -- intervals )
     [ suffix ] { } assoc>map concat 3 group ;
 
-ERROR: not-an-interval-map obj ;
-
-: check-interval-map ( map -- map )
-    dup interval-map? [ not-an-interval-map ] unless ; inline
-
 PRIVATE>
 
 : interval-at* ( key map -- value ? )
-    check-interval-map
+    interval-map check-instance
     [ drop ] [ find-interval ] 2bi
     [ nip ] [ interval-contains? ] 2bi
-    [ value t ] [ drop f f ] if ; inline
+    [ third-unsafe t ] [ drop f f ] if ; inline
 
 : interval-at ( key map -- value ) interval-at* drop ; inline
 
 : interval-key? ( key map -- ? ) interval-at* nip ; inline
 
 : interval-values ( map -- values )
-    check-interval-map array>> [ value ] map ;
+    interval-map check-instance array>> [ third-unsafe ] map ;
 
 : <interval-map> ( specification -- map )
     all-intervals [ first-unsafe second-unsafe ] sort-with