This commit is contained in:
Andreas Rumpf 2017-10-30 14:45:57 +01:00
commit b14cc1e3b2
8 changed files with 65 additions and 38 deletions

View file

@ -425,7 +425,7 @@ proc rotatedInternal[T](arg: openarray[T]; first, middle, last: int): seq[T] =
for i in last ..< arg.len:
result[i] = arg[i]
proc rotateLeft*[T](arg: var openarray[T]; slice: Slice[int, int]; dist: int): int =
proc rotateLeft*[T](arg: var openarray[T]; slice: HSlice[int, int]; dist: int): int =
## Performs a left rotation on a range of elements. If you want to rotate right, use a negative ``dist``.
## Specifically, ``rotateLeft`` rotates the elements at ``slice`` by ``dist`` positions.
## The element at index ``slice.a + dist`` will be at index ``slice.a``.
@ -457,7 +457,7 @@ proc rotateLeft*[T](arg: var openarray[T]; dist: int): int =
let distLeft = ((dist mod arglen) + arglen) mod arglen
arg.rotateInternal(0, distLeft, arglen)
proc rotatedLeft*[T](arg: openarray[T]; slice: Slice[int, int], dist: int): seq[T] =
proc rotatedLeft*[T](arg: openarray[T]; slice: HSlice[int, 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

View file

@ -55,7 +55,7 @@ proc `[]=`*(s: var SharedString; i: Natural; value: char) =
if i < s.len: s.buffer.data[i+s.first] = value
else: raise newException(IndexError, "index out of bounds")
proc `[]`*(s: SharedString; ab: Slice[int]): SharedString =
proc `[]`*(s: SharedString; ab: HSlice[int, int]): SharedString =
#incRef(src.buffer)
if ab.a < s.len:
result.buffer = s.buffer

View file

@ -48,7 +48,7 @@ proc validEmailAddress*(s: string): bool {.noSideEffect,
"aero", "jobs", "museum": return true
else: return false
proc parseInt*(s: string, value: var int, validRange: Slice[int, int]) {.
proc parseInt*(s: string, value: var int, validRange: HSlice[int, int]) {.
noSideEffect, rtl, extern: "nmatchParseInt".} =
## parses `s` into an integer in the range `validRange`. If successful,
## `value` is modified to contain the result. Otherwise no exception is

View file

@ -93,7 +93,7 @@ proc random*(max: float): float {.benign.} =
let u = (0x3FFu64 shl 52u64) or (x shr 12u64)
result = (cast[float](u) - 1.0) * max
proc random*[T](x: Slice[T, T]): T =
proc random*[T](x: HSlice[T, T]): T =
## For a slice `a .. b` returns a value in the range `a .. b-1`.
result = T(random(x.b - x.a)) + x.a