js-sorted-set icon indicating copy to clipboard operation
js-sorted-set copied to clipboard

Add ability to initialize sorted set with an array of data

Open svanderbeck11 opened this issue 5 years ago • 0 comments
trafficstars

A great improvement could be adding an optional initial data argument to the constructor, or an initialize method to add an an initial data set. While the runtime would still be nLog(n) vs a user running repeated insert operations, you could avoid lots of data splicing on the ArrayStrategy.

Perhaps something along the lines of:

// AbstractSortedSet: initialize(values){ this.priv.initialize(values); this.length = values.length; return this; }

// ArrayStrategy: initialize(values){ values.sort(this.comparator); this.data =values }

svanderbeck11 avatar Oct 02 '20 21:10 svanderbeck11