binary-search: faster by specializing on array and vectors.
parent
19002c93a6
commit
da6c8e3b8b
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2008, 2010 Slava Pestov.
|
! Copyright (C) 2008, 2010 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors arrays combinators hints kernel locals math
|
USING: accessors arrays combinators kernel locals math
|
||||||
math.order sequences sequences.private ;
|
math.order sequences sequences.private vectors ;
|
||||||
IN: binary-search
|
IN: binary-search
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
@ -26,10 +26,10 @@ PRIVATE>
|
||||||
over empty? [ 2drop f f ] [ [ 0 over length ] dip (search) ] if ;
|
over empty? [ 2drop f f ] [ [ 0 over length ] dip (search) ] if ;
|
||||||
inline
|
inline
|
||||||
|
|
||||||
: natural-search ( obj seq -- i elt )
|
GENERIC: natural-search ( obj seq -- i elt )
|
||||||
[ <=> ] with search ;
|
M: object natural-search [ <=> ] with search ;
|
||||||
|
M: array natural-search [ <=> ] with search ;
|
||||||
HINTS: natural-search array ;
|
M: vector natural-search [ <=> ] with search ;
|
||||||
|
|
||||||
: sorted-index ( obj seq -- i )
|
: sorted-index ( obj seq -- i )
|
||||||
natural-search drop ;
|
natural-search drop ;
|
||||||
|
|
Loading…
Reference in New Issue