sorting: faster sort-keys and sort-values for hashtables.

db4
John Benediktsson 2014-12-05 10:50:22 -08:00
parent 7023cff14b
commit e7bb1a43df
1 changed files with 9 additions and 2 deletions

View 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 ;