]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/sorting/quick/quick.factor
Rename and add sorting words
[factor.git] / extra / sorting / quick / quick.factor
index 08476e18e7f2999f10b60c408e6a71f21f08de3b..d153504aa80d77a1a35aad229c7da92509e51250 100644 (file)
@@ -39,18 +39,28 @@ IN: sorting.quick
 
 PRIVATE>
 
-: sort! ( seq quot: ( obj1 obj2 -- <=> ) -- )
+: sort-with! ( seq quot: ( obj1 obj2 -- <=> ) -- )
     [ 0 over length check-array-capacity 1 - ] dip quicksort ; inline
 
-: sort-with! ( seq quot: ( elt -- key ) -- )
-    [ compare ] curry sort! ; inline
+: inv-sort-with! ( seq quot: ( obj1 obj2 -- <=> ) -- )
+    '[ @ invert-comparison ] sort-with! ; inline
 
-: inv-sort-with! ( seq quot: ( elt -- key ) -- )
-    [ compare invert-comparison ] curry sort! ; inline
+: sort-by! ( seq quot: ( elt -- key ) -- )
+    [ compare ] curry sort-with! ; inline
 
-GENERIC: natural-sort! ( seq -- )
+: inv-sort-by! ( seq quot: ( elt -- key ) -- )
+    [ compare invert-comparison ] curry sort-with! ; inline
 
-M: object natural-sort!  [ <=> ] sort! ;
-M: array natural-sort! [ <=> ] sort! ;
-M: vector natural-sort! [ <=> ] sort! ;
-M: string natural-sort! [ <=> ] sort! ;
+GENERIC: sort! ( seq -- )
+
+M: object sort! [ <=> ] sort-with! ;
+M: array sort! [ <=> ] sort-with! ;
+M: vector sort! [ <=> ] sort-with! ;
+M: string sort! [ <=> ] sort-with! ;
+
+GENERIC: inv-sort! ( seq -- )
+
+M: object inv-sort! [ <=> ] inv-sort-with! ;
+M: array inv-sort! [ <=> ] inv-sort-with! ;
+M: vector inv-sort! [ <=> ] inv-sort-with! ;
+M: string inv-sort! [ <=> ] inv-sort-with! ;