]> gitweb.factorcode.org Git - factor.git/commitdiff
sorting: faster sort-keys and sort-values for hashtables.
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 5 Dec 2014 18:50:22 +0000 (10:50 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 5 Dec 2014 18:50:22 +0000 (10:50 -0800)
core/sorting/sorting.factor

index 32ebe7f7bfce5343764e956225c69401d7ffbd23..52c86560082f757b94fe3004c3f3331ac6485595 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2005, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays assocs growable.private kernel math
-math.order sequences sequences.private vectors ;
+USING: accessors arrays assocs growable.private hashtables
+kernel kernel.private math math.order sequences
+sequences.private vectors ;
 IN: sorting
 
 ! Optimized merge-sort:
@@ -159,6 +160,9 @@ M: object sort-keys >alist sort-keys ;
 M: sequence sort-keys
     0 check-bounds [ first-unsafe ] sort-with ;
 
+M: hashtable sort-keys
+    >alist [ { array } declare first-unsafe ] sort-with ;
+
 GENERIC: sort-values ( obj -- sortedseq )
 
 M: object sort-values >alist sort-values ;
@@ -166,4 +170,7 @@ M: object sort-values >alist sort-values ;
 M: sequence sort-values
     1 check-bounds [ second-unsafe ] sort-with ;
 
+M: hashtable sort-values
+    >alist [ { array } declare second-unsafe ] sort-with ;
+
 : sort-pair ( a b -- c d ) 2dup after? [ swap ] when ;