# Choose a module

> Every task the modules solve, in plain words. Search for yours, then open the module that answers it.

Each module page also lists what it is **not** for, and where to go instead, including when a built-in `Map`, `Set`, or array is the better answer.

Describe the task: “top k”, “dedupe ids”, “p-value”… (153 tasks)

## Collections

* filter membership over millions of non-negative integer ids without paying a byte per possible id[bitset](/modules/bitset/)
* combine two id sets by union, intersection, or difference without allocating a third set[bitset](/modules/bitset/)
* ask how many ids are at or below a value or inside a range, which id is the k-th smallest, or which id comes next or before[bitset](/modules/bitset/)
* walk a set of ids in ascending order without sorting them[bitset](/modules/bitset/)
* hold ids scattered across a wide range, such as row or document ids, without allocating the whole range[bitset](/modules/bitset/)
* keep the results of repeated lookups in memory without letting them grow past a fixed size[cache](/modules/cache/)
* bound a store by total byte size or cost instead of by number of entries[cache](/modules/cache/)
* let stored results expire after a fixed time while the clock stays under test control[cache](/modules/cache/)
* find out which entries were pushed out to make room, so they can be flushed or logged[cache](/modules/cache/)
* switch the eviction policy for a given traffic shape without changing any call site[cache](/modules/cache/)
* evict in an order of my own, such as by recompute cost or an assigned priority, while the cache keeps handling weights, expiry, and iteration[cache](/modules/cache/)
* take items out in the order they arrived without Array.prototype.shift turning the loop quadratic[deque](/modules/deque/)
* add and remove items at both ends of a sequence, such as a breadth-first and depth-first hybrid[deque](/modules/deque/)
* keep only the last N values of a stream and learn which value just fell out, for a running sum or moving average[deque](/modules/deque/)
* hold a long numeric buffer in eight bytes per value with no per-element allocation[deque](/modules/deque/)
* read the k-th item from either end of a queue without removing anything[deque](/modules/deque/)
* tell whether two items are already connected, while connections keep arriving one at a time[disjoint-set](/modules/disjoint-set/)
* merge two groups of items into one, pair by pair, and count how many groups remain[disjoint-set](/modules/disjoint-set/)
* run Kruskal's minimum spanning tree, or detect a cycle in an undirected graph[disjoint-set](/modules/disjoint-set/)
* group a large collection of items into its connected components[disjoint-set](/modules/disjoint-set/)
* drive percolation, image segmentation, or any equivalence relation that only ever grows by merging[disjoint-set](/modules/disjoint-set/)
* read the exact number of occurrences of a key[frequency-table](/modules/frequency-table/)
* track repeated integer observations as items enter and leave[frequency-table](/modules/frequency-table/)
* sum frequencies between two bounds after updates[frequency-table](/modules/frequency-table/)
* read a median or quantile by its position among all observations[frequency-table](/modules/frequency-table/)
* repeatedly take the smallest or largest item from a changing collection[heap](/modules/heap/)
* run Dijkstra, Prim, or A\* with decrease-key on a keyed queue[heap](/modules/heap/)
* keep a running top-k over a stream, evicting the worst entry as it arrives[heap](/modules/heap/)
* schedule tasks by priority and re-prioritize work that is already queued[heap](/modules/heap/)
* drain a set in sorted order without sorting all of it first[heap](/modules/heap/)
* find which SSTables' \[minKey, maxKey] fence pointers can hold a key on a level-0 read[interval-index](/modules/interval-index/)
* select every table in the next level whose key range overlaps a compaction input[interval-index](/modules/interval-index/)
* find every booking, lease, or time window that covers a moment or overlaps a span[interval-index](/modules/interval-index/)
* keep a set of ranges that are added and removed by id while answering overlap queries[interval-index](/modules/interval-index/)
* match ranges whose endpoints are byte strings, numbers, or any keys with a total order[interval-index](/modules/interval-index/)
* read the k-th smallest key while keys enter and leave[ordered-map](/modules/ordered-map/)
* count keys at or below a bound[ordered-map](/modules/ordered-map/)
* find the nearest stored key at or above, or at or below, a probe[ordered-map](/modules/ordered-map/)
* iterate key-value entries in a sorted range, from a start key onward, or in descending order[ordered-map](/modules/ordered-map/)
* buffer sorted writes in memory before flushing them in key order, as an LSM MemTable does[ordered-map](/modules/ordered-map/)
* limit one client's request weight and tell it the least whole millisecond to wait before retrying[rate-limit](/modules/rate-limit/)
* limit many clients without letting the per-client table grow with every client ever seen[rate-limit](/modules/rate-limit/)
* choose a rate-limit algorithm by the most weight it admits in a trailing window rather than by its name[rate-limit](/modules/rate-limit/)
* combine two limits for one client into one meter a keyed table accepts like a built-in kind[rate-limit](/modules/rate-limit/)
* prove a limiter's worst case and its retry boundary by replaying the same arrival schedules[rate-limit](/modules/rate-limit/)
* read a set as it was at an earlier point, while it keeps changing[snapshot-set](/modules/snapshot-set/)
* answer whether a value was present at a given moment, for an audit trail or a change log[snapshot-set](/modules/snapshot-set/)
* serve MVCC reads: older readers keep their view while a writer mutates[snapshot-set](/modules/snapshot-set/)
* keep an undo stack over membership, or time-travel debug a collection, without cloning it per step[snapshot-set](/modules/snapshot-set/)
* report when each value joined and left a live set, as of any snapshot taken earlier[snapshot-set](/modules/snapshot-set/)
* build the data or index block of a sorted string table from key-value pairs already in key order[sorted-block](/modules/sorted-block/)
* store many sorted Uint8Array keys that share long prefixes in fewer bytes than an array of pairs[sorted-block](/modules/sorted-block/)
* look up, seek to the first key at or above a bound, or scan a key range in a block built once[sorted-block](/modules/sorted-block/)
* persist a sorted run as bytes and reload it with every offset, varint, and key order validated[sorted-block](/modules/sorted-block/)
* trade block size against lookup cost by choosing how often a key is stored whole[sorted-block](/modules/sorted-block/)
* read only the first few items across several already-sorted inputs[sorted-merge](/modules/sorted-merge/)
* merge sorted runs or posting lists with one buffered item per input[sorted-merge](/modules/sorted-merge/)
* combine sorted streams with deterministic ordering for equal items[sorted-merge](/modules/sorted-merge/)
* merge sorted async streams, such as remote SSTable block reads, without buffering whole inputs[sorted-merge](/modules/sorted-merge/)

## Search and text

* look up all records tagged with an exact key after reading the input once[inverted-index](/modules/inverted-index/)
* visit records carrying any requested tag once, in their original order[inverted-index](/modules/inverted-index/)
* group record positions by feature when a record can supply several features or repeat one[inverted-index](/modules/inverted-index/)
* fetch up to a fixed number of autocomplete candidates from a static vocabulary[prefix-index](/modules/prefix-index/)
* expand the last query token into matching terms before an exact posting query[prefix-index](/modules/prefix-index/)
* list identifiers or paths starting with a string without scanning all keys[prefix-index](/modules/prefix-index/)
* rank documents matching any of a set of exact tokens[term-index](/modules/term-index/)
* restrict ranked search to eligible document IDs without changing corpus statistics[term-index](/modules/term-index/)
* read term counts per document and document frequencies without scanning the corpus[term-index](/modules/term-index/)
* find the longest known key that prefixes a query, such as a tool slug or a route segment[trie](/modules/trie/)
* resolve a dotted path, package name, or header name against a catalog built once[trie](/modules/trie/)
* fall back from a specific entry to a broader one, including an empty default key[trie](/modules/trie/)
* look up a known set of token sequences by prefix without slicing and re-joining candidates[trie](/modules/trie/)

## Graphs and optimization

* count permutations or unordered combinations exactly[combinatorics](/modules/combinatorics/)
* compute Stirling numbers for permutations by cycle count and partitions by block count[combinatorics](/modules/combinatorics/)
* compute Bell numbers to count all set partitions[combinatorics](/modules/combinatorics/)
* evaluate log-factorials and log binomial coefficients for large inputs[combinatorics](/modules/combinatorics/)
* share repeated subexpressions even when their operands were built from different equivalent terms[e-graph](/modules/e-graph/)
* recognize that replacing an operand with an equal operand preserves an expression[e-graph](/modules/e-graph/)
* select the cheapest equivalent expression under a caller's operator prices[e-graph](/modules/e-graph/)
* find a good route or schedule where improving one position at a time gets stuck[evolution](/modules/evolution/)
* keep the best candidate seen across generations while a whole population changes[evolution](/modules/evolution/)
* select parents in proportion to rank, then recombine two orderings into one child ordering[evolution](/modules/evolution/)
* run an optimizer deterministically from a seed so a recorded run replays exactly[evolution](/modules/evolution/)
* decide when to stop from a stagnation count instead of a fixed generation budget[evolution](/modules/evolution/)
* mutate or cross a permutation without touching the array the caller handed in[evolution](/modules/evolution/)
* find the fewest-hops route between two points or the cheapest routes to selected destinations, all reachable points, or between every pair on a small graph[graph](/modules/graph/)
* order tasks, builds, or courses so every dependency comes first, or find the cycle that makes that impossible[graph](/modules/graph/)
* count the islands or connected pieces of a map, a grid, or a network, and say which piece each item is in[graph](/modules/graph/)
* decide whether one item can reach another, and list the steps of the path between them[graph](/modules/graph/)
* ask who depends on an item and what it depends on, with in-degree and out-degree[graph](/modules/graph/)
* store a graph from an edge list as compact typed arrays, and persist it as bytes[graph](/modules/graph/)

## Randomness and statistics

* rank vector differences by coordinate magnitude or angle[distance](/modules/distance/)
* measure the extra information cost of approximating one probability distribution with another[distance](/modules/distance/)
* bound how much any event probability can change between two probability distributions[distance](/modules/distance/)
* compute exact set overlap or set distance[distance](/modules/distance/)
* look up which direction to rank a comparison and whether it is symmetric or follows the triangle inequality[distance](/modules/distance/)
* compute probability below a threshold in a named distribution[distribution](/modules/distribution/)
* find a quantile for a distribution[distribution](/modules/distribution/)
* draw values from an injected source according to a distribution[distribution](/modules/distribution/)
* summarize observed numbers with a mean, variance, quantile, histogram, or correlation[distribution](/modules/distribution/)
* compute a chi-square p-value for observed counts against category probabilities[hypothesis-test](/modules/hypothesis-test/)
* test whether draws fit a continuous distribution with Kolmogorov-Smirnov[hypothesis-test](/modules/hypothesis-test/)
* compare the distributions of two samples[hypothesis-test](/modules/hypothesis-test/)
* test one sample mean, two sample means, or paired measurements with a t-test, or three or more group means with a one-way ANOVA, or compare samples by rank with Mann-Whitney U, Wilcoxon signed-rank, or Kruskal-Wallis[hypothesis-test](/modules/hypothesis-test/)
* test an observed success count using an exact binomial p-value[hypothesis-test](/modules/hypothesis-test/)
* calculate a two-sided or directional Fisher exact p-value for a 2-by-2 table[hypothesis-test](/modules/hypothesis-test/)
* replay the same random sequence from a seed in tests, simulations, or procedural generation[prng](/modules/prng/)
* roll an unbiased integer in 1..n without modulo bias[prng](/modules/prng/)
* draw unsigned 64-bit values larger than 2^53 without losing precision or capping the bound[prng](/modules/prng/)
* give parallel workers non-overlapping subsequences of one sequence[prng](/modules/prng/)
* produce the same random values in a browser, in Node.js, and in Bun[prng](/modules/prng/)
* pick k distinct items from a population or an index range without shuffling the whole population[sampling](/modules/sampling/)
* shuffle a copy of a list reproducibly, so a rerun from the same seed yields the same order[sampling](/modules/sampling/)
* pick one item in proportion to its weight, or k items in proportion to their weights without replacement[sampling](/modules/sampling/)
* keep a bounded uniform sample of a stream whose length is not known in advance[sampling](/modules/sampling/)
* pick two distinct items, optionally at least a minimum number of positions apart[sampling](/modules/sampling/)
* replay a simulation or a generated test fixture exactly from a recorded seed[sampling](/modules/sampling/)
* count distinct visitors without storing every visitor[scalar-sketch](/modules/scalar-sketch/)
* check whether an id or URL was already processed, with a small false-positive rate and no false negatives[scalar-sketch](/modules/scalar-sketch/)
* find the heavy hitters of a stream without keeping a counter per key[scalar-sketch](/modules/scalar-sketch/)
* estimate how much two large sets overlap without holding both of them[scalar-sketch](/modules/scalar-sketch/)
* answer those questions per partition and merge the answers afterwards[scalar-sketch](/modules/scalar-sketch/)
* keep the answer in a fixed-size summary that is serialized now and queried later[scalar-sketch](/modules/scalar-sketch/)
* skip a disk or network read for a key that an immutable table or file certainly does not hold[static-filter](/modules/static-filter/)
* check membership in a set of byte keys that is known in full before the first query and never changes[static-filter](/modules/static-filter/)
* keep a membership test for millions of keys in the smallest memory a Worker or browser tab can spare[static-filter](/modules/static-filter/)
* ship a compact membership summary beside an SSTable, a static index, or a release artifact and reload it later[static-filter](/modules/static-filter/)
* pick between a 0.39% and a 0.0015% false-positive rate at 9 to 10 or 18 to 20 bits per key[static-filter](/modules/static-filter/)

## Serialization and utilities

* store the same artifact once no matter how many callers write it[cas](/modules/cas/)
* prove that the bytes a store returned are the content a key names[cas](/modules/cas/)
* share artifacts between processes that do not share a filesystem[cas](/modules/cas/)
* keep serialized structures in an object store, a browser cache, or a Map behind one interface[cas](/modules/cas/)
* catch a failure from any Knotkit package without importing each package's own error classes[errors](/modules/errors/)
* read which package failed, which category, and the exact code from a caught error[errors](/modules/errors/)
* recognize a Knotkit error that crossed a realm or came from a duplicate copy of a package, where instanceof reports a false negative[errors](/modules/errors/)
* format an unknown thrown value into a message without a hostile toString replacing the caller's error[errors](/modules/errors/)
* fail a decode on the first invalid element using the throwing package's own error class and code[errors](/modules/errors/)
* fingerprint bytes, text, or an unsigned integer the same way in every browser, Node.js, and Bun runtime[hash](/modules/hash/)
* shard keys across buckets or deduplicate records by a cheap fingerprint[hash](/modules/hash/)
* hash table keys without allocating or retaining a copy of the input[hash](/modules/hash/)
* reproduce earlier digests in a later process from a persisted algorithm version and seed[hash](/modules/hash/)
* hash a large payload chunk by chunk without holding it all in memory[hash](/modules/hash/)
* build a composite key such as (user id, timestamp) that a byte-ordered store sorts field by field[key-encoding](/modules/key-encoding/)
* sort one field of a composite key descending, such as newest version first, without a custom comparator[key-encoding](/modules/key-encoding/)
* store signed integers or doubles as keys that sort numerically rather than by their raw bytes[key-encoding](/modules/key-encoding/)
* scan every key that starts with a prefix by computing the range's exclusive upper bound[key-encoding](/modules/key-encoding/)
* compare or sort Uint8Array keys in the order memcmp, LevelDB, or IndexedDB uses[key-encoding](/modules/key-encoding/)
* encode a package-identified binary artifact with validated section geometry[wire](/modules/wire/)
* declare a module's binary artifact once so every decoder runs the same prelude and raises the same codes[wire](/modules/wire/)
* encode generic values with an injected byte codec[wire](/modules/wire/)
* prove an element codec injective over a run before emitting an artifact[wire](/modules/wire/)
* share bounded little-endian wire primitives across data-structure packages[wire](/modules/wire/)
* hand closure state to a package serializer without widening its public interface[wire](/modules/wire/)

Nothing matches. Try fewer words, or browse [all modules](/modules/).

Agents can do the same lookup offline: the installed package includes `node_modules/knotkit/capabilities.json`, and the [`knotkit-select` skill](/agents/#install-the-skill) reads it for them.
