You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The idea behind pullHead seems to be, instead of constantly splicing the array, just move the head pointer forward and delete the old element, creating a sparse array. Unfortunately, that's not what this line: queue.array[queue.head] = void 0; is doing. It just creates a reference to undefined and adds it to array.
What you probably wanted was this:
deletequeue.array[queue.head];
Tested in Chrome like this:
q = QueueMaker();
function times(n, fn) { for (var i = 0; i < n; i++) fn(); }
function push() { q.pushTail(Math.random()); }
function pull() { q.pullHead(); }
function stress() { times(100, push); times(100, pull); }
setInterval(stress, 1);
In one tab, pasted the code above. In other, fixed with delete instead of assignment.
After ~ 15-20 minutes:
The first tab is the unpatched code.
The text was updated successfully, but these errors were encountered:
I'm talking about the Queue implementation that is featured multiple times throughout the book.
The idea behind
pullHead
seems to be, instead of constantly splicing the array, just move the head pointer forward and delete the old element, creating a sparse array. Unfortunately, that's not what this line:queue.array[queue.head] = void 0;
is doing. It just creates a reference toundefined
and adds it to array.What you probably wanted was this:
Tested in Chrome like this:
In one tab, pasted the code above. In other, fixed with
delete
instead of assignment.After ~ 15-20 minutes:
The first tab is the unpatched code.
The text was updated successfully, but these errors were encountered: