algorithms icon indicating copy to clipboard operation
algorithms copied to clipboard

Fix `push` to be O(1) as promised.

Open BMorearty opened this issue 4 years ago • 0 comments

The method comment says it is O(1) but the code was O(n). It was doing an unnecessary loop.

This reduces the time for the "Insertion then sort" benchmark from 7.659 to 0.011.

Fixes #36.

Related: https://github.com/kanwei/algorithms/pull/46 needs to be merged. It has the benchmark that I ran.

cc @alexkalderimis

Benchmark before this change (focus on top right number): image

Benchmark after this change: image

BMorearty avatar Dec 09 '21 22:12 BMorearty