on master help sign in
Remove trailing whitespaces
commitfecaad394df41c5e878b1355fb7cd5b78b0d39f1 authorChristian Widera <xash@posteo.de> dateMon 31 Mar 2014, 16:25 (13 years ago) parentbb81ddb
2 files changed+31−33
libraries/Array.elm+14−14 libraries/Native/Array.js+17−19
libraries/Array.elm+14−14
@@ -4,7 +4,7 @@ module Array where
44array must have the same type. The arrays are implemented in Relaxed
55Radix Balanced-Trees for fast updating and concating.
66
7−If you use more then one map or zip function on an array, consider turning it
7+If you use more then one map or zip function on an array, consider turning it
88first into a list, operating on it, and then turning it back into an array.
99
1010# Basics
@@ -27,7 +27,7 @@ import List
2727
2828data Array a = Array
2929
30−{-| Fills an array with a given length and a default element.
30+{-| Fills an array with a given length and a default element.
3131
3232 fill 3 5 == fromList [5,5,5]
3333-}
@@ -59,7 +59,7 @@ indices a = [0..Native.Array.length a - 1]
5959assocs : Array a -> [(Int, a)]
6060assocs a = List.zip (indices a) (Native.Array.elements a)
6161
62−{-| Apply a function on every element in an array.
62+{-| Apply a function on every element in an array.
6363
6464 map (\x -> x*x) (fromList [1,2,3]) == fromList [1,4,9]
6565-}
@@ -73,7 +73,7 @@ map = Native.Array.map
7373assocMap : (Int -> a -> b) -> Array a -> Array b
7474assocMap = Native.Array.assocMap
7575
76−{-| Reduce an array from the left.
76+{-| Reduce an array from the left.
7777
7878 foldl (+) 0 (fill 3 5) == 15
7979-}
@@ -87,7 +87,7 @@ foldl = Native.Array.foldl
8787foldr : (a -> b -> b) -> b -> Array a -> b
8888foldr = Native.Array.foldr
8989
90−{-| Zip the elements of two arrays via a tuple into a new array. If one array is
90+{-| Zip the elements of two arrays via a tuple into a new array. If one array is
9191longer, the extra elements are dropped.
9292
9393 zip (fromList [1,2,3,4]) (fromList [0,0,0]) = fromList [(1,0), (2,0), (3,0)]
@@ -95,16 +95,16 @@ longer, the extra elements are dropped.
9595zip : Array a -> Array b -> Array (a,b)
9696zip = zipWith (,)
9797
98−{-| Zips the elements of two arrays via a function into a new array. If one array
98+{-| Zips the elements of two arrays via a function into a new array. If one array
9999is longer, the extra elements are dropped.
100100
101101 zipWith (+) (fill 3 5) (fill 5 8) == fill 3 13
102102-}
103103zipWith : (a -> b -> c) -> Array a -> Array b -> Array c
104−zipWith f a b =
104+zipWith f a b =
105105 fromList <| List.zipWith f (Native.Array.elements a) (Native.Array.elements b)
106106
107−{-| Return an empty array.
107+{-| Return an empty array.
108108
109109 length empty == 0
110110-}
@@ -118,8 +118,8 @@ empty = Native.Array.empty
118118push : a -> Array a -> Array a
119119push = Native.Array.push
120120
121−{-| Return the value at the index. Breaks, if index is out of range. If the
122−array length is unkown, use safeGet oder getWithDefault.
121+{-| Return the value at the index. Breaks, if index is out of range. If the
122+array length is unkown, use safeGet oder getWithDefault.
123123
124124 get 2 (A.fromList [3,2,1]) == 1
125125-}
@@ -136,7 +136,7 @@ safeGet i array = if Native.Array.length array > i
136136 then Just (Native.Array.get i array)
137137 else Nothing
138138
139−{-| Get the element at the index. If the index is out of range, the given default
139+{-| Get the element at the index. If the index is out of range, the given default
140140elementis returned.
141141
142142 getWithDefault 0 2 (A.fromList [3,2,1]) == 1
@@ -146,7 +146,7 @@ getWithDefault : a -> Int -> Array a -> a
146146getWithDefault default i array = if Native.Array.length array > i
147147 then Native.Array.get i array else default
148148
149−{-| Set the element at the index. Returns the updated array, or if the index is
149+{-| Set the element at the index. Returns the updated array, or if the index is
150150out of range, the unaltered array.
151151
152152 set 1 7 (fromList [1,2,3]) == fromList [1,7,3]
@@ -162,7 +162,7 @@ updates : [(Int, a)] -> Array a -> Array a
162162updates assocs array = List.foldl (uncurry Native.Array.set) array assocs
163163
164164{-| Slice an array given a range. The selection is inclusive, so the last
165−element in the selection will also be in the new array. This may change in the
165+element in the selection will also be in the new array. This may change in the
166166future.
167167You can select from the end by giving a negative Int.
168168
@@ -180,7 +180,7 @@ slice = Native.Array.slice
180180length : Array a -> Int
181181length = Native.Array.length
182182
183−{-| Concat two arrays to a new one.
183+{-| Concat two arrays to a new one.
184184
185185 concat (fill 3 1) (fill 4 2) == fromList [1,1,1,2,2,2,2]
186186-}
libraries/Native/Array.js+17−19
@@ -16,9 +16,9 @@ Elm.Native.Array.make = function(elm) {
1616 // M is the maximal node size. 32 seems fast. E is the allowed increase
1717 // of search steps when concatting to find an index. Lower values will
1818 // decrease balancing, but will increase search steps.
19− var M = 32;
19+ var M = 32;
2020 var E = 2;
21−
21+
2222 // An empty array.
2323 var empty = { ctor:"_Array", _0:0, _1:new Array() };
2424
@@ -31,12 +31,12 @@ Elm.Native.Array.make = function(elm) {
3131 throw new Error("Index "+ i +" on the array is out of range. Check the length first or you safeGet.");
3232 }
3333 }
34−
34+
3535 var slot = getSlot(i, a);
3636 var sub = slot > 0 ? a._2[slot-1] : 0;
3737 return get(i - sub, a._1[slot]);
38− }
39−
38+ }
39+
4040 // Sets the value at the index i. Only the nodes leading to i will get
4141 // copied and updated.
4242 function set(i, item, a) {
@@ -81,7 +81,7 @@ Elm.Native.Array.make = function(elm) {
8181 return null;
8282 }
8383 }
84−
84+
8585 // Recursively push
8686 var pushed = push_(item, botRight(a));
8787
@@ -124,7 +124,7 @@ Elm.Native.Array.make = function(elm) {
124124 function map(f, a) {
125125 var newA = { ctor:"_Array", _0:a._0, _1:new Array(a._1) };
126126 if (a._0 > 0) { newA._2 = a._2; }
127− for (var i = 0; i < a._1.length; i++) {
127+ for (var i = 0; i < a._1.length; i++) {
128128 newA._1[i] = a._0 == 0 ? f(a._1[i]) : map(f, a._1[i]);
129129 }
130130 return newA;
@@ -156,7 +156,7 @@ Elm.Native.Array.make = function(elm) {
156156 // Returns a sliced tree. The to is inclusive, but this may change,
157157 // when I understand, why e.g. JS does not handle it this way. :-)
158158 // If from or to is negative, they will select from the end on.
159− // TODO: currently, it slices the right, then the left. This can be
159+ // TODO: currently, it slices the right, then the left. This can be
160160 // optimized.
161161 function slice(from, to, a) {
162162 if (from < 0) { from += length(a); }
@@ -184,7 +184,7 @@ Elm.Native.Array.make = function(elm) {
184184 if (right == 0) {
185185 return sliced;
186186 }
187−
187+
188188 // Create new node.
189189 var newA = { ctor:"_Array", _0:a._0
190190 , _1:a._1.slice(0, right + 1)
@@ -219,7 +219,7 @@ Elm.Native.Array.make = function(elm) {
219219 var newA = { ctor:"_Array", _0:a._0
220220 , _1:a._1.slice(left, a._1.length + 1)
221221 , _2:new Array(a._1.length - left) };
222− newA._1[left] = sliced;
222+ newA._1[left] = sliced;
223223 var len = 0;
224224 for (var i = 0; i < newA._1.length; i++) {
225225 len += length(newA._1[i]);
@@ -258,7 +258,7 @@ Elm.Native.Array.make = function(elm) {
258258
259259 return shuffle(a, b, toRemove);
260260 }
261−
261+
262262 var concated = concat_(botRight(a), botLeft(b));
263263 a = nodeCopy(a), b = nodeCopy(b);
264264
@@ -302,9 +302,9 @@ Elm.Native.Array.make = function(elm) {
302302 subLengths += b._1[i]._1.length;
303303 }
304304
305− var toRemove = a._1.length + b._1.length
305+ var toRemove = a._1.length + b._1.length
306306 return toRemove - (Math.floor((subLengths - 1) / M) + 1);
307− }
307+ }
308308
309309 // get2 and set2 are helpers for accessing over two arrays.
310310 function get2(a, b, index) {
@@ -333,7 +333,7 @@ Elm.Native.Array.make = function(elm) {
333333 function saveSlot(a, b, index, slot) {
334334 set2(a._1, b._1, index, slot);
335335
336− var l = (index == 0 || index == a._2.length) ?
336+ var l = (index == 0 || index == a._2.length) ?
337337 0 : get2(a._2, a._2, index - 1);
338338 set2(a._2, b._2, index, l + length(slot));
339339 }
@@ -384,12 +384,12 @@ Elm.Native.Array.make = function(elm) {
384384 }
385385
386386 // Only create a new slot if the current one is filled up.
387− if (slot._1.length == M) {
387+ if (slot._1.length == M) {
388388 saveSlot(newA, newB, write, slot);
389389 slot = createNode(a._0 - 1,0);
390390 write++;
391391 }
392− }
392+ }
393393
394394 // Cleanup after the loop. Copy the last slot into the new nodes.
395395 if (slot._1.length > 0) {
@@ -398,7 +398,7 @@ Elm.Native.Array.make = function(elm) {
398398 }
399399
400400 // Shift the untouched slots to the left
401− while (read < a._1.length + b._1.length ) {
401+ while (read < a._1.length + b._1.length ) {
402402 saveSlot(newA, newB, write, get2(a._1, b._1, read));
403403 read++; write++;
404404 }
@@ -486,5 +486,3 @@ Elm.Native.Array.make = function(elm) {
486486
487487 return elm.Native.Array.values = Elm.Native.Array.values;
488488}
489−
490−