diff --git a/extra/sequences/shifted/authors.txt b/extra/sequences/shifted/authors.txt new file mode 100644 index 0000000000..e091bb8164 --- /dev/null +++ b/extra/sequences/shifted/authors.txt @@ -0,0 +1 @@ +John Benediktsson diff --git a/extra/sequences/shifted/shifted-tests.factor b/extra/sequences/shifted/shifted-tests.factor new file mode 100644 index 0000000000..a25a2b883f --- /dev/null +++ b/extra/sequences/shifted/shifted-tests.factor @@ -0,0 +1,10 @@ +! Copyright (C) 2013 John Benediktsson +! See http://factorcode.org/license.txt for BSD license +USING: arrays sequences tools.test ; +IN: sequences.shifted + +{ { 1 2 3 7 } } [ 4 iota -1 7 >array ] unit-test +{ { 7 0 1 2 } } [ 4 iota 1 7 >array ] unit-test +{ { 0 1 2 3 } } [ 4 iota 0 f >array ] unit-test +{ { f f f f } } [ 4 iota 4 f >array ] unit-test +{ { f f f f } } [ 4 iota -4 f >array ] unit-test diff --git a/extra/sequences/shifted/shifted.factor b/extra/sequences/shifted/shifted.factor new file mode 100644 index 0000000000..dec9db4370 --- /dev/null +++ b/extra/sequences/shifted/shifted.factor @@ -0,0 +1,27 @@ +! Copyright (C) 2013 John Benediktsson +! See http://factorcode.org/license.txt for BSD license +USING: accessors kernel math sequences sequences.private ; +IN: sequences.shifted + +TUPLE: shifted +{ underlying read-only } +{ n integer read-only } +{ fill read-only } ; + +C: shifted + +M: shifted length underlying>> length ; + +M: shifted like underlying>> like ; + +M: shifted new-sequence underlying>> new-sequence ; + +M: shifted nth-unsafe + [ n>> neg + ] [ underlying>> ] [ ] tri + 2over bounds-check? [ drop nth-unsafe ] [ 2nip fill>> ] if ; + +M: shifted set-nth-unsafe + [ n>> neg + ] [ underlying>> ] bi + 2dup bounds-check? [ set-nth-unsafe ] [ 3drop ] if ; + +INSTANCE: shifted sequence diff --git a/extra/sequences/shifted/summary.txt b/extra/sequences/shifted/summary.txt new file mode 100644 index 0000000000..6048c984e1 --- /dev/null +++ b/extra/sequences/shifted/summary.txt @@ -0,0 +1 @@ +Shifted virtual sequences