Echo JS 0.11.0

<~>
tracker1 1346 days ago. link parent 1 point
Then use splice if you're really concerned about it... will be O(n) with an n of 2.

Also, have you actually measured the performance cost of Delete... as I mentioned, you're optimizing by using an expensive call.

Replies

panzerdp 1344 days ago. link 1 point
"Then use splice if you're really concerned about it... will be O(n) with an n of 2."

enqueue() and dequeue() operations on a queue have to be O(1) time complexity. Using unshift(), splice() is a mistake, they are O(n).

Your proposal is to use an O(n) complexity function splice() instead of delete O(1) - but that's just a mistake.

"Also, have you actually measured the performance cost of Delete... as I mentioned, you're optimizing by using an expensive call."

delete operator is O(1) time complexity. That's all that matters.

If you are concerned about the delete operator performance (which in 99% you shouldn't be), use a Map instead of a plan JavaScript object, then use map.delete(key).
tracker1 1342 days ago. link 2 points
You are correct, I apologize.  I will note, that `undefined` assignment is faster than deletion.  I wasn't able to get a good/consistent memory profile for comparison.  I was mistaken about how Array is implemented from a couple articles that I'd read, the impression was slice would only effect the starting index and the number of items in the array affected, not the entire series.

Depending on how big the queue might get, it might be worth exploring using a linked-list instead of object refs.

https://github.com/tracker1/queue-testing
panzerdp 1341 days ago. link 1 point
Thanks for comparing the different implementations! Yeah, clearly the SplicingQueue is the slowest.