math-binpack: Some cleanups recommended on IRC.
parent
9cd9a98ce9
commit
1c76a6865a
|
@ -6,16 +6,17 @@ USING: sequences kernel arrays vectors accessors assocs sorting math math.functi
|
||||||
IN: math.binpack
|
IN: math.binpack
|
||||||
|
|
||||||
: (binpack) ( bins item -- )
|
: (binpack) ( bins item -- )
|
||||||
swap dup [ [ second ] map sum ] map swap zip sort-keys values first push ;
|
[ [ values sum ] map ] keep
|
||||||
|
zip sort-keys values first push ;
|
||||||
|
|
||||||
: binpack ( assoc n -- bins )
|
: binpack ( assoc n -- bins )
|
||||||
[ sort-values reverse [ length ] keep swap ] dip
|
[ sort-values <reversed> dup length ] dip
|
||||||
[ / ceiling ] keep swap <array> [ <vector> ] map
|
tuck / ceiling <array> [ <vector> ] map
|
||||||
swap [ dupd (binpack) ] each ;
|
tuck [ (binpack) ] curry each ;
|
||||||
|
|
||||||
: binpack* ( items n -- bins )
|
: binpack* ( items n -- bins )
|
||||||
[ dup zip ] dip binpack [ keys ] map ;
|
[ dup zip ] dip binpack [ keys ] map ;
|
||||||
|
|
||||||
: binpack! ( items quot n -- bins )
|
: binpack! ( items quot n -- bins )
|
||||||
[ dup ] 2dip [ map zip ] dip binpack [ keys ] map ;
|
[ dupd map zip ] dip binpack [ keys ] map ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue