js-sorted-set
js-sorted-set copied to clipboard
Add ability to initialize sorted set with an array of data
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 }