summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@googlemail.com>2015-05-16 18:52:30 +0100
committerDominik Picheta <dominikpicheta@googlemail.com>2015-05-16 18:52:30 +0100
commit61c7cc2ff76fbc589d4827d9eba257b280e43c4a (patch)
treeceb5f4ec8889e29cd118d7f15af09b17e87901ed
parent4441c961c94c6cc479dab6096f63786038b3f6ca (diff)
parent3a3a7d012f35b4c40ec212748e58caa7bdc3b0d6 (diff)
downloadNim-61c7cc2ff76fbc589d4827d9eba257b280e43c4a.tar.gz
Merge pull request #2701 from borisvassilev/fill
Fill array with same values (was issue #2462)
-rw-r--r--lib/pure/algorithm.nim11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/pure/algorithm.nim b/lib/pure/algorithm.nim
index 6dfdff275..46d049f14 100644
--- a/lib/pure/algorithm.nim
+++ b/lib/pure/algorithm.nim
@@ -24,6 +24,17 @@ proc `*`*(x: int, order: SortOrder): int {.inline.} =
   var y = order.ord - 1
   result = (x xor y) - y
 
+proc fill*[T](a: var openArray[T], first, last: Natural, value: T) =
+  ## fills the array ``a[first..last]`` with `value`.
+  var x = first
+  while x <= last:
+    a[x] = value
+    inc(x)
+
+proc fill*[T](a: var openArray[T], value: T) =
+  ## fills the array `a` with `value`.
+  fill(a, 0, a.high, value)
+
 proc reverse*[T](a: var openArray[T], first, last: Natural) =
   ## reverses the array ``a[first..last]``.
   var x = first