{
H{
- { 97 2 }
+ { 97 5 }
{ 98 2 }
{ 99 2 }
}
} [
"aabbcc" histogram
+ "aaa" histogram!
+] unit-test
+
+{
+ H{
+ { 97 5 }
+ { 98 2 }
+ { 99 2 }
+ }
+} [
+ "aabbcc" [ ] histogram-by
+ "aaa" [ ] histogram-by!
+] unit-test
+
+{
+ H{ { t 2 } { f 7 } }
+} [
+ "aabbcc" [ even? ] histogram-by
+ "aaa" [ even? ] histogram-by!
] unit-test
{ H{ { 1 1/2 } { 2 1/6 } { 3 1/3 } } }
: trimean ( seq -- x )
quartile first3 [ 2 * ] dip + + 4 / ;
+: histogram-by! ( assoc seq quot: ( x -- bin ) -- hashtable )
+ rot [ '[ @ _ inc-at ] each ] keep ; inline
+
: histogram! ( hashtable seq -- hashtable )
- over '[ _ inc-at ] each ;
+ [ ] histogram-by! ; inline
: histogram-by ( seq quot: ( x -- bin ) -- hashtable )
- H{ } clone [ '[ @ _ inc-at ] each ] keep ; inline
+ [ H{ } clone ] 2dip histogram-by! ; inline
: histogram ( seq -- hashtable )
[ ] histogram-by ;