invertase/denque

What's the point?

Closed this issue · 3 comments

Forgive me for my ignorance. But can you please enlighten me why such a data structure is needed in JavaScript? Isn't the native Array object capable of handling all such stuff?

Thanks in advance

Arrays take linear O(N) time to do shift and unshift operations.

That means in theory that an array with 1000 items is 1000 times slower to do those operations than with a deque with a 1000 items. 10000 times slower with 10000 items and so on. There's also memory usage implications of this - see the benchmarks on readme (arrays cause an out of memory error).

Whereas on a double ended queue every queue operation is done in constant O(1) time.

Ehesp commented

Just to add, if you're doing basic operations with arrays don't worry about using this library. It's designed for high usage and throughput where performance is critical.

I got the idea. Thank you.