sequences.extras: adding a (slow) arg-sort.
parent
1a5f2ad961
commit
4bdb40574a
|
@ -124,6 +124,8 @@ IN: sequences.extras.tests
|
||||||
|
|
||||||
{ 1 } [ { 1 7 3 7 6 3 7 } arg-max ] unit-test
|
{ 1 } [ { 1 7 3 7 6 3 7 } arg-max ] unit-test
|
||||||
{ 0 } [ { 1 7 3 7 6 3 7 } arg-min ] unit-test
|
{ 0 } [ { 1 7 3 7 6 3 7 } arg-min ] unit-test
|
||||||
|
{ { 0 4 } } [ { 5 3 2 10 5 } [ 5 = ] arg-where ] unit-test
|
||||||
|
{ { 2 1 0 4 3 } } [ { 5 3 2 10 5 } arg-sort ] unit-test
|
||||||
|
|
||||||
{ t } [ { 1 2 3 4 5 } 1 first= ] unit-test
|
{ t } [ { 1 2 3 4 5 } 1 first= ] unit-test
|
||||||
{ t } [ { 1 2 3 4 5 } 2 second= ] unit-test
|
{ t } [ { 1 2 3 4 5 } 2 second= ] unit-test
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
USING: accessors arrays assocs fry grouping growable kernel
|
USING: accessors arrays assocs fry grouping growable kernel
|
||||||
locals make math math.order math.ranges sequences
|
locals make math math.order math.ranges sequences
|
||||||
sequences.private splitting ;
|
sequences.private sorting splitting ;
|
||||||
FROM: sequences => change-nth ;
|
FROM: sequences => change-nth ;
|
||||||
IN: sequences.extras
|
IN: sequences.extras
|
||||||
|
|
||||||
|
@ -319,6 +319,9 @@ INSTANCE: odds immutable-sequence
|
||||||
[ dup length iota zip ] dip
|
[ dup length iota zip ] dip
|
||||||
[ first-unsafe ] prepose filter values ; inline
|
[ first-unsafe ] prepose filter values ; inline
|
||||||
|
|
||||||
|
: arg-sort ( seq -- indices )
|
||||||
|
dup length iota zip sort-keys values ;
|
||||||
|
|
||||||
: first= ( seq elt -- ? ) [ first ] dip = ; inline
|
: first= ( seq elt -- ? ) [ first ] dip = ; inline
|
||||||
: second= ( seq elt -- ? ) [ second ] dip = ; inline
|
: second= ( seq elt -- ? ) [ second ] dip = ; inline
|
||||||
: third= ( seq elt -- ? ) [ third ] dip = ; inline
|
: third= ( seq elt -- ? ) [ third ] dip = ; inline
|
||||||
|
|
Loading…
Reference in New Issue