summary refs log tree commit diff stats
path: root/lib/pure/algorithm.nim
diff options
context:
space:
mode:
authorBoris Vassilev <boris.vassilev@gmail.com>2015-05-12 15:52:38 +0300
committerBoris Vassilev <boris.vassilev@gmail.com>2015-05-12 15:52:38 +0300
commit3a3a7d012f35b4c40ec212748e58caa7bdc3b0d6 (patch)
tree70dcbc1a49395caa85e49b90fdfe2834141ba3aa /lib/pure/algorithm.nim
parent0b184f2584221543a7dec9c8ae4a700533919e0c (diff)
downloadNim-3a3a7d012f35b4c40ec212748e58caa7bdc3b0d6.tar.gz
Fill array with same values (was issue #2462)
Diffstat (limited to 'lib/pure/algorithm.nim')
-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 f7ccb9234..20920bd44 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