]> gitweb.factorcode.org Git - factor.git/commitdiff
binary-search: faster by specializing on array and vectors.
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 19 Apr 2013 18:35:14 +0000 (11:35 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 19 Apr 2013 18:35:14 +0000 (11:35 -0700)
basis/binary-search/binary-search.factor

index 412e7e0c16907f609ffdc2f9960c5d0401dacc39..976f5fbb71c346e8b78fe3a1de65b43a276bcfd9 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays combinators hints kernel locals math
-math.order sequences sequences.private ;
+USING: accessors arrays combinators kernel locals math
+math.order sequences sequences.private vectors ;
 IN: binary-search
 
 <PRIVATE
@@ -26,10 +26,10 @@ PRIVATE>
     over empty? [ 2drop f f ] [ [ 0 over length ] dip (search) ] if ;
     inline
 
-: natural-search ( obj seq -- i elt )
-    [ <=> ] with search ;
-
-HINTS: natural-search array ;
+GENERIC: natural-search ( obj seq -- i elt )
+M: object natural-search [ <=> ] with search ;
+M: array natural-search [ <=> ] with search ;
+M: vector natural-search [ <=> ] with search ;
 
 : sorted-index ( obj seq -- i )
     natural-search drop ;