]> gitweb.factorcode.org Git - factor.git/commitdiff
sorting.quick: a bit faster for standard data types.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sat, 15 Aug 2015 15:57:47 +0000 (08:57 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 15 Aug 2015 15:57:47 +0000 (08:57 -0700)
extra/sorting/quick/quick.factor

index 819fd59beb6c3af8c1b5b33d52e4cccb938a41ca..be2a5309a86cf6d2c5933b7cff14e96999c04ac2 100644 (file)
@@ -1,25 +1,25 @@
 ! Copyright (C) 2014 John Benediktsson
 ! See http://factorcode.org/license.txt for BSD license
 
-USING: combinators kernel locals math math.order sequences
-sequences.private ;
+USING: arrays combinators kernel locals math math.order
+sequences sequences.private strings vectors ;
 
 IN: sorting.quick
 
 <PRIVATE
 
-:: quicksort ( seq from to quot -- )
+:: quicksort ( seq from to quot: ( obj1 obj2 -- <=> ) -- )
     from to < [
         from to + 2/ seq nth-unsafe :> pivot
 
         from to [ 2dup <= ] [
             [
-                over seq nth-unsafe pivot quot call( x x -- x )
+                over seq nth-unsafe pivot quot call
                 +lt+ eq?
             ] [ [ 1 + ] dip ] while
 
             [
-                dup seq nth-unsafe pivot quot call( x x -- x )
+                dup seq nth-unsafe pivot quot call
                 +gt+ eq?
             ] [ 1 - ] while
 
@@ -44,5 +44,9 @@ PRIVATE>
 : inv-sort-with! ( seq quot: ( elt -- key ) -- )
     [ compare invert-comparison ] curry sort! ; inline
 
-: natural-sort! ( seq -- )
-    [ <=> ] sort! ;
+GENERIC: natural-sort! ( seq -- )
+
+M: object natural-sort!  [ <=> ] sort! ;
+M: array natural-sort! [ <=> ] sort! ;
+M: vector natural-sort! [ <=> ] sort! ;
+M: string natural-sort! [ <=> ] sort! ;