Use [ max ] map-reduce instead of map supremum; would be nice to find a good name for this and put it in sequences vocab

db4
Slava Pestov 2009-02-02 03:46:10 -06:00
parent ce83be67a4
commit b684db297a
9 changed files with 21 additions and 19 deletions

View File

@ -2,7 +2,7 @@
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays generic hashtables kernel kernel.private
math namespaces parser sequences strings words libc fry
alien.c-types alien.structs.fields cpu.architecture ;
alien.c-types alien.structs.fields cpu.architecture math.order ;
IN: alien.structs
TUPLE: struct-type size align fields ;
@ -47,7 +47,7 @@ M: struct-type stack-size
[ first2 <field-spec> ] with with map ;
: compute-struct-align ( types -- n )
[ c-type-align ] map supremum ;
[ c-type-align ] [ max ] map-reduce ;
: define-struct ( name vocab fields -- )
[
@ -59,5 +59,5 @@ M: struct-type stack-size
: define-union ( name members -- )
[ expand-constants ] map
[ [ heap-size ] map supremum ] keep
[ [ heap-size ] [ max ] map-reduce ] keep
compute-struct-align f (define-struct) ;

View File

@ -1,7 +1,7 @@
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: namespaces sequences accessors math kernel
compiler.tree ;
compiler.tree math.order ;
IN: compiler.tree.normalization.introductions
SYMBOL: introductions
@ -25,7 +25,7 @@ M: #introduce count-introductions*
M: #branch count-introductions*
children>>
[ count-introductions ] map supremum
[ count-introductions ] [ max ] map-reduce
introductions+ ;
M: #recursive count-introductions*

View File

@ -1,6 +1,6 @@
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: fry vectors sequences assocs math accessors kernel
USING: fry vectors sequences assocs math math.order accessors kernel
combinators quotations namespaces grouping stack-checker.state
stack-checker.backend stack-checker.errors stack-checker.visitor
stack-checker.values stack-checker.recursive-state ;
@ -16,7 +16,7 @@ SYMBOL: +bottom+
: pad-with-bottom ( seq -- newseq )
dup empty? [
dup [ length ] map supremum
dup [ length ] [ max ] map-reduce
'[ _ +bottom+ pad-head ] map
] unless ;

View File

@ -2,7 +2,8 @@
! See http://factorcode.org/license.txt for BSD license.
USING: tools.disassembler namespaces combinators
alien alien.syntax alien.c-types lexer parser kernel
sequences layouts math math.parser system make fry arrays ;
sequences layouts math math.order
math.parser system make fry arrays ;
IN: tools.disassembler.udis
<<
@ -56,7 +57,7 @@ SINGLETON: udis-disassembler
: buf/len ( from to -- buf len ) [ drop <alien> ] [ swap - ] 2bi ;
: format-disassembly ( lines -- lines' )
dup [ second length ] map supremum
dup [ second length ] [ max ] map-reduce
'[
[
[ first >hex cell 2 * CHAR: 0 pad-head % ": " % ]

View File

@ -1,6 +1,6 @@
! Copyright (c) 2007, 2008 Aaron Schaefer.
! See http://factorcode.org/license.txt for BSD license.
USING: grouping math.parser sequences ;
USING: grouping math.order math.parser sequences ;
IN: project-euler.008
! http://projecteuler.net/index.php?section=problems&id=8
@ -64,7 +64,7 @@ IN: project-euler.008
PRIVATE>
: euler008 ( -- answer )
source-008 5 clump [ string>digits product ] map supremum ;
source-008 5 clump [ string>digits product ] [ max ] map-reduce ;
! [ euler008 ] 100 ave-time
! 2 ms ave run time - 0.79 SD (100 trials)

View File

@ -1,6 +1,6 @@
! Copyright (c) 2007, 2008 Aaron Schaefer.
! See http://factorcode.org/license.txt for BSD license.
USING: grouping kernel make sequences ;
USING: grouping kernel make math.order sequences ;
IN: project-euler.011
! http://projecteuler.net/index.php?section=problems&id=11
@ -88,7 +88,7 @@ IN: project-euler.011
: max-product ( matrix width -- n )
[ clump ] curry map concat
[ product ] map supremum ; inline
[ product ] [ max ] map-reduce ; inline
PRIVATE>

View File

@ -23,7 +23,7 @@ IN: project-euler.056
: euler056 ( -- answer )
90 100 [a,b) dup cartesian-product
[ first2 ^ number>digits sum ] map supremum ;
[ first2 ^ number>digits sum ] [ max ] map-reduce ;
! [ euler056 ] 100 ave-time
! 22 ms ave run time - 2.13 SD (100 trials)

View File

@ -1,6 +1,7 @@
! Copyright (C) 2008 Alex Chapman
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays kernel math sequences sequences.private shuffle ;
USING: accessors arrays kernel math math.order
sequences sequences.private shuffle ;
IN: sequences.modified
TUPLE: modified ;
@ -50,7 +51,7 @@ M: offset modified-set-nth ( elt n seq -- )
TUPLE: summed < modified seqs ;
C: <summed> summed
M: summed length seqs>> [ length ] map supremum ;
M: summed length seqs>> [ length ] [ max ] map-reduce ;
<PRIVATE
: ?+ ( x/f y/f -- sum )

View File

@ -1,7 +1,7 @@
! Copyright (C) 2006, 2007, 2008 Alex Chapman
! See http://factorcode.org/license.txt for BSD license.
USING: kernel arrays namespaces sequences math math.vectors
colors random ;
USING: kernel arrays namespaces sequences math math.order
math.vectors colors random ;
IN: tetris.tetromino
TUPLE: tetromino states colour ;
@ -104,7 +104,7 @@ SYMBOL: tetrominoes
tetrominoes get random ;
: blocks-max ( blocks quot -- max )
map [ 1+ ] map supremum ; inline
map [ 1+ ] [ max ] map-reduce ; inline
: blocks-width ( blocks -- width )
[ first ] blocks-max ;