add sorted-histogram word
parent
aaba25527c
commit
092dd9fc39
|
@ -98,6 +98,19 @@ HELP: histogram*
|
||||||
}
|
}
|
||||||
{ $description "Takes an existing hashtable and uses " { $link histogram } " to continue counting the number of occurences of each element." } ;
|
{ $description "Takes an existing hashtable and uses " { $link histogram } " to continue counting the number of occurences of each element." } ;
|
||||||
|
|
||||||
|
HELP: sorted-histogram
|
||||||
|
{ $values
|
||||||
|
{ "seq" sequence }
|
||||||
|
{ "alist" "an array of key/value pairs" }
|
||||||
|
}
|
||||||
|
{ $description "Outputs a " { $link histogram } " of a sequence sorted by number of occurences from lowest to highest." }
|
||||||
|
{ $examples
|
||||||
|
{ $example "USING: prettyprint math.statistics ;"
|
||||||
|
""""abababbbbbbc" sorted-histogram ."""
|
||||||
|
"{ { 99 1 } { 97 3 } { 98 8 } }"
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
|
||||||
HELP: sequence>assoc
|
HELP: sequence>assoc
|
||||||
{ $values
|
{ $values
|
||||||
{ "seq" sequence } { "quot" quotation } { "exemplar" "an exemplar assoc" }
|
{ "seq" sequence } { "quot" quotation } { "exemplar" "an exemplar assoc" }
|
||||||
|
@ -145,6 +158,7 @@ ARTICLE: "histogram" "Computing histograms"
|
||||||
{ $subsections
|
{ $subsections
|
||||||
histogram
|
histogram
|
||||||
histogram*
|
histogram*
|
||||||
|
sorted-histogram
|
||||||
}
|
}
|
||||||
"Combinators for implementing histogram:"
|
"Combinators for implementing histogram:"
|
||||||
{ $subsections
|
{ $subsections
|
||||||
|
|
|
@ -79,6 +79,9 @@ PRIVATE>
|
||||||
: histogram ( seq -- hashtable )
|
: histogram ( seq -- hashtable )
|
||||||
[ inc-at ] sequence>hashtable ;
|
[ inc-at ] sequence>hashtable ;
|
||||||
|
|
||||||
|
: sorted-histogram ( seq -- alist )
|
||||||
|
histogram >alist sort-values ;
|
||||||
|
|
||||||
: collect-values ( seq quot: ( obj hashtable -- ) -- hash )
|
: collect-values ( seq quot: ( obj hashtable -- ) -- hash )
|
||||||
'[ [ dup @ ] dip push-at ] sequence>hashtable ; inline
|
'[ [ dup @ ] dip push-at ] sequence>hashtable ; inline
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue