on master help sign in
Clarify things
commit339f3b51fa5edfcddb7f9ebee407513808547b06 authorChristian Widera <xash@posteo.de> dateMon 31 Mar 2014, 22:45 (13 years ago) parent7c1f156
1 file changed+15−14
libraries/Native/Array.js+15−14
libraries/Native/Array.js+15−14
@@ -122,7 +122,7 @@ Elm.Native.Array.make = function(elm) {
122122 return list;
123123 }
124124
125− // Maps a function over an array.
125+ // Maps a function over the elements of an array.
126126 function map(f, a) {
127127 var newA = { ctor:"_Array", height:a.height, table:new Array(a.table) };
128128 if (a.height > 0) { newA.lengths = a.lengths; }
@@ -132,6 +132,7 @@ Elm.Native.Array.make = function(elm) {
132132 return newA;
133133 }
134134
135+ // Maps a function over the indices and elements of an array.
135136 function assocMap(f, a) {
136137 var newA = { ctor:"_Array", height:a.height, table:new Array(a.table) };
137138 if (a.height > 0) { newA.lengths = a.lengths; }
@@ -155,9 +156,9 @@ Elm.Native.Array.make = function(elm) {
155156 return b;
156157 }
157158
158− // Returns a sliced tree. The to is inclusive, but this may change,
159+ // Returns a sliced tree. "to" is inclusive, but this may change,
159160 // when I understand, why e.g. JS does not handle it this way. :-)
160− // If from or to is negative, they will select from the end on.
161+ // If "from" or "to" is negative, they will select from the end on.
161162 // TODO: currently, it slices the right, then the left. This can be
162163 // optimized.
163164 function slice(from, to, a) {
@@ -308,7 +309,7 @@ Elm.Native.Array.make = function(elm) {
308309 return toRemove - (Math.floor((subLengths - 1) / M) + 1);
309310 }
310311
311− // get2 and set2 are helpers for accessing over two arrays.
312+ // get2, set2 and saveSlot are helpers for accessing elements over two arrays.
312313 function get2(a, b, index) {
313314 return index < a.length ? a[index] : b[index - a.length];
314315 }
@@ -321,6 +322,14 @@ Elm.Native.Array.make = function(elm) {
321322 }
322323 }
323324
325+ function saveSlot(a, b, index, slot) {
326+ set2(a.table, b.table, index, slot);
327+
328+ var l = (index == 0 || index == a.lengths.length) ?
329+ 0 : get2(a.lengths, a.lengths, index - 1);
330+ set2(a.lengths, b.lengths, index, l + length(slot));
331+ }
332+
324333 // Creates a node or leaf with a given length at their arrays for perfomance.
325334 // Is only used by shuffle.
326335 function createNode(h, length) {
@@ -332,14 +341,6 @@ Elm.Native.Array.make = function(elm) {
332341 return a;
333342 }
334343
335− function saveSlot(a, b, index, slot) {
336− set2(a.table, b.table, index, slot);
337−
338− var l = (index == 0 || index == a.lengths.length) ?
339− 0 : get2(a.lengths, a.lengths, index - 1);
340− set2(a.lengths, b.lengths, index, l + length(slot));
341− }
342−
343344 // Returns an array of two balanced nodes.
344345 function shuffle(a, b, toRemove) {
345346 var newA = createNode(a.height, Math.min(M, a.table.length + b.table.length - toRemove));
@@ -430,8 +431,8 @@ Elm.Native.Array.make = function(elm) {
430431 }
431432 }
432433
433− // Calculates in which slot the item probably is, then
434− // find the exact slot in "lengths". Returns the index.
434+ // Calculates in which slot of "table" the item probably is, then
435+ // find the exact slot via forward searching in "lengths". Returns the index.
435436 function getSlot(i, a) {
436437 var slot = Math.floor(i / (Math.pow(M, a.height)));
437438 while (a.lengths[slot] <= i) {