1 comments

  • zrwusa 8 hours ago ago

    Hi HN! I built a data structures library for JavaScript/TypeScript that I've been refining for 2+ years.

    *Why another one?*

    Native JS only gives us Array, Map, Set, Object. When you need a sorted map, priority queue, or graph algorithms, you're stuck with either: - Half-baked npm packages with poor TS support - Porting Java/C++ code yourself - Libraries that expose too many internals

    *What's different:*

    1. *Native API feel* - TreeMap/TreeSet work like Map/Set, just sorted: ```ts const map = new TreeMap([['b', 2], ['a', 1], ['c', 3]]); [...map.keys()] // ['a', 'b', 'c'] - sorted! ```

    2. *Java-style navigation* - `floor()`, `ceiling()`, `lower()`, `higher()`, `rangeSearch()`

    3. *Full TypeScript* - No `any` types, proper generics throughout

    4. *Performance* - Red-Black Tree backed, ~2x faster iteration than js-sdsl

    *Included:* - Binary Trees: BST, AVL, Red-Black, TreeMap, TreeSet, TreeMultiMap - Heaps: Min/Max Heap, Priority Queue - Graphs: Directed/Undirected with Dijkstra, Bellman-Ford, Tarjan, etc. - Linear: Queue, Deque, Stack, LinkedList - Others: Trie, HashMap

    npm: `npm install data-structure-typed`

    Happy to answer questions about implementation details, performance tradeoffs, or TypeScript typing challenges!

    ---

    ## Alternative shorter version:

    *Title:* Show HN: TreeMap, Heap, Graph for TypeScript – native API feel, full type safety

    *Text:* After 2 years of refinement, sharing my TypeScript data structures library.

    TreeMap/TreeSet work like native Map/Set but sorted. Includes Java-style navigation (floor, ceiling, rangeSearch). Also: Heap, PriorityQueue, Graph with Dijkstra/Bellman-Ford/Tarjan, Trie, and more.

    Red-Black Tree backed, ~2x faster iteration than js-sdsl.

    Would love feedback, especially on API design choices!