@@ -16,9 +16,9 @@ Elm.Native.Array.make = function(elm) {
16 // M is the maximal node size. 32 seems fast. E is the allowed increase
16 // M is the maximal node size. 32 seems fast. E is the allowed increase
17 // of search steps when concatting to find an index. Lower values will
17 // of search steps when concatting to find an index. Lower values will
18 // decrease balancing, but will increase search steps.
18 // decrease balancing, but will increase search steps.
19− var M = 32;
19+ var M = 32;
20 var E = 2;
20 var E = 2;
22 // An empty array.
22 // An empty array.
23 var empty = { ctor:"_Array", _0:0, _1:new Array() };
23 var empty = { ctor:"_Array", _0:0, _1:new Array() };
@@ -31,12 +31,12 @@ Elm.Native.Array.make = function(elm) {
31 throw new Error("Index "+ i +" on the array is out of range. Check the length first or you safeGet.");
31 throw new Error("Index "+ i +" on the array is out of range. Check the length first or you safeGet.");
35 var slot = getSlot(i, a);
35 var slot = getSlot(i, a);
36 var sub = slot > 0 ? a._2[slot-1] : 0;
36 var sub = slot > 0 ? a._2[slot-1] : 0;
37 return get(i - sub, a._1[slot]);
37 return get(i - sub, a._1[slot]);
40 // Sets the value at the index i. Only the nodes leading to i will get
40 // Sets the value at the index i. Only the nodes leading to i will get
41 // copied and updated.
41 // copied and updated.
42 function set(i, item, a) {
42 function set(i, item, a) {
@@ -81,7 +81,7 @@ Elm.Native.Array.make = function(elm) {
81 return null;
81 return null;
85 // Recursively push
85 // Recursively push
86 var pushed = push_(item, botRight(a));
86 var pushed = push_(item, botRight(a));
@@ -124,7 +124,7 @@ Elm.Native.Array.make = function(elm) {
124 function map(f, a) {
124 function map(f, a) {
125 var newA = { ctor:"_Array", _0:a._0, _1:new Array(a._1) };
125 var newA = { ctor:"_Array", _0:a._0, _1:new Array(a._1) };
126 if (a._0 > 0) { newA._2 = a._2; }
126 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++) {
128 newA._1[i] = a._0 == 0 ? f(a._1[i]) : map(f, a._1[i]);
128 newA._1[i] = a._0 == 0 ? f(a._1[i]) : map(f, a._1[i]);
130 return newA;
130 return newA;
@@ -156,7 +156,7 @@ Elm.Native.Array.make = function(elm) {
156 // Returns a sliced tree. The to is inclusive, but this may change,
156 // Returns a sliced tree. The to is inclusive, but this may change,
157 // when I understand, why e.g. JS does not handle it this way. :-)
157 // when I understand, why e.g. JS does not handle it this way. :-)
158 // If from or to is negative, they will select from the end on.
158 // 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
160 // optimized.
160 // optimized.
161 function slice(from, to, a) {
161 function slice(from, to, a) {
162 if (from < 0) { from += length(a); }
162 if (from < 0) { from += length(a); }
@@ -184,7 +184,7 @@ Elm.Native.Array.make = function(elm) {
184 if (right == 0) {
184 if (right == 0) {
185 return sliced;
185 return sliced;
188 // Create new node.
188 // Create new node.
189 var newA = { ctor:"_Array", _0:a._0
189 var newA = { ctor:"_Array", _0:a._0
190 , _1:a._1.slice(0, right + 1)
190 , _1:a._1.slice(0, right + 1)
@@ -219,7 +219,7 @@ Elm.Native.Array.make = function(elm) {
219 var newA = { ctor:"_Array", _0:a._0
219 var newA = { ctor:"_Array", _0:a._0
220 , _1:a._1.slice(left, a._1.length + 1)
220 , _1:a._1.slice(left, a._1.length + 1)
221 , _2:new Array(a._1.length - left) };
221 , _2:new Array(a._1.length - left) };
222− newA._1[left] = sliced;
222+ newA._1[left] = sliced;
223 var len = 0;
223 var len = 0;
224 for (var i = 0; i < newA._1.length; i++) {
224 for (var i = 0; i < newA._1.length; i++) {
225 len += length(newA._1[i]);
225 len += length(newA._1[i]);
@@ -258,7 +258,7 @@ Elm.Native.Array.make = function(elm) {
259 return shuffle(a, b, toRemove);
259 return shuffle(a, b, toRemove);
262 var concated = concat_(botRight(a), botLeft(b));
262 var concated = concat_(botRight(a), botLeft(b));
263 a = nodeCopy(a), b = nodeCopy(b);
263 a = nodeCopy(a), b = nodeCopy(b);
@@ -302,9 +302,9 @@ Elm.Native.Array.make = function(elm) {
302 subLengths += b._1[i]._1.length;
302 subLengths += b._1[i]._1.length;
305− var toRemove = a._1.length + b._1.length
305+ var toRemove = a._1.length + b._1.length
306 return toRemove - (Math.floor((subLengths - 1) / M) + 1);
306 return toRemove - (Math.floor((subLengths - 1) / M) + 1);
309 // get2 and set2 are helpers for accessing over two arrays.
309 // get2 and set2 are helpers for accessing over two arrays.
310 function get2(a, b, index) {
310 function get2(a, b, index) {
@@ -333,7 +333,7 @@ Elm.Native.Array.make = function(elm) {
333 function saveSlot(a, b, index, slot) {
333 function saveSlot(a, b, index, slot) {
334 set2(a._1, b._1, index, slot);
334 set2(a._1, b._1, index, slot);
336− var l = (index == 0 || index == a._2.length) ?
336+ var l = (index == 0 || index == a._2.length) ?
337 0 : get2(a._2, a._2, index - 1);
337 0 : get2(a._2, a._2, index - 1);
338 set2(a._2, b._2, index, l + length(slot));
338 set2(a._2, b._2, index, l + length(slot));
@@ -384,12 +384,12 @@ Elm.Native.Array.make = function(elm) {
386 // Only create a new slot if the current one is filled up.
386 // Only create a new slot if the current one is filled up.
387− if (slot._1.length == M) {
387+ if (slot._1.length == M) {
388 saveSlot(newA, newB, write, slot);
388 saveSlot(newA, newB, write, slot);
389 slot = createNode(a._0 - 1,0);
389 slot = createNode(a._0 - 1,0);
394 // Cleanup after the loop. Copy the last slot into the new nodes.
394 // Cleanup after the loop. Copy the last slot into the new nodes.
395 if (slot._1.length > 0) {
395 if (slot._1.length > 0) {
@@ -398,7 +398,7 @@ Elm.Native.Array.make = function(elm) {
400 // Shift the untouched slots to the left
400 // 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 ) {
402 saveSlot(newA, newB, write, get2(a._1, b._1, read));
402 saveSlot(newA, newB, write, get2(a._1, b._1, read));
403 read++; write++;
403 read++; write++;
@@ -486,5 +486,3 @@ Elm.Native.Array.make = function(elm) {
487 return elm.Native.Array.values = Elm.Native.Array.values;
487 return elm.Native.Array.values = Elm.Native.Array.values;