From aa6a6182167ca928858507ee2e4c5903bd92e211 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 22 Jul 2022 17:03:04 -0500 Subject: [PATCH] basis: use head-to-index and index-to-tail --- basis/math/combinatorics/combinatorics.factor | 6 +++--- basis/math/matrices/matrices.factor | 12 ++++++------ basis/specialized-arrays/specialized-arrays.factor | 8 ++++---- basis/stack-checker/backend/backend.factor | 3 +-- extra/crypto/aes/aes.factor | 2 +- extra/crypto/aes/utils/utils.factor | 2 +- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/basis/math/combinatorics/combinatorics.factor b/basis/math/combinatorics/combinatorics.factor index be9cc1b967..0b8713cc6b 100644 --- a/basis/math/combinatorics/combinatorics.factor +++ b/basis/math/combinatorics/combinatorics.factor @@ -48,7 +48,7 @@ PRIVATE> '[ dup _ >= [ 1 + ] when ] map! drop ; inline : (>permutation) ( seq n index -- seq ) - swap [ dupd (head) ] dip bump-indices ; + swap [ dupd head-to-index ] dip bump-indices ; : >permutation ( factoradic -- permutation ) reverse! dup [ (>permutation) ] each-index reverse! ; @@ -139,7 +139,7 @@ PRIVATE> [ nip ] [ nth-unsafe ] 2bi [ > ] curry find-last drop ; inline : reverse-tail! ( n seq -- seq ) - [ swap 1 + (tail) reverse! drop ] keep ; inline + [ swap 1 + index-to-tail reverse! drop ] keep ; inline : (next-permutation) ( seq -- seq ) dup cut-point [ @@ -266,7 +266,7 @@ INSTANCE: combinations immutable-sequence over length - '[ _ + >= ] find-index drop ; inline : increment-rest ( i seq -- ) - [ nth-unsafe ] [ swap (tail) ] 2bi + [ nth-unsafe ] [ swap index-to-tail ] 2bi [ drop 1 + dup ] map! 2drop ; inline : increment-last ( seq -- ) diff --git a/basis/math/matrices/matrices.factor b/basis/math/matrices/matrices.factor index c811027ec5..847ba1e028 100644 --- a/basis/math/matrices/matrices.factor +++ b/basis/math/matrices/matrices.factor @@ -59,23 +59,23 @@ PREDICATE: zero-square-matrix < square-matrix dup ; inline ! main-diagonal matrix diff --git a/basis/specialized-arrays/specialized-arrays.factor b/basis/specialized-arrays/specialized-arrays.factor index 88145dc906..7a085d650e 100644 --- a/basis/specialized-arrays/specialized-arrays.factor +++ b/basis/specialized-arrays/specialized-arrays.factor @@ -121,10 +121,10 @@ PRIVATE> : direct-slice ( from to seq -- seq' ) check-slice direct-slice-unsafe ; inline -: direct-head ( seq n -- seq' ) (head) direct-slice ; inline -: direct-tail ( seq n -- seq' ) (tail) direct-slice ; inline -: direct-head* ( seq n -- seq' ) from-end direct-head ; inline -: direct-tail* ( seq n -- seq' ) from-end direct-tail ; inline +: direct-head ( seq n -- seq' ) head-to-index direct-slice ; inline +: direct-tail ( seq n -- seq' ) index-to-tail direct-slice ; inline +: direct-head* ( seq n -- seq' ) from-tail direct-head ; inline +: direct-tail* ( seq n -- seq' ) from-tail direct-tail ; inline : define-array-vocab ( type -- vocab ) underlying-type diff --git a/basis/stack-checker/backend/backend.factor b/basis/stack-checker/backend/backend.factor index e3e231e93e..9f43424129 100644 --- a/basis/stack-checker/backend/backend.factor +++ b/basis/stack-checker/backend/backend.factor @@ -5,7 +5,6 @@ math.order namespaces quotations sequences stack-checker.dependencies stack-checker.errors stack-checker.recursive-state stack-checker.state stack-checker.values stack-checker.visitor words ; -FROM: sequences.private => from-end ; IN: stack-checker.backend : push-d ( obj -- ) meta-d push ; @@ -36,7 +35,7 @@ IN: stack-checker.backend [ introduce-values ] [ meta-d push-all ] bi meta-d push-all ] when - swap from-end [ tail ] [ update-inner-d ] bi ; + swap from-tail [ tail ] [ update-inner-d ] bi ; : shorten-by ( n seq -- ) [ length swap - ] keep shorten ; inline diff --git a/extra/crypto/aes/aes.factor b/extra/crypto/aes/aes.factor index 48fec0c322..7e63b4803e 100644 --- a/extra/crypto/aes/aes.factor +++ b/extra/crypto/aes/aes.factor @@ -155,7 +155,7 @@ M: aes-256-key key-expand-round ( temp i -- temp' ) : (key-sched-round) ( output temp i -- output' ) key-expand-round - [ dup 4th-from-end ] dip bitxor suffix! ; inline + [ dup 4th-from-tail ] dip bitxor suffix! ; inline : (sched-interval) ( K Nr -- seq ) [ length ] dip 1 + 4 * [a..b) ; ! over the interval Nk...Nb(Nr + 1) diff --git a/extra/crypto/aes/utils/utils.factor b/extra/crypto/aes/utils/utils.factor index 0c701ec16f..9a21572d70 100644 --- a/extra/crypto/aes/utils/utils.factor +++ b/extra/crypto/aes/utils/utils.factor @@ -57,5 +57,5 @@ IN: crypto.aes.utils a2 2 seq set-nth-unsafe a3 3 seq set-nth-unsafe ; -: 4th-from-end ( seq -- el ) +: 4th-from-tail ( seq -- el ) [ length 4 - ] keep nth ; -- 2.34.1