From c6c3ea599013d178f2df707f0b1fb833ff20b232 Mon Sep 17 00:00:00 2001 From: Arne Döring Date: Tue, 14 Feb 2017 01:01:36 +0100 Subject: added rotate in algorithm --- lib/pure/algorithm.nim | 112 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 1 deletion(-) (limited to 'lib/pure/algorithm.nim') diff --git a/lib/pure/algorithm.nim b/lib/pure/algorithm.nim index 9eee04404..189e96593 100644 --- a/lib/pure/algorithm.nim +++ b/lib/pure/algorithm.nim @@ -343,7 +343,7 @@ proc prevPermutation*[T](x: var openarray[T]): bool {.discardable.} = swap x[i-1], x[j] result = true - + when isMainModule: # Tests for lowerBound var arr = @[1,2,3,5,6,7,8,9] @@ -371,3 +371,113 @@ when isMainModule: for i in 0 .. high(arr1): assert arr1.reversed(0, i) == arr1.reversed()[high(arr1) - i .. high(arr1)] assert arr1.reversed(i, high(arr1)) == arr1.reversed()[0 .. high(arr1) - i] + + +proc rotate*[T](arg: var openarray[T]; first, middle, last: int): int {.discardable.} = + ## Performs a left rotation on a range of elements. + ## Specifically, ``rotate`` swaps the elements in the range [first, last) in such a way + ## that the element at index ``middle`` becomes the first element of the sub range and + ## ``middle - 1`` becomes the last element of the sub range. The time complexity is + ## linear to ``last - first``. returns ``first + (last - middle)``. ``T`` must support swap operation + ## + ## ``first`` + ## the index of the first element that should be rotated. + ## + ## ``middle`` + ## the index of the element that should appear at the beginning of the rotated range. + ## + ## ``last`` + ## the index of the first element that should not be rotated anymore (exclusive upper bound). + ## + ## .. code-block:: nim + ## var list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + ## list.rotate(1,4,9) + ## echo @list # @[0, 4, 5, 6, 7, 8, 1, 2, 3, 9, 10] + + result = first + last - middle + + if first == middle or middle == last: + return + + assert first < middle + assert middle < last + + # m prefix for mutable + var + mFirst = first + mMiddle = middle + next = middle + + swap(arg[mFirst], arg[next]) + mFirst += 1 + next += 1 + if mFirst == mMiddle: + mMiddle = next + + while next != last: + swap(arg[mFirst], arg[next]) + mFirst += 1 + next += 1 + if mFirst == mMiddle: + mMiddle = next + + next = mMiddle + while next != last: + swap(arg[mFirst], arg[next]) + mFirst += 1 + next += 1 + if mFirst == mMiddle: + mMiddle = next + elif next == last: + next = mMiddle + +proc rotate[T](arg: var openarray[T]; middle: int): int {.discardable.} = + ## default arguments for first and last, so that this procedure operates on the entire + ## argument, and not just on a portion of it. + arg.rotate(0, middle, arg.len) + +proc rotated*[T](arg: openarray[T]; first, middle, last: int): seq[T] = + ## same as ``rotate``, just with the difference that it does + ## not modify the argument, but writes into a new ``seq`` instead + + result = newSeq[T](arg.len) + + for i in 0 ..< first: + result[i] = arg[i] + + let N = last - middle + let M = middle - first + + for i in 0 ..< N: + result[first+i] = arg[middle+i] + + for i in 0 ..< M: + result[first+N+i] = arg[first+i] + + for i in last ..< arg.len: + result[i] = arg[i] + +proc rotated*[T](arg: openarray[T]; middle: int): seq[T] = + ## same as ``rotate``, just with the difference that it does + ## not modify the argument, but writes into a new ``seq`` instead + arg.rotated(0, middle, arg.len) + +when isMainModule: + var list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + let list2 = list.rotated(1,4,9) + let expected = [0, 4, 5, 6, 7, 8, 1, 2, 3, 9, 10] + + doAssert list.rotate(1,4,9) == 6 + doAssert list == expected + doAssert list2 == @expected + + var s0,s1,s2 = "xxxabcdefgxxx" + + doAssert s0.rotate(3, 6, 10) == 7 + doAssert s0 == "xxxdefgabcxxx" + doAssert s1.rotate(3, 5, 10) == 8 + doAssert s1 == "xxxcdefgabxxx" + doAssert s2.rotate(3, 7, 10) == 6 + doassert s2 == "xxxefgabcdxxx" + + -- cgit 1.4.1-2-gfad0 From c6417515232b496952e12948cbb787d93084d3eb Mon Sep 17 00:00:00 2001 From: Arne Döring Date: Tue, 21 Mar 2017 12:03:41 +0100 Subject: fixes for feedback --- lib/pure/algorithm.nim | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'lib/pure/algorithm.nim') diff --git a/lib/pure/algorithm.nim b/lib/pure/algorithm.nim index 189e96593..25d03a356 100644 --- a/lib/pure/algorithm.nim +++ b/lib/pure/algorithm.nim @@ -343,7 +343,7 @@ proc prevPermutation*[T](x: var openarray[T]): bool {.discardable.} = swap x[i-1], x[j] result = true - + when isMainModule: # Tests for lowerBound var arr = @[1,2,3,5,6,7,8,9] @@ -373,12 +373,14 @@ when isMainModule: assert arr1.reversed(i, high(arr1)) == arr1.reversed()[0 .. high(arr1) - i] -proc rotate*[T](arg: var openarray[T]; first, middle, last: int): int {.discardable.} = +proc rotate*[T](arg: var openarray[T]; first, middle, last: int): int = ## Performs a left rotation on a range of elements. ## Specifically, ``rotate`` swaps the elements in the range [first, last) in such a way ## that the element at index ``middle`` becomes the first element of the sub range and ## ``middle - 1`` becomes the last element of the sub range. The time complexity is ## linear to ``last - first``. returns ``first + (last - middle)``. ``T`` must support swap operation + ## returs ``first + last - middle``, the new index, where the element this was at index ``last`` will + ## be ater the rotation. ## ## ``first`` ## the index of the first element that should be rotated. @@ -388,7 +390,7 @@ proc rotate*[T](arg: var openarray[T]; first, middle, last: int): int {.discarda ## ## ``last`` ## the index of the first element that should not be rotated anymore (exclusive upper bound). - ## + ## ## .. code-block:: nim ## var list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ## list.rotate(1,4,9) @@ -431,15 +433,15 @@ proc rotate*[T](arg: var openarray[T]; first, middle, last: int): int {.discarda elif next == last: next = mMiddle -proc rotate[T](arg: var openarray[T]; middle: int): int {.discardable.} = - ## default arguments for first and last, so that this procedure operates on the entire - ## argument, and not just on a portion of it. +proc rotate*[T](arg: var openarray[T]; middle: int): int = + ## default arguments for first and last, so that this procedure operates on entire + ## ``arg``, and not just on a part of it. arg.rotate(0, middle, arg.len) proc rotated*[T](arg: openarray[T]; first, middle, last: int): seq[T] = ## same as ``rotate``, just with the difference that it does - ## not modify the argument, but writes into a new ``seq`` instead - + ## not modify the argument. It creates a new ``seq`` instead + result = newSeq[T](arg.len) for i in 0 ..< first: @@ -459,14 +461,15 @@ proc rotated*[T](arg: openarray[T]; first, middle, last: int): seq[T] = proc rotated*[T](arg: openarray[T]; middle: int): seq[T] = ## same as ``rotate``, just with the difference that it does - ## not modify the argument, but writes into a new ``seq`` instead + ## not modify the argument. It creates a new ``seq`` instead + arg.rotated(0, middle, arg.len) - + when isMainModule: var list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] let list2 = list.rotated(1,4,9) let expected = [0, 4, 5, 6, 7, 8, 1, 2, 3, 9, 10] - + doAssert list.rotate(1,4,9) == 6 doAssert list == expected doAssert list2 == @expected @@ -479,5 +482,3 @@ when isMainModule: doAssert s1 == "xxxcdefgabxxx" doAssert s2.rotate(3, 7, 10) == 6 doassert s2 == "xxxefgabcdxxx" - - -- cgit 1.4.1-2-gfad0 From 409854c91379610853103cabc3ec29c04fbd13e0 Mon Sep 17 00:00:00 2001 From: Arne Döring Date: Thu, 27 Jul 2017 17:39:34 +0200 Subject: changed rotate to rotateLeft with slice api --- lib/pure/algorithm.nim | 86 ++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 45 deletions(-) (limited to 'lib/pure/algorithm.nim') diff --git a/lib/pure/algorithm.nim b/lib/pure/algorithm.nim index 25d03a356..ea7752b18 100644 --- a/lib/pure/algorithm.nim +++ b/lib/pure/algorithm.nim @@ -373,29 +373,7 @@ when isMainModule: assert arr1.reversed(i, high(arr1)) == arr1.reversed()[0 .. high(arr1) - i] -proc rotate*[T](arg: var openarray[T]; first, middle, last: int): int = - ## Performs a left rotation on a range of elements. - ## Specifically, ``rotate`` swaps the elements in the range [first, last) in such a way - ## that the element at index ``middle`` becomes the first element of the sub range and - ## ``middle - 1`` becomes the last element of the sub range. The time complexity is - ## linear to ``last - first``. returns ``first + (last - middle)``. ``T`` must support swap operation - ## returs ``first + last - middle``, the new index, where the element this was at index ``last`` will - ## be ater the rotation. - ## - ## ``first`` - ## the index of the first element that should be rotated. - ## - ## ``middle`` - ## the index of the element that should appear at the beginning of the rotated range. - ## - ## ``last`` - ## the index of the first element that should not be rotated anymore (exclusive upper bound). - ## - ## .. code-block:: nim - ## var list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - ## list.rotate(1,4,9) - ## echo @list # @[0, 4, 5, 6, 7, 8, 1, 2, 3, 9, 10] - +proc rotate_internal[T](arg: var openarray[T]; first, middle, last: int): int = result = first + last - middle if first == middle or middle == last: @@ -433,52 +411,70 @@ proc rotate*[T](arg: var openarray[T]; first, middle, last: int): int = elif next == last: next = mMiddle -proc rotate*[T](arg: var openarray[T]; middle: int): int = - ## default arguments for first and last, so that this procedure operates on entire - ## ``arg``, and not just on a part of it. - arg.rotate(0, middle, arg.len) - -proc rotated*[T](arg: openarray[T]; first, middle, last: int): seq[T] = - ## same as ``rotate``, just with the difference that it does - ## not modify the argument. It creates a new ``seq`` instead - +proc rotated_internal[T](arg: openarray[T]; first, middle, last: int): seq[T] = result = newSeq[T](arg.len) - for i in 0 ..< first: result[i] = arg[i] - let N = last - middle let M = middle - first - for i in 0 ..< N: result[first+i] = arg[middle+i] - for i in 0 ..< M: result[first+N+i] = arg[first+i] - for i in last ..< arg.len: result[i] = arg[i] -proc rotated*[T](arg: openarray[T]; middle: int): seq[T] = - ## same as ``rotate``, just with the difference that it does +proc rotateLeft*[T](arg: var openarray[T]; slice: Slice[int]; dist: int): int = + ## Performs a left rotation on a range of elements. + ## Specifically, ``rotate`` rotates the elements at ``slice`` by ``dist`` positions.. + ## The element at index ``slice.a + dist`` will be at index ``slice.a``. + ## The element at index ``slice.b`` will be at ``slice.a + dist -1``. + ## The element at index ``slice.a`` will be at ``slice.b + 1 - dist``. + ## The element at index ``slice.a + dist - 1`` will be at ``slice.b``. + ## Elements outsize of ``slice`` well be left unchanged. + ## The time complexity is linear to ``slice.b - slice.a + 1``. + ## + ## ``slice`` + ## the indices of the element range that should be rotated. + ## + ## ``dist`` + ## the distance in amount of elements that the data should be rotated. + ## + ## .. code-block:: nim + ## var list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + ## list.rotateLeft(1 .. 8, 3) + ## echo @list # @[0, 4, 5, 6, 7, 8, 1, 2, 3, 9, 10] + arg.rotate_internal(slice.a, slice.a+dist, slice.b + 1) + +proc rotateLeft*[T](arg: var openarray[T]; dist: int): int = + ## default arguments for slice, so that this procedure operates on the entire + ## ``arg``, and not just on a part of it. + arg.rotate_internal(0, dist, arg.len) + +proc rotatedLeft*[T](arg: openarray[T]; slice: Slice[int], dist: int): seq[T] = + ## same as ``rotateLeft``, just with the difference that it does ## not modify the argument. It creates a new ``seq`` instead + arg.rotated_internal(slice.a, slice.a+dist, slice.b+1) - arg.rotated(0, middle, arg.len) +proc rotatedLeft*[T](arg: openarray[T]; dist: int): seq[T] = + ## same as ``rotateLeft``, just with the difference that it does + ## not modify the argument. It creates a new ``seq`` instead + arg.rotated_internal(0, dist, arg.len) when isMainModule: var list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - let list2 = list.rotated(1,4,9) + let list2 = list.rotatedLeft(1 ..< 9, 3) let expected = [0, 4, 5, 6, 7, 8, 1, 2, 3, 9, 10] - doAssert list.rotate(1,4,9) == 6 + doAssert list.rotateLeft(1 ..< 9, 3) == 6 doAssert list == expected doAssert list2 == @expected var s0,s1,s2 = "xxxabcdefgxxx" - doAssert s0.rotate(3, 6, 10) == 7 + doAssert s0.rotateLeft(3 ..< 10, 3) == 7 doAssert s0 == "xxxdefgabcxxx" - doAssert s1.rotate(3, 5, 10) == 8 + doAssert s1.rotateLeft(3 ..< 10, 2) == 8 doAssert s1 == "xxxcdefgabxxx" - doAssert s2.rotate(3, 7, 10) == 6 + doAssert s2.rotateLeft(3 ..< 10, 4) == 6 doassert s2 == "xxxefgabcdxxx" -- cgit 1.4.1-2-gfad0 From 316886542b0a7b9143e0ba96ef93b93a9caadbe6 Mon Sep 17 00:00:00 2001 From: Arne Döring Date: Thu, 27 Jul 2017 18:22:59 +0200 Subject: allow a negative distance argument. Improved documentation. --- lib/pure/algorithm.nim | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'lib/pure/algorithm.nim') diff --git a/lib/pure/algorithm.nim b/lib/pure/algorithm.nim index ea7752b18..a808b6703 100644 --- a/lib/pure/algorithm.nim +++ b/lib/pure/algorithm.nim @@ -425,7 +425,7 @@ proc rotated_internal[T](arg: openarray[T]; first, middle, last: int): seq[T] = result[i] = arg[i] proc rotateLeft*[T](arg: var openarray[T]; slice: Slice[int]; dist: int): int = - ## Performs a left rotation on a range of elements. + ## Performs a left rotation on a range of elements. If you want to rotate right, use a negative ``dist``. ## Specifically, ``rotate`` rotates the elements at ``slice`` by ``dist`` positions.. ## The element at index ``slice.a + dist`` will be at index ``slice.a``. ## The element at index ``slice.b`` will be at ``slice.a + dist -1``. @@ -438,28 +438,36 @@ proc rotateLeft*[T](arg: var openarray[T]; slice: Slice[int]; dist: int): int = ## the indices of the element range that should be rotated. ## ## ``dist`` - ## the distance in amount of elements that the data should be rotated. + ## the distance in amount of elements that the data should be rotated. Can be negative, can be any number. ## ## .. code-block:: nim ## var list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ## list.rotateLeft(1 .. 8, 3) ## echo @list # @[0, 4, 5, 6, 7, 8, 1, 2, 3, 9, 10] - arg.rotate_internal(slice.a, slice.a+dist, slice.b + 1) + let sliceLen = slice.b + 1 - slice.a + let distLeft = ((dist mod sliceLen) + sliceLen) mod sliceLen + arg.rotate_internal(slice.a, slice.a+distLeft, slice.b + 1) proc rotateLeft*[T](arg: var openarray[T]; dist: int): int = ## default arguments for slice, so that this procedure operates on the entire ## ``arg``, and not just on a part of it. - arg.rotate_internal(0, dist, arg.len) + let arglen = arg.len + let distLeft = ((dist mod arglen) + arglen) mod arglen + arg.rotate_internal(0, distLeft, arglen) proc rotatedLeft*[T](arg: openarray[T]; slice: Slice[int], dist: int): seq[T] = ## same as ``rotateLeft``, just with the difference that it does ## not modify the argument. It creates a new ``seq`` instead - arg.rotated_internal(slice.a, slice.a+dist, slice.b+1) + let sliceLen = slice.b + 1 - slice.a + let distLeft = ((dist mod sliceLen) + sliceLen) mod sliceLen + arg.rotated_internal(slice.a, slice.a+distLeft, slice.b+1) proc rotatedLeft*[T](arg: openarray[T]; dist: int): seq[T] = ## same as ``rotateLeft``, just with the difference that it does ## not modify the argument. It creates a new ``seq`` instead - arg.rotated_internal(0, dist, arg.len) + let arglen = arg.len + let distLeft = ((dist mod arglen) + arglen) mod arglen + arg.rotated_internal(0, distLeft, arg.len) when isMainModule: var list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] @@ -470,11 +478,17 @@ when isMainModule: doAssert list == expected doAssert list2 == @expected - var s0,s1,s2 = "xxxabcdefgxxx" + var s0,s1,s2,s3,s4,s5 = "xxxabcdefgxxx" doAssert s0.rotateLeft(3 ..< 10, 3) == 7 doAssert s0 == "xxxdefgabcxxx" doAssert s1.rotateLeft(3 ..< 10, 2) == 8 doAssert s1 == "xxxcdefgabxxx" doAssert s2.rotateLeft(3 ..< 10, 4) == 6 - doassert s2 == "xxxefgabcdxxx" + doAssert s2 == "xxxefgabcdxxx" + doAssert s3.rotateLeft(3 ..< 10, -3) == 6 + doAssert s3 == "xxxefgabcdxxx" + doAssert s4.rotateLeft(3 ..< 10, -10) == 6 + doAssert s4 == "xxxefgabcdxxx" + doAssert s5.rotateLeft(3 ..< 10, 11) == 6 + doAssert s5 == "xxxefgabcdxxx" -- cgit 1.4.1-2-gfad0 From efe606ef81849984ec4de2e18be72ceff933d743 Mon Sep 17 00:00:00 2001 From: Arne Döring Date: Mon, 14 Aug 2017 13:55:38 +0200 Subject: fix for feedback on PR --- lib/pure/algorithm.nim | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'lib/pure/algorithm.nim') diff --git a/lib/pure/algorithm.nim b/lib/pure/algorithm.nim index a808b6703..2fac537e3 100644 --- a/lib/pure/algorithm.nim +++ b/lib/pure/algorithm.nim @@ -373,11 +373,12 @@ when isMainModule: assert arr1.reversed(i, high(arr1)) == arr1.reversed()[0 .. high(arr1) - i] -proc rotate_internal[T](arg: var openarray[T]; first, middle, last: int): int = +proc rotateInternal[T](arg: var openarray[T]; first, middle, last: int): int = + ## A port of std::rotate from c++. Ported from `this reference `_. result = first + last - middle if first == middle or middle == last: - return + return assert first < middle assert middle < last @@ -411,7 +412,7 @@ proc rotate_internal[T](arg: var openarray[T]; first, middle, last: int): int = elif next == last: next = mMiddle -proc rotated_internal[T](arg: openarray[T]; first, middle, last: int): seq[T] = +proc rotatedInternal[T](arg: openarray[T]; first, middle, last: int): seq[T] = result = newSeq[T](arg.len) for i in 0 ..< first: result[i] = arg[i] @@ -426,12 +427,13 @@ proc rotated_internal[T](arg: openarray[T]; first, middle, last: int): seq[T] = proc rotateLeft*[T](arg: var openarray[T]; slice: Slice[int]; dist: int): int = ## Performs a left rotation on a range of elements. If you want to rotate right, use a negative ``dist``. - ## Specifically, ``rotate`` rotates the elements at ``slice`` by ``dist`` positions.. + ## Specifically, ``rotateLeft`` rotates the elements at ``slice`` by ``dist`` positions. ## The element at index ``slice.a + dist`` will be at index ``slice.a``. ## The element at index ``slice.b`` will be at ``slice.a + dist -1``. ## The element at index ``slice.a`` will be at ``slice.b + 1 - dist``. ## The element at index ``slice.a + dist - 1`` will be at ``slice.b``. - ## Elements outsize of ``slice`` well be left unchanged. + # + ## Elements outsize of ``slice`` will be left unchanged. ## The time complexity is linear to ``slice.b - slice.a + 1``. ## ## ``slice`` @@ -446,28 +448,28 @@ proc rotateLeft*[T](arg: var openarray[T]; slice: Slice[int]; dist: int): int = ## echo @list # @[0, 4, 5, 6, 7, 8, 1, 2, 3, 9, 10] let sliceLen = slice.b + 1 - slice.a let distLeft = ((dist mod sliceLen) + sliceLen) mod sliceLen - arg.rotate_internal(slice.a, slice.a+distLeft, slice.b + 1) + arg.rotateInternal(slice.a, slice.a+distLeft, slice.b + 1) proc rotateLeft*[T](arg: var openarray[T]; dist: int): int = ## default arguments for slice, so that this procedure operates on the entire ## ``arg``, and not just on a part of it. let arglen = arg.len let distLeft = ((dist mod arglen) + arglen) mod arglen - arg.rotate_internal(0, distLeft, arglen) + arg.rotateInternal(0, distLeft, arglen) proc rotatedLeft*[T](arg: openarray[T]; slice: Slice[int], dist: int): seq[T] = ## same as ``rotateLeft``, just with the difference that it does ## not modify the argument. It creates a new ``seq`` instead let sliceLen = slice.b + 1 - slice.a let distLeft = ((dist mod sliceLen) + sliceLen) mod sliceLen - arg.rotated_internal(slice.a, slice.a+distLeft, slice.b+1) + arg.rotatedInternal(slice.a, slice.a+distLeft, slice.b+1) proc rotatedLeft*[T](arg: openarray[T]; dist: int): seq[T] = ## same as ``rotateLeft``, just with the difference that it does ## not modify the argument. It creates a new ``seq`` instead let arglen = arg.len let distLeft = ((dist mod arglen) + arglen) mod arglen - arg.rotated_internal(0, distLeft, arg.len) + arg.rotatedInternal(0, distLeft, arg.len) when isMainModule: var list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] -- cgit 1.4.1-2-gfad0 From 484f729e27f5d6f51120a207120627166bf4d240 Mon Sep 17 00:00:00 2001 From: Arne Döring Date: Thu, 17 Aug 2017 13:34:03 +0200 Subject: use doAssert in rotateLeft example --- lib/pure/algorithm.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/pure/algorithm.nim') diff --git a/lib/pure/algorithm.nim b/lib/pure/algorithm.nim index 2fac537e3..1b0790706 100644 --- a/lib/pure/algorithm.nim +++ b/lib/pure/algorithm.nim @@ -445,7 +445,7 @@ proc rotateLeft*[T](arg: var openarray[T]; slice: Slice[int]; dist: int): int = ## .. code-block:: nim ## var list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ## list.rotateLeft(1 .. 8, 3) - ## echo @list # @[0, 4, 5, 6, 7, 8, 1, 2, 3, 9, 10] + ## doAssert list == [0, 4, 5, 6, 7, 8, 1, 2, 3, 9, 10] let sliceLen = slice.b + 1 - slice.a let distLeft = ((dist mod sliceLen) + sliceLen) mod sliceLen arg.rotateInternal(slice.a, slice.a+distLeft, slice.b + 1) -- cgit 1.4.1-2-gfad0