Merge branch 'sorting' of git://github.com/mrjbq7/factor
commit
29d37737bc
|
@ -452,7 +452,7 @@ M: array elements*
|
||||||
|
|
||||||
: $definition-icons ( element -- )
|
: $definition-icons ( element -- )
|
||||||
drop
|
drop
|
||||||
icons get >alist sort-keys
|
icons get sort-keys
|
||||||
[ [ <$link> ] [ definition-icon-path <$image> ] bi* swap ] assoc-map
|
[ [ <$link> ] [ definition-icon-path <$image> ] bi* swap ] assoc-map
|
||||||
{ "" "Definition class" } prefix
|
{ "" "Definition class" } prefix
|
||||||
$table ;
|
$table ;
|
||||||
|
|
|
@ -37,7 +37,7 @@ CONSTANT: max-redirects 10
|
||||||
[ "Header injection attack" throw ] when ;
|
[ "Header injection attack" throw ] when ;
|
||||||
|
|
||||||
: write-header ( assoc -- )
|
: write-header ( assoc -- )
|
||||||
>alist sort-keys [
|
sort-keys [
|
||||||
[ check-header-string write ": " write ]
|
[ check-header-string write ": " write ]
|
||||||
[ header-value>string check-header-string write crlf ] bi*
|
[ header-value>string check-header-string write crlf ] bi*
|
||||||
] assoc-each crlf ;
|
] assoc-each crlf ;
|
||||||
|
|
|
@ -21,7 +21,7 @@ SYMBOL: message-histogram
|
||||||
drop ;
|
drop ;
|
||||||
|
|
||||||
: recent-histogram ( assoc n -- alist )
|
: recent-histogram ( assoc n -- alist )
|
||||||
[ >alist sort-values <reversed> ] dip short head ;
|
[ sort-values <reversed> ] dip short head ;
|
||||||
|
|
||||||
: analyze-entries ( entries word-names -- errors word-histogram message-histogram )
|
: analyze-entries ( entries word-names -- errors word-histogram message-histogram )
|
||||||
[
|
[
|
||||||
|
|
|
@ -59,7 +59,7 @@ PRIVATE>
|
||||||
swapd each-permutation ; inline
|
swapd each-permutation ; inline
|
||||||
|
|
||||||
: inverse-permutation ( seq -- permutation )
|
: inverse-permutation ( seq -- permutation )
|
||||||
<enum> >alist sort-values keys ;
|
<enum> sort-values keys ;
|
||||||
|
|
||||||
|
|
||||||
! Combinadic-based combination methodology
|
! Combinadic-based combination methodology
|
||||||
|
|
|
@ -79,7 +79,7 @@ PRIVATE>
|
||||||
[ ] [ inc-at ] sequence>hashtable ;
|
[ ] [ inc-at ] sequence>hashtable ;
|
||||||
|
|
||||||
: sorted-histogram ( seq -- alist )
|
: sorted-histogram ( seq -- alist )
|
||||||
histogram >alist sort-values ;
|
histogram sort-values ;
|
||||||
|
|
||||||
: collect-pairs ( seq quot -- hashtable )
|
: collect-pairs ( seq quot -- hashtable )
|
||||||
[ push-at ] sequence>hashtable ; inline
|
[ push-at ] sequence>hashtable ; inline
|
||||||
|
|
|
@ -47,7 +47,7 @@ IN: regexp.minimize
|
||||||
over '[ drop first2 _ _ stay-same? ] assoc-filter ;
|
over '[ drop first2 _ _ stay-same? ] assoc-filter ;
|
||||||
|
|
||||||
: partition>classes ( partitions -- synonyms ) ! old-state => new-state
|
: partition>classes ( partitions -- synonyms ) ! old-state => new-state
|
||||||
>alist sort-keys
|
sort-keys
|
||||||
[ drop first2 swap ] assoc-map
|
[ drop first2 swap ] assoc-map
|
||||||
<reversed>
|
<reversed>
|
||||||
>hashtable ;
|
>hashtable ;
|
||||||
|
|
|
@ -28,7 +28,7 @@ IN: tools.threads
|
||||||
[ [ write ] with-cell ] each
|
[ [ write ] with-cell ] each
|
||||||
] with-row
|
] with-row
|
||||||
|
|
||||||
threads >alist sort-keys values [
|
threads sort-keys values [
|
||||||
[ thread. ] with-row
|
[ thread. ] with-row
|
||||||
] each
|
] each
|
||||||
] tabular-output nl ;
|
] tabular-output nl ;
|
||||||
|
|
|
@ -59,7 +59,7 @@ M: source-file-renderer column-alignment drop { 0 0 1 } ;
|
||||||
M: source-file-renderer filled-column drop 1 ;
|
M: source-file-renderer filled-column drop 1 ;
|
||||||
|
|
||||||
: <source-file-model> ( model -- model' )
|
: <source-file-model> ( model -- model' )
|
||||||
[ group-by-source-file >alist sort-keys ] <arrow> ;
|
[ group-by-source-file sort-keys ] <arrow> ;
|
||||||
|
|
||||||
:: <source-file-table> ( error-list -- table )
|
:: <source-file-table> ( error-list -- table )
|
||||||
error-list model>> <source-file-model>
|
error-list model>> <source-file-model>
|
||||||
|
|
|
@ -141,7 +141,7 @@ PRIVATE>
|
||||||
2dup bounds-check? [ set-nth ] [ 3drop ] if ;
|
2dup bounds-check? [ set-nth ] [ 3drop ] if ;
|
||||||
|
|
||||||
:: fill-ranges ( table -- table )
|
:: fill-ranges ( table -- table )
|
||||||
name-map >alist sort-values keys
|
name-map sort-values keys
|
||||||
[ { [ "first>" tail? ] [ "last>" tail? ] } 1|| ] filter
|
[ { [ "first>" tail? ] [ "last>" tail? ] } 1|| ] filter
|
||||||
2 group [
|
2 group [
|
||||||
[ name>char ] bi@ [ [a,b] ] [ table ?nth ] bi
|
[ name>char ] bi@ [ [a,b] ] [ table ?nth ] bi
|
||||||
|
|
|
@ -67,7 +67,7 @@ M: interpolated [undo-xml]
|
||||||
|
|
||||||
: >enum ( assoc -- enum )
|
: >enum ( assoc -- enum )
|
||||||
! Assumes keys are 0..n
|
! Assumes keys are 0..n
|
||||||
>alist sort-keys values <enum> ;
|
sort-keys values <enum> ;
|
||||||
|
|
||||||
: undo-xml ( xml -- quot )
|
: undo-xml ( xml -- quot )
|
||||||
[undo-xml] '[ H{ } clone [ _ bind ] keep >enum ] ;
|
[undo-xml] '[ H{ } clone [ _ bind ] keep >enum ] ;
|
||||||
|
|
|
@ -24,7 +24,7 @@ ARTICLE: "enums" "Enumerations"
|
||||||
<enum>
|
<enum>
|
||||||
}
|
}
|
||||||
"Inverting a permutation using enumerations:"
|
"Inverting a permutation using enumerations:"
|
||||||
{ $example "IN: scratchpad" ": invert ( perm -- perm' )" " <enum> >alist sort-values keys ;" "{ 2 0 4 1 3 } invert ." "{ 1 3 0 4 2 }" } ;
|
{ $example "IN: scratchpad" ": invert ( perm -- perm' )" " <enum> sort-values keys ;" "{ 2 0 4 1 3 } invert ." "{ 1 3 0 4 2 }" } ;
|
||||||
|
|
||||||
HELP: enum
|
HELP: enum
|
||||||
{ $class-description "An associative structure which wraps a sequence and maps integers to the corresponding elements of the sequence."
|
{ $class-description "An associative structure which wraps a sequence and maps integers to the corresponding elements of the sequence."
|
||||||
|
|
|
@ -36,12 +36,12 @@ HELP: inv-sort-with
|
||||||
{ $description "Sorts the elements of " { $snippet "seq" } " by applying " { $link compare } " with " { $snippet "quot" } " to each pair of elements in the sequence and inverting the results." } ;
|
{ $description "Sorts the elements of " { $snippet "seq" } " by applying " { $link compare } " with " { $snippet "quot" } " to each pair of elements in the sequence and inverting the results." } ;
|
||||||
|
|
||||||
HELP: sort-keys
|
HELP: sort-keys
|
||||||
{ $values { "seq" "an alist" } { "sortedseq" "a new sorted sequence" } }
|
{ $values { "obj" "an object" } { "sortedseq" "a new sorted sequence" } }
|
||||||
{ $description "Sorts the elements of " { $snippet "seq" } " comparing first elements of pairs using the " { $link <=> } " word." } ;
|
{ $description "Sorts the elements of " { $snippet "obj" } " (converting to an alist first if not a sequence), comparing first elements of pairs using the " { $link <=> } " word." } ;
|
||||||
|
|
||||||
HELP: sort-values
|
HELP: sort-values
|
||||||
{ $values { "seq" "an alist" } { "sortedseq" "a new sorted sequence" } }
|
{ $values { "obj" "an object" } { "sortedseq" "a new sorted sequence" } }
|
||||||
{ $description "Sorts the elements of " { $snippet "seq" } " comparing second elements of pairs using the " { $link <=> } " word." } ;
|
{ $description "Sorts the elements of " { $snippet "obj" } " (converting to an alist first if not a sequence), comparing second elements of pairs using the " { $link <=> } " word." } ;
|
||||||
|
|
||||||
HELP: natural-sort
|
HELP: natural-sort
|
||||||
{ $values { "seq" "a sequence of real numbers" } { "sortedseq" "a new sorted sequence" } }
|
{ $values { "seq" "a sequence of real numbers" } { "sortedseq" "a new sorted sequence" } }
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2005, 2009 Slava Pestov.
|
! Copyright (C) 2005, 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors arrays kernel math vectors math.order
|
USING: accessors arrays assocs kernel math vectors math.order
|
||||||
sequences sequences.private ;
|
sequences sequences.private ;
|
||||||
IN: sorting
|
IN: sorting
|
||||||
|
|
||||||
|
@ -160,8 +160,16 @@ PRIVATE>
|
||||||
: inv-sort-with ( seq quot -- sortedseq )
|
: inv-sort-with ( seq quot -- sortedseq )
|
||||||
[ compare invert-comparison ] curry sort ; inline
|
[ compare invert-comparison ] curry sort ; inline
|
||||||
|
|
||||||
: sort-keys ( seq -- sortedseq ) [ first ] sort-with ;
|
GENERIC: sort-keys ( obj -- sortedseq )
|
||||||
|
|
||||||
: sort-values ( seq -- sortedseq ) [ second ] sort-with ;
|
M: object sort-keys >alist sort-keys ;
|
||||||
|
|
||||||
|
M: sequence sort-keys [ first ] sort-with ;
|
||||||
|
|
||||||
|
GENERIC: sort-values ( obj -- sortedseq )
|
||||||
|
|
||||||
|
M: object sort-values >alist sort-values ;
|
||||||
|
|
||||||
|
M: sequence sort-values [ second ] sort-with ;
|
||||||
|
|
||||||
: sort-pair ( a b -- c d ) 2dup after? [ swap ] when ;
|
: sort-pair ( a b -- c d ) 2dup after? [ swap ] when ;
|
||||||
|
|
|
@ -19,7 +19,7 @@ CONSTANT: knucleotide-in "vocab:benchmark/knucleotide/knucleotide-input.txt"
|
||||||
|
|
||||||
: handle-table ( inputs n -- )
|
: handle-table ( inputs n -- )
|
||||||
<clumps>
|
<clumps>
|
||||||
[ histogram >alist sort-values reverse ] [ length ] bi
|
[ histogram sort-values reverse ] [ length ] bi
|
||||||
'[
|
'[
|
||||||
[ first write bl ]
|
[ first write bl ]
|
||||||
[ second 100 * _ /f "%.3f" printf nl ] bi
|
[ second 100 * _ /f "%.3f" printf nl ] bi
|
||||||
|
|
|
@ -53,7 +53,7 @@ nonce ;
|
||||||
] H{ } make-assoc ; inline
|
] H{ } make-assoc ; inline
|
||||||
|
|
||||||
:: sign-params ( url request-method consumer-token request-token params -- signed-params )
|
:: sign-params ( url request-method consumer-token request-token params -- signed-params )
|
||||||
params >alist sort-keys :> params
|
params sort-keys :> params
|
||||||
url request-method params signature-base-string :> sbs
|
url request-method params signature-base-string :> sbs
|
||||||
consumer-token secret>> request-token dup [ secret>> ] when hmac-key :> key
|
consumer-token secret>> request-token dup [ secret>> ] when hmac-key :> key
|
||||||
sbs key sha1 hmac-bytes >base64 >string :> signature
|
sbs key sha1 hmac-bytes >base64 >string :> signature
|
||||||
|
|
Loading…
Reference in New Issue