Developer releases sorted-collections, a TypeScript library for always-sorted data structures
A developer has published sorted-collections, an open-source TypeScript package that provides SortedList, SortedSet, and SortedMap data structures that maintain sorted order automatically on every insertion. The library is inspired by Python's sortedcontainers and uses a bucket-based sqrt-decomposition design rather than balanced trees, offering O(log n) insertions and built-in range queries. JavaScript's native Array, Set, and Map lack native sorted behaviour, forcing developers to repeatedly call .sort() — an O(n log n) operation — as a workaround. The package weighs around 2KB gzipped, has zero runtime dependencies, supports both ESM and CJS, and includes full TypeScript types with custom comparator support. Benchmarks show the library delivers the greatest performance advantage over large or continuously growing datasets, while plain arrays remain a simpler choice for small or infrequently updated collections.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in