# Extension points — trekhleb/javascript-algorithms

> Canonical page: https://codevetter.com/unpack/javascript-algorithms/extension-points

# Extension points — trekhleb/javascript-algorithms

Scanned commit 85293e3e2b88f4d2ce330d956b139cf628aa1e82 (2026-07-25). Generated by codevetter codevetter 1.12.0 on 2026-09-22.

The whole repo is designed as an additive catalog: a new algorithm or data structure is a new folder that plugs in via file convention, not registration. Two deliberate seams exist inside the code — constructor-injected Comparator functions and the Sort/Heap/MinHeap inheritance chain plus traversal callbacks — and CONTRIBUTING.md spells out the social conventions (one algorithm per PR, README required, 100% coverage).
- Adding an algorithm means creating src/algorithms/<topic>/<name>/<name>.js with a default export plus a __test__ directory; no index file or registry needs updating — Jest discovers tests via testRegex. — [CONTRIBUTING.md#L17-25](https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/CONTRIBUTING.md#L17-L25) [jest.config.js#L22](https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/jest.config.js#L22)
- New sorting algorithms plug in by extending Sort: implement sort(), inherit this.comparator and this.callbacks (compareCallback, visitingCallback), then reuse SortTester.testSort/testSortStability/testAlgorithmTimeComplexity for free coverage. — [src/algorithms/sorting/Sort.js#L11-34](https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/src/algorithms/sorting/Sort.js#L11-L34) [src/algorithms/sorting/quick-sort/QuickSort.js#L3](https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/src/algorithms/sorting/quick-sort/QuickSort.js#L3) [src/algorithms/sorting/SortTester.js#L9-71](https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/src/algorithms/sorting/SortTester.js#L9-L71)
- Comparator injection is the universal customization point: LinkedList, Heap, Sort and PriorityQueue all accept a compareFunction in their constructor, letting the same structures order arbitrary objects. — [src/utils/comparator/Comparator.js#L7-9](https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/src/utils/comparator/Comparator.js#L7-L9) [src/data-structures/linked-list/LinkedList.js#L8-16](https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/src/data-structures/linked-list/LinkedList.js#L8-L16) [src/data-structures/heap/Heap.js#L11-19](https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/src/data-structures/heap/Heap.js#L11-L19)
- Graph traversal behavior is extended through the {allowTraversal, enterVertex, leaveVertex} callback object — consumers implement cycle detection, ordering, or instrumentation without touching the traversal internals. — [src/algorithms/graph/breadth-first-search/breadthFirstSearch.js#L4-42](https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/src/algorithms/graph/breadth-first-search/breadthFirstSearch.js#L4-L42) [src/algorithms/graph/depth-first-search/depthFirstSearch.js#L2-40](https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/src/algorithms/graph/depth-first-search/depthFirstSearch.js#L2-L40)
- Heap is intentionally abstract (new.target guard throws on direct construction) so MinHeap/MaxHeap define ordering by overriding pairIsInCorrectOrder; PriorityQueue shows a second extension axis by overriding compare wholesale. — [src/data-structures/heap/Heap.js#L6-14](https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/src/data-structures/heap/Heap.js#L6-L14) [src/data-structures/priority-queue/PriorityQueue.js#L6-17](https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/src/data-structures/priority-queue/PriorityQueue.js#L6-L17)
- New heap-flavored structures can subclass MinHeap or swap in a custom Comparator, exactly as PriorityQueue does with its priorities Map. — [src/data-structures/priority-queue/PriorityQueue.js#L1-30](https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/src/data-structures/priority-queue/PriorityQueue.js#L1-L30) [src/data-structures/heap/MinHeap.js](https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/src/data-structures/heap/MinHeap.js)
- BloomFilter.createStore returns a closed-over storage interface ({getValue,setValue}), so the bit-array backend could be swapped without changing insert/mayContain. — [src/data-structures/bloom-filter/BloomFilter.js#L40-67](https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/src/data-structures/bloom-filter/BloomFilter.js#L40-L67)
- Translation is an extension surface: adding README.xx-XX.md files (root or per-topic) follows a documented locale-code convention in CONTRIBUTING.md. — [CONTRIBUTING.md#L9-15](https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/CONTRIBUTING.md#L9-L15) [README.md#L23-41](https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/README.md#L23-L41)
- The playground (src/playground/playground.js + __test__/playground.test.js) is a designed extension point for experimentation — it already demonstrates importing an algorithm and asserting on it. — [src/playground/playground.js#L1-12](https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/src/playground/playground.js#L1-L12) [src/playground/__test__/playground.test.js](https://github.com/trekhleb/javascript-algorithms/blob/85293e3e2b88f4d2ce330d956b139cf628aa1e82/src/playground/__test__/playground.test.js)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
